-
Notifications
You must be signed in to change notification settings - Fork 12
/
TopBar.tsx
70 lines (66 loc) · 2.09 KB
/
TopBar.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { Menu, MenuButton, MenuItem, MenuList } from '@reach/menu-button'
import { useNavigate } from 'react-router-dom'
import { navToLogin, useApiMutation, useApiQuery } from '@oxide/api'
import {
Button,
DirectionDownIcon,
Info16Icon,
Notifications16Icon,
Profile16Icon,
} from '@oxide/ui'
export function TopBar() {
const navigate = useNavigate()
const logout = useApiMutation('logout', {
onSuccess: () => {
// server will respond to /login with a login redirect
// TODO-usability: do we just want to dump them back to login or is there
// another page that would make sense, like a logged out homepage
navToLogin({ includeCurrent: false })
},
})
const { data: user, error } = useApiQuery(
'sessionMe',
{},
{ cacheTime: 0, refetchOnWindowFocus: false }
)
const loggedIn = user && !error
return (
// shrink-0 is needed to prevent getting squished by body content
<div className="flex shrink-0 h-10 items-center justify-end">
<Button variant="link" size="xs" className="-mr-0.5 !text-tertiary" title="Info">
<Info16Icon />
</Button>
<Button variant="link" size="xs" className="!text-tertiary" title="Notifications">
<Notifications16Icon />
</Button>
<Menu>
<MenuButton
aria-label="User menu"
className="flex ml-1.5 text-tertiary items-center"
title="User menu"
>
{/* span needed to make the button align with the other ones */}
<span>
<Profile16Icon /> <DirectionDownIcon className="ml-0.5 !w-2.5" />
</span>
</MenuButton>
<MenuList className="mt-2">
<MenuItem
onSelect={() => {
navigate('/settings')
}}
>
Settings
</MenuItem>
{loggedIn ? (
<MenuItem onSelect={() => logout.mutate({})}>Sign out</MenuItem>
) : (
<MenuItem onSelect={() => navToLogin({ includeCurrent: true })}>
Sign In
</MenuItem>
)}
</MenuList>
</Menu>
</div>
)
}