Skip to content

Commit

Permalink
feat: add random color for user fallback bg
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <tukon479@gmail.com>
  • Loading branch information
Innei committed Oct 29, 2024
1 parent bc1f39b commit dcbae89
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion apps/renderer/src/modules/user/UserAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Avatar, AvatarFallback, AvatarImage } from "@follow/components/ui/avatar/index.jsx"
import { getColorScheme, stringToHue } from "@follow/utils/color"
import { cn } from "@follow/utils/utils"
import { forwardRef } from "react"

Expand Down Expand Up @@ -49,6 +50,7 @@ export const UserAvatar = forwardRef<
}

const renderUserData = userId ? profile.data : session?.user
const randomColor = stringToHue(renderUserData?.name || "")
return (
<div
style={style}
Expand All @@ -75,7 +77,12 @@ export const UserAvatar = forwardRef<
className="duration-200 animate-in fade-in-0"
src={replaceImgUrlIfNeed(renderUserData?.image || undefined)}
/>
<AvatarFallback>{renderUserData?.name?.slice(0, 2)}</AvatarFallback>
<AvatarFallback
style={{ backgroundColor: getColorScheme(randomColor).light.accent }}
className="text-xs"
>
{renderUserData?.name?.[0]}
</AvatarFallback>
</Avatar>
{!hideName && <div>{renderUserData?.name}</div>}
</div>
Expand Down

0 comments on commit dcbae89

Please sign in to comment.