Skip to content

Commit

Permalink
feat: move badge data to the computation step
Browse files Browse the repository at this point in the history
  • Loading branch information
cecilia-sanare committed Sep 13, 2024
1 parent 2710e4c commit a7f0746
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/components/app/AppBadges.tsx
Original file line number Diff line number Diff line change
@@ -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<ThinApp>;
};

export const AppBadges: FC<Props> = ({ 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 (
<IconTooltip className="absolute top-1 right-1" icon={BadgePlus}>
Expand Down
4 changes: 4 additions & 0 deletions src/service/protontweaks.service.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -29,6 +30,9 @@ export function getComputedApp<T extends ThinApp>(app: T): ComputedApp<T> {
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)),
},
};
}

Expand Down
3 changes: 3 additions & 0 deletions src/types/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ export type App = {

export type ComputedApp<T extends ThinApp = App> = T & {
image_url: string;
badges: {
is_new: boolean;
};
};

0 comments on commit a7f0746

Please sign in to comment.