From 34bcdc3b055dca1cfbb7cc3035fcf492dc14951f Mon Sep 17 00:00:00 2001 From: zyachel Date: Sun, 1 Jun 2025 13:08:06 +0000 Subject: [PATCH] fix(name,title): handle empty states in "did you know" section --- src/components/name/DidYouKnow.tsx | 81 ++++++++++++++++------------- src/components/title/DidYouKnow.tsx | 8 ++- 2 files changed, 53 insertions(+), 36 deletions(-) diff --git a/src/components/name/DidYouKnow.tsx b/src/components/name/DidYouKnow.tsx index bf65c60..86a5801 100644 --- a/src/components/name/DidYouKnow.tsx +++ b/src/components/name/DidYouKnow.tsx @@ -9,43 +9,54 @@ type Props = { const DidYouKnow = ({ data }: Props) => (

Did you know

- {!!data.trivia?.total && ( -
-

Trivia

-
-
- )} - {!!data.quotes?.total && ( -
-

Quotes

-
-
- )} - {!!data.trademark?.total && ( -
-

Trademark

-
-
- )} - {!!data.nicknames.length && ( -
-

Nicknames

-

{data.nicknames.join(', ')}

-
- )} - {!!data.salary?.total && ( -
-

Salary

-

- {data.salary.value} in - - {data.salary.title.text} - - ({data.salary.title.year}) -

-
+ {isEmpty(data) ? ( +

Nothing interesting to show.

+ ) : ( + <> + {!!data.trivia?.total && ( +
+

Trivia

+
+
+ )} + {!!data.quotes?.total && ( +
+

Quotes

+
+
+ )} + {!!data.trademark?.total && ( +
+

Trademark

+
+
+ )} + {!!data.nicknames.length && ( +
+

Nicknames

+

{data.nicknames.join(', ')}

+
+ )} + {!!data.salary?.total && ( +
+

Salary

+

+ {data.salary.value} in + + {data.salary.title.text} + + ({data.salary.title.year}) +

+
+ )} + )}
); export default DidYouKnow; + +const isEmpty = (data: Props['data']) => + Boolean( + !data.nicknames.length && !data.quotes && !data.salary && !data.trademark && !data.trivia + ); \ No newline at end of file diff --git a/src/components/title/DidYouKnow.tsx b/src/components/title/DidYouKnow.tsx index 01de91d..66c5ab2 100644 --- a/src/components/title/DidYouKnow.tsx +++ b/src/components/title/DidYouKnow.tsx @@ -7,7 +7,13 @@ type Props = { }; const DidYouKnow = ({ data }: Props) => { - if (!Object.keys(data).length) return <>; + if (!Object.keys(data).length) + return ( +
+

Did you know

+

Nothing interesting to show.

+
+ ); return (

Did you know