Skip to content

Commit

Permalink
feat(frontend): allow expiring cache for fitness entity list
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnisDa committed Jan 28, 2025
1 parent 99c1f9a commit b2878de
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions apps/frontend/app/routes/_dashboard.fitness.$entity.list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,17 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
page: query[pageQueryParam],
},
};
const itemList = await match(entity)
const displayData = await match(entity)
.with(FitnessEntity.Workouts, async () => {
const { userWorkoutsList } = await serverGqlService.authenticatedRequest(
request,
UserWorkoutsListDocument,
{ input },
);
return {
items: userWorkoutsList.items,
details: userWorkoutsList.details,
cacheId: userWorkoutsList.cacheId,
items: userWorkoutsList.response.items,
details: userWorkoutsList.response.details,
};
})
.with(FitnessEntity.Templates, async () => {
Expand All @@ -136,17 +137,18 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
{ input },
);
return {
items: userWorkoutTemplatesList.items,
details: userWorkoutTemplatesList.details,
cacheId: userWorkoutTemplatesList.cacheId,
items: userWorkoutTemplatesList.response.items,
details: userWorkoutTemplatesList.response.details,
};
})
.exhaustive();
const totalPages = await redirectToFirstPageIfOnInvalidPage(
request,
itemList.details.total,
displayData.details.total,
query[pageQueryParam],
);
return { query, entity, itemList, cookieName, totalPages };
return { query, entity, displayData, cookieName, totalPages };
};

export const meta = ({ data }: MetaArgs<typeof loader>) => {
Expand Down Expand Up @@ -212,13 +214,13 @@ export default function Page() {
<FiltersModalForm />
</FiltersModal>
</Group>
{loaderData.itemList.items.length > 0 ? (
{loaderData.displayData.items.length > 0 ? (
<Stack gap="xs">
<DisplayListDetailsAndRefresh
cacheId={"abcd"}
total={loaderData.itemList.details.total}
cacheId={loaderData.displayData.cacheId}
total={loaderData.displayData.details.total}
/>
{loaderData.itemList.items.map((entityId, index) => (
{loaderData.displayData.items.map((entityId, index) => (
<DisplayFitnessEntity
index={index}
key={entityId}
Expand Down

0 comments on commit b2878de

Please sign in to comment.