From 99545889139156acf55d720faf4ac293862e6280 Mon Sep 17 00:00:00 2001 From: Hollgy Date: Mon, 25 Mar 2024 10:58:25 +0100 Subject: [PATCH] Fixed bug where invalid date renders in comments as loop, did not piss off lintbro --- client-solid/src/Components/Comment.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/client-solid/src/Components/Comment.tsx b/client-solid/src/Components/Comment.tsx index d78fa0a..c706750 100644 --- a/client-solid/src/Components/Comment.tsx +++ b/client-solid/src/Components/Comment.tsx @@ -7,15 +7,23 @@ export function Comment(props: { comment: PublicComment }): JSXElement { const [content, setContent] = createSignal(""); createEffect(() => { - setCreationDate(new Date(props.comment.created_at).toDateString()); + const date = new Date(props.comment.created_at); + if (!isNaN(date.getTime())) { + setCreationDate(date.toDateString()); + } else { + // Set creation date to an empty string or any default value when the date is invalid + setCreationDate(""); + } setContent(props.comment.content); }); return ( <> -
- -
+ {creationDate() && ( // Render creation date only if it's not an empty string +
+ +
+ )}
{content()}