From d1f2f8a305619ab9f56441ac1e08659af12e8ea4 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Tue, 11 Jul 2023 23:49:32 +0100 Subject: [PATCH] feat: use DiceBear to display default avatars --- .../[subdomain]/events/page-component.tsx | 1 + .../[subdomain]/layout-component.tsx | 1 + src/components/common/CharacterCard.tsx | 1 + src/components/common/CharacterListItem.tsx | 1 + src/components/common/CommentInput.tsx | 4 +++ src/components/common/CommentItem.tsx | 5 ++- src/components/common/ConnectButton.tsx | 1 + src/components/common/PatronModal.tsx | 2 ++ src/components/common/ReactionLike.tsx | 1 + src/components/common/ReactionMint.tsx | 1 + src/components/common/ReactionTip.tsx | 1 + src/components/home/HomeFeed.tsx | 1 + src/components/home/HomeSidebar.tsx | 1 + src/components/site/SiteHeader.tsx | 17 +++++----- src/components/ui/Avatar.tsx | 34 +++++-------------- src/components/ui/AvatarStack.tsx | 2 ++ src/models/home.model.ts | 4 +++ 17 files changed, 42 insertions(+), 36 deletions(-) diff --git a/src/app/dashboard/[subdomain]/events/page-component.tsx b/src/app/dashboard/[subdomain]/events/page-component.tsx index 81ecbf63..ce7d6608 100644 --- a/src/app/dashboard/[subdomain]/events/page-component.tsx +++ b/src/app/dashboard/[subdomain]/events/page-component.tsx @@ -26,6 +26,7 @@ function SiteAvatar({ siteId }: { siteId: string }) { })} > diff --git a/src/components/common/ConnectButton.tsx b/src/components/common/ConnectButton.tsx index c7c786d0..1130fd24 100644 --- a/src/components/common/ConnectButton.tsx +++ b/src/components/common/ConnectButton.tsx @@ -255,6 +255,7 @@ export const ConnectButton = ({ aria-label="connector" > ({ images: $.character?.metadata?.content?.avatars, name: $.character?.metadata?.content?.name, + cid: $.characterId, })), [likes], ) diff --git a/src/components/common/ReactionMint.tsx b/src/components/common/ReactionMint.tsx index 9e7f0401..14f783a2 100644 --- a/src/components/common/ReactionMint.tsx +++ b/src/components/common/ReactionMint.tsx @@ -102,6 +102,7 @@ export const ReactionMint = ({ .map((mint) => ({ images: mint.character?.metadata?.content?.avatars, name: mint.character?.metadata?.content?.name, + cid: mint.character.characterId, })) || noopArr, [mints], ) diff --git a/src/components/common/ReactionTip.tsx b/src/components/common/ReactionTip.tsx index 63298e55..0cbf8e0f 100644 --- a/src/components/common/ReactionTip.tsx +++ b/src/components/common/ReactionTip.tsx @@ -64,6 +64,7 @@ export const ReactionTip = ({ .map((mint) => ({ images: mint.character?.metadata?.content?.avatars, name: mint.character?.metadata?.content?.name, + cid: mint.character?.characterId, })) || noopArr, [tips.data?.pages], ) diff --git a/src/components/home/HomeFeed.tsx b/src/components/home/HomeFeed.tsx index 789ae919..e3a6daaa 100644 --- a/src/components/home/HomeFeed.tsx +++ b/src/components/home/HomeFeed.tsx @@ -84,6 +84,7 @@ const PostCard = ({ > - {site?.metadata?.content?.avatars?.[0] && ( - - )} +

diff --git a/src/components/ui/Avatar.tsx b/src/components/ui/Avatar.tsx index 5e97a372..2a1920cf 100644 --- a/src/components/ui/Avatar.tsx +++ b/src/components/ui/Avatar.tsx @@ -5,6 +5,7 @@ import { toGateway } from "~/lib/ipfs-parser" import { cn } from "~/lib/utils" export const Avatar = ({ + cid, images, size, name, @@ -14,6 +15,7 @@ export const Avatar = ({ priority, ...props }: { + cid?: string | number | null images: (string | null | undefined)[] name?: string | null size?: number @@ -24,15 +26,7 @@ export const Avatar = ({ } & React.HTMLAttributes) => { size = size || 60 - const fontSize = size * 0.5 - - const nameAbbr = (name || "") - .split(" ") - .slice(0, 2) - .map((word) => word[0]) - .join("") - - const image = useMemo(() => { + let image = useMemo(() => { for (const image of images) { if (image) return toGateway(image) } @@ -41,23 +35,11 @@ export const Avatar = ({ const borderRadius = rounded === false ? "rounded-lg" : "rounded-full" if (!image) { - return ( - - {nameAbbr} - - ) + image = `https://api.dicebear.com/6.x/bottts-neutral/svg?seed=${cid}` + } + + if (cid === 56592) { + image = `https://api.dicebear.com/6.x/bottts-neutral/svg?seed=${name}` } return ( diff --git a/src/components/ui/AvatarStack.tsx b/src/components/ui/AvatarStack.tsx index 30707da4..473a3b6c 100644 --- a/src/components/ui/AvatarStack.tsx +++ b/src/components/ui/AvatarStack.tsx @@ -9,6 +9,7 @@ interface AvatarStackProps { avatars: { name: string | null | undefined images: string[] | null | undefined + cid: number | null | undefined }[] count: number @@ -28,6 +29,7 @@ export const AvatarStack: FC = (props) => { return (