Skip to content

Commit

Permalink
fix: handle cases when dashboard is empty
Browse files Browse the repository at this point in the history
Also for new users, the recommendations getting for loop runs forever!
  • Loading branch information
IgnisDa committed Jan 23, 2025
1 parent ca17011 commit 4ac24a8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 35 deletions.
88 changes: 54 additions & 34 deletions apps/frontend/app/routes/_dashboard._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import {
UserUpcomingCalendarEventsDocument,
} from "@ryot/generated/graphql/backend/graphql";
import { isNumber } from "@ryot/ts-utils";
import { IconInfoCircle, IconRotateClockwise } from "@tabler/icons-react";
import {
IconBackpack,
IconInfoCircle,
IconRotateClockwise,
} from "@tabler/icons-react";
import CryptoJS from "crypto-js";
import type { ReactNode } from "react";
import { ClientOnly } from "remix-utils/client-only";
Expand Down Expand Up @@ -135,6 +139,13 @@ export default function Page() {
"false",
);

const isDashboardEmpty =
loaderData.userUpcomingCalendarEvents.length +
loaderData.inProgressCollectionContents.results.items.length +
loaderData.userRecommendations.length +
Number(Boolean(latestUserSummary)) ===
0;

return (
<Container>
<Stack gap={32}>
Expand All @@ -152,6 +163,13 @@ export default function Page() {
) : null
}
</ClientOnly>
{isDashboardEmpty ? (
<Alert icon={<IconBackpack />}>
Start by marking a few movies as watched by: clicking on the Media
section in the sidebar, selecting Movie, opening the search tab and
then typing your favorite movie!
</Alert>
) : null}
{userPreferences.general.dashboard.map((de) =>
match([de.section, de.hidden])
.with([DashboardElementLot.Upcoming, false], ([v, _]) =>
Expand Down Expand Up @@ -185,39 +203,41 @@ export default function Page() {
</Section>
) : null,
)
.with([DashboardElementLot.Recommendations, false], ([v, _]) => (
<Section key={v} lot={v}>
<Group justify="space-between">
<SectionTitle text="Recommendations" />
<ActionIcon
variant="subtle"
onClick={() => {
openConfirmationModal(
"Are you sure you want to refresh the recommendations?",
async () => {
await clientGqlService.request(
UserMetadataRecommendationsDocument,
{ shouldRefresh: true },
);
revalidator.revalidate();
},
);
}}
>
<IconRotateClockwise />
</ActionIcon>
</Group>
{coreDetails.isServerKeyValidated ? (
<ApplicationGrid>
{loaderData.userRecommendations.map((lm) => (
<MetadataDisplayItem key={lm} metadataId={lm} />
))}
</ApplicationGrid>
) : (
<ProRequiredAlert tooltipLabel="Get new recommendations every hour" />
)}
</Section>
))
.with([DashboardElementLot.Recommendations, false], ([v, _]) =>
loaderData.userRecommendations.length > 0 ? (
<Section key={v} lot={v}>
<Group justify="space-between">
<SectionTitle text="Recommendations" />
<ActionIcon
variant="subtle"
onClick={() => {
openConfirmationModal(
"Are you sure you want to refresh the recommendations?",
async () => {
await clientGqlService.request(
UserMetadataRecommendationsDocument,
{ shouldRefresh: true },
);
revalidator.revalidate();
},
);
}}
>
<IconRotateClockwise />
</ActionIcon>
</Group>
{coreDetails.isServerKeyValidated ? (
<ApplicationGrid>
{loaderData.userRecommendations.map((lm) => (
<MetadataDisplayItem key={lm} metadataId={lm} />
))}
</ApplicationGrid>
) : (
<ProRequiredAlert tooltipLabel="Get new recommendations every hour" />
)}
</Section>
) : null,
)
.with([DashboardElementLot.Summary, false], ([v, _]) =>
latestUserSummary ? (
<Section key={v} lot={v}>
Expand Down
3 changes: 2 additions & 1 deletion crates/services/user/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ impl UserService {
return Ok(Vec::new());
}
let mut recommendations = HashSet::new();
loop {
for i in 0..10 {
if recommendations.len() >= limit.try_into().unwrap() {
break;
}
ryot_log!(debug, "Generating recommendation in loop: {}", i);
let selected_lot = enabled.choose(&mut rand::rng()).unwrap();
let rec = Metadata::find()
.select_only()
Expand Down

0 comments on commit 4ac24a8

Please sign in to comment.