From a7f07462662e851d74961e3dcff62ce4918db9a6 Mon Sep 17 00:00:00 2001 From: Cecilia Sanare Date: Fri, 13 Sep 2024 12:56:34 -0500 Subject: [PATCH] feat: move badge data to the computation step --- src/components/app/AppBadges.tsx | 7 ++----- src/service/protontweaks.service.ts | 4 ++++ src/types/apps.ts | 3 +++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/app/AppBadges.tsx b/src/components/app/AppBadges.tsx index 56b576e..af5cc16 100644 --- a/src/components/app/AppBadges.tsx +++ b/src/components/app/AppBadges.tsx @@ -1,17 +1,14 @@ -import { useMemo, type FC } from 'react'; +import { type FC } from 'react'; import type { ComputedApp, ThinApp } from '@/types'; import { BadgePlus } from 'lucide-react'; import { IconTooltip } from '@/components/common/IconTooltip'; -import { isAfter, parseISO, subWeeks } from 'date-fns'; type Props = { app: ComputedApp; }; export const AppBadges: FC = ({ app }) => { - const isNew = useMemo(() => isAfter(parseISO(app.created_at), subWeeks(new Date(), 1)), [app.created_at]); - - if (!isNew) return null; + if (!app.badges.is_new) return null; return ( diff --git a/src/service/protontweaks.service.ts b/src/service/protontweaks.service.ts index 650fe65..f9d4fc1 100644 --- a/src/service/protontweaks.service.ts +++ b/src/service/protontweaks.service.ts @@ -1,3 +1,4 @@ +import { isAfter, parseISO, subWeeks } from 'date-fns'; import type { ApiInfo, App, AppsList, ComputedApp, ThinApp } from '../types'; import { fetch } from '../utils/fetch'; @@ -29,6 +30,9 @@ export function getComputedApp(app: T): ComputedApp { return { ...app, image_url: `https://steamcdn-a.akamaihd.net/steam/apps/${app.id}/header.jpg`, + badges: { + is_new: isAfter(parseISO(app.created_at), subWeeks(new Date(), 1)), + }, }; } diff --git a/src/types/apps.ts b/src/types/apps.ts index 1edd0aa..c4dadb3 100644 --- a/src/types/apps.ts +++ b/src/types/apps.ts @@ -31,4 +31,7 @@ export type App = { export type ComputedApp = T & { image_url: string; + badges: { + is_new: boolean; + }; };