MCPcopy Create free account
hub / github.com/CodeFox-Repo/codefox / UserSettingsBar

Function UserSettingsBar

frontend/src/components/user-settings-bar.tsx:35–128  ·  view source on GitHub ↗
({ isSimple }: UserSettingsProps)

Source from the content-addressed store, hash-verified

33 * @returns UserSettings JSX element.
34 */
35export const UserSettingsBar = ({ isSimple }: UserSettingsProps) => {
36 const { user, isLoading, logout } = useAuthContext();
37 const [open, setOpen] = useState(false);
38 const router = useRouter();
39
40 const handleLogout = useMemo(() => {
41 return () => {
42 router.push('/');
43 // router.push('/login');
44 logout();
45 };
46 }, [logout, router]);
47
48 const avatarFallback = useMemo(() => {
49 if (!user?.username) return 'US';
50 return user.username.substring(0, 2).toUpperCase();
51 }, [user?.username]);
52
53 const displayUsername = useMemo(() => {
54 if (isLoading) return 'Loading...';
55 return user?.username || 'Anonymous';
56 }, [isLoading, user?.username]);
57
58 // Normalize the avatar URL
59 const normalizedAvatarUrl = useMemo(() => {
60 return normalizeAvatarUrl(user?.avatarUrl);
61 }, [user?.avatarUrl]);
62
63 const handleSettingsClick = () => {
64 // First navigate using Next.js router
65 router.push('/settings');
66
67 // Then dispatch the event
68 setTimeout(() => {
69 const event = new Event(EventEnum.SETTING);
70 window.dispatchEvent(event);
71 }, 0);
72 };
73
74 const avatarButton = useMemo(() => {
75 return (
76 <Button
77 size="setting"
78 variant="ghost"
79 className={`flex justify-start ${
80 isSimple ? 'w-10 h-12 p-auto' : 'gap-2 w-full h-12 p-1'
81 }`}
82 >
83 <SmallAvatar className="flex items-center justify-center">
84 {/* Use normalized avatar URL */}
85 <AvatarImage
86 src={normalizedAvatarUrl}
87 alt="User"
88 key={user?.avatarUrl}
89 />
90 <AvatarFallback>{avatarFallback}</AvatarFallback>
91 </SmallAvatar>
92 </Button>

Callers

nothing calls this directly

Calls 2

useAuthContextFunction · 0.90
normalizeAvatarUrlFunction · 0.90

Tested by

no test coverage detected