Skip to content

Commit f8597d4

Browse files
committed
feat: update user avatar handling to use fallback image from DiceBear API
1 parent ff977a8 commit f8597d4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/app/[username]/[articleHandle]/page.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,18 @@ const Page: NextPage<ArticlePageProps> = async ({ params }) => {
114114
</div>
115115
)}
116116

117+
{/* <pre>{JSON.stringify(article?.user, null, 2)}</pre> */}
118+
117119
{/* User information */}
118120
<div className="mb-4 flex items-center my-4">
119121
<div className="relative rounded-full overflow-hidden border transition-transform duration-300 size-10">
120-
<Image
121-
src={getFileUrl(article?.user?.profile_photo) ?? ""}
122+
<img
123+
src={
124+
Boolean(article?.user?.profile_photo)
125+
? getFileUrl(article?.user?.profile_photo)
126+
: "https://api.dicebear.com/9.x/personas/svg?seed=" +
127+
article?.user?.name
128+
}
122129
alt={article?.user?.username ?? ""}
123130
width={40}
124131
height={40}

src/components/ArticleCard.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ const ArticleCard = ({
5656
width={32}
5757
height={32}
5858
unoptimized
59-
src={author.avatar ?? ""}
59+
src={
60+
Boolean(author.avatar)
61+
? author.avatar
62+
: "https://api.dicebear.com/9.x/personas/svg?seed=" +
63+
author.name
64+
}
6065
alt={author.name ?? ""}
6166
className="w-full h-full object-cover transition-opacity duration-300 ease-in-out opacity-100"
6267
/>

0 commit comments

Comments
 (0)