From 582c276e954f8dfa73111c5a475ce69c445777ff Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Wed, 23 Oct 2024 13:23:44 -0300 Subject: [PATCH] fix: N/A problem on repacks --- src/renderer/src/hooks/use-date.ts | 2 ++ src/renderer/src/pages/game-details/hero/hero-panel.tsx | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/hooks/use-date.ts b/src/renderer/src/hooks/use-date.ts index 9486400c..9a5172d3 100644 --- a/src/renderer/src/hooks/use-date.ts +++ b/src/renderer/src/hooks/use-date.ts @@ -77,6 +77,8 @@ export function useDate() { }, formatDate: (date: number | Date | string): string => { + if (isNaN(new Date(date).getDate())) return "N/A"; + const locale = getDateLocale(); return format(date, locale == enUS ? "MM/dd/yyyy" : "dd/MM/yyyy"); }, diff --git a/src/renderer/src/pages/game-details/hero/hero-panel.tsx b/src/renderer/src/pages/game-details/hero/hero-panel.tsx index 7f010705..e8675023 100644 --- a/src/renderer/src/pages/game-details/hero/hero-panel.tsx +++ b/src/renderer/src/pages/game-details/hero/hero-panel.tsx @@ -1,8 +1,7 @@ -import { format } from "date-fns"; import { useContext } from "react"; import { useTranslation } from "react-i18next"; -import { useDownload } from "@renderer/hooks"; +import { useDate, useDownload } from "@renderer/hooks"; import { HeroPanelActions } from "./hero-panel-actions"; import * as styles from "./hero-panel.css"; @@ -17,6 +16,8 @@ export interface HeroPanelProps { export function HeroPanel({ isHeaderStuck }: HeroPanelProps) { const { t } = useTranslation("game_details"); + const { formatDate } = useDate(); + const { game, repacks, gameColor } = useContext(gameDetailsContext); const { lastPacket } = useDownload(); @@ -29,7 +30,9 @@ export function HeroPanel({ isHeaderStuck }: HeroPanelProps) { const [latestRepack] = repacks; if (latestRepack) { - const lastUpdate = format(latestRepack.uploadDate!, "dd/MM/yyyy"); + const lastUpdate = latestRepack.uploadDate + ? formatDate(latestRepack.uploadDate!) + : ""; const repacksCount = repacks.length; return (