Skip to content

Commit

Permalink
Merge pull request #17 from hubcio2115/fix/profile-picture-fallback
Browse files Browse the repository at this point in the history
Fix/profile picture fallback
  • Loading branch information
Maxxxxxxxxxxxxxxxxxxxxx committed Nov 3, 2023
2 parents e547def + 6427d36 commit b20a380
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Binary file modified bun.lockb
Binary file not shown.
11 changes: 7 additions & 4 deletions src/components/profile.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"use client";

import { Avatar, AvatarFallback, AvatarImage } from "@radix-ui/react-avatar";
import type { Session } from "next-auth";

import { Avatar, AvatarFallback, AvatarImage } from "~/components/ui/avatar";

interface ProfileProps {
session: Session;
}
Expand All @@ -11,7 +12,10 @@ function getInitials(name: string) {
const firstName = name.split(" ")[0];
const lastName = name.split(" ")[1];

return `${firstName?.at(0)}${lastName?.at(0)}`;
// If username is somehow all blank
if (!firstName && !lastName) return "You";

return `${firstName?.at(0) ?? ""}${lastName?.at(0) ?? ""}`;
}

export default function Profile({ session }: ProfileProps) {
Expand All @@ -20,10 +24,9 @@ export default function Profile({ session }: ProfileProps) {
<AvatarImage
// eslint-disable-next-line
src={session.user.image!}
className="h-10 w-10 rounded-full"
alt="profile picture"
/>
<AvatarFallback>
<AvatarFallback className="bg-white transition-colors hover:bg-accent hover:text-accent-foreground">
{session.user.name ? getInitials(session.user.name) : ""}
</AvatarFallback>
</Avatar>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const AvatarFallback = forwardRef<
<AvatarPrimitive.Fallback
ref={ref}
className={cn(
"flex h-full w-full items-center justify-center rounded-full bg-muted",
"flex h-full w-full items-center justify-center rounded-full",
className,
)}
{...props}
Expand Down

0 comments on commit b20a380

Please sign in to comment.