Skip to content

Commit ad02ede

Browse files
committed
minor: extract UserMenu component for readability
1 parent 9ef82ba commit ad02ede

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

app/components/TopBar.tsx

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ import * as DropdownMenu from '~/ui/lib/DropdownMenu'
1919
import { pb } from '~/util/path-builder'
2020

2121
export function TopBar({ systemOrSilo }: { systemOrSilo: 'system' | 'silo' }) {
22-
const logout = useApiMutation('logout', {
23-
onSuccess: () => navToLogin({ includeCurrent: false }),
24-
})
25-
// fetch happens in loader wrapping all authed pages
26-
const { me } = useCurrentUser()
27-
2822
// The height of this component is governed by the `PageContainer`
2923
// It's important that this component returns two distinct elements (wrapped in a fragment).
3024
// Each element will occupy one of the top column slots provided by `PageContainer`.
@@ -39,30 +33,39 @@ export function TopBar({ systemOrSilo }: { systemOrSilo: 'system' | 'silo' }) {
3933
<div className="mx-3 flex h-[--top-bar-height] shrink-0 items-center justify-between">
4034
<Breadcrumbs />
4135
<div className="flex items-center gap-2">
42-
<DropdownMenu.Root>
43-
<DropdownMenu.Trigger
44-
className={cn(
45-
buttonStyle({ size: 'sm', variant: 'secondary' }),
46-
'flex items-center gap-2'
47-
)}
48-
aria-label="User menu"
49-
>
50-
<Profile16Icon className="text-quaternary" />
51-
<span className="normal-case text-sans-md text-secondary">
52-
{me.displayName || 'User'}
53-
</span>
54-
<DirectionDownIcon className="!w-2.5" />
55-
</DropdownMenu.Trigger>
56-
<DropdownMenu.Content gap={8}>
57-
<DropdownMenu.LinkItem to={pb.profile()}>Settings</DropdownMenu.LinkItem>
58-
<DropdownMenu.Item onSelect={() => logout.mutate({})}>
59-
Sign out
60-
</DropdownMenu.Item>
61-
</DropdownMenu.Content>
62-
</DropdownMenu.Root>
36+
<UserMenu />
6337
</div>
6438
</div>
6539
</div>
6640
</>
6741
)
6842
}
43+
44+
function UserMenu() {
45+
const logout = useApiMutation('logout', {
46+
onSuccess: () => navToLogin({ includeCurrent: false }),
47+
})
48+
// fetch happens in loader wrapping all authed pages
49+
const { me } = useCurrentUser()
50+
return (
51+
<DropdownMenu.Root>
52+
<DropdownMenu.Trigger
53+
className={cn(
54+
buttonStyle({ size: 'sm', variant: 'secondary' }),
55+
'flex items-center gap-2'
56+
)}
57+
aria-label="User menu"
58+
>
59+
<Profile16Icon className="text-quaternary" />
60+
<span className="normal-case text-sans-md text-secondary">
61+
{me.displayName || 'User'}
62+
</span>
63+
<DirectionDownIcon className="!w-2.5" />
64+
</DropdownMenu.Trigger>
65+
<DropdownMenu.Content gap={8}>
66+
<DropdownMenu.LinkItem to={pb.profile()}>Settings</DropdownMenu.LinkItem>
67+
<DropdownMenu.Item onSelect={() => logout.mutate({})}>Sign out</DropdownMenu.Item>
68+
</DropdownMenu.Content>
69+
</DropdownMenu.Root>
70+
)
71+
}

0 commit comments

Comments
 (0)