Skip to content

Commit 275a8ff

Browse files
committed
Add sign out menu item to plus button context menu
1 parent 0349a1e commit 275a8ff

File tree

2 files changed

+63
-48
lines changed

2 files changed

+63
-48
lines changed

src/components/organisms/AppNavigator.tsx

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,27 @@ const TopLevelNavigator = () => {
7878
const { createStorage } = useDb()
7979
const { prompt } = useDialog()
8080
const { setGeneralStatus } = useGeneralStatus()
81-
const { signOut } = useBoostHub()
81+
const { requestSignOut } = useBoostHub()
82+
83+
const signOut = useCallback(async () => {
84+
if (
85+
routeParams.name === 'boosthub.teams.show' ||
86+
routeParams.name === 'boosthub.teams.create'
87+
) {
88+
push('/app/boosthub/login')
89+
}
90+
setPreferences({
91+
'boosthub.user': null,
92+
})
93+
setGeneralStatus({
94+
boostHubTeams: [],
95+
})
96+
try {
97+
await requestSignOut()
98+
} catch (error) {
99+
console.warn('Failed to send signing out request', error)
100+
}
101+
}, [routeParams.name, setPreferences, setGeneralStatus, requestSignOut, push])
82102

83103
const openSideNavContextMenu = useCallback(
84104
(event: React.MouseEvent) => {
@@ -126,26 +146,8 @@ const TopLevelNavigator = () => {
126146
}
127147
: {
128148
type: 'normal',
129-
label: 'Log out Boost Hub',
130-
click: async () => {
131-
if (
132-
routeParams.name === 'boosthub.teams.show' ||
133-
routeParams.name === 'boosthub.teams.create'
134-
) {
135-
push('/app/boosthub/login')
136-
}
137-
setPreferences({
138-
'boosthub.user': null,
139-
})
140-
setGeneralStatus({
141-
boostHubTeams: [],
142-
})
143-
try {
144-
await signOut()
145-
} catch (error) {
146-
console.warn('Failed to send signing out request', error)
147-
}
148-
},
149+
label: 'Sign Out Boost Hub',
150+
click: signOut,
149151
},
150152
{
151153
type: 'separator',
@@ -162,16 +164,7 @@ const TopLevelNavigator = () => {
162164
],
163165
})
164166
},
165-
[
166-
boostHubUserInfo,
167-
prompt,
168-
createStorage,
169-
signOut,
170-
push,
171-
setPreferences,
172-
setGeneralStatus,
173-
routeParams.name,
174-
]
167+
[boostHubUserInfo, prompt, createStorage, push, setPreferences, signOut]
175168
)
176169

177170
const openNewStorageContextMenu: MouseEventHandler<HTMLButtonElement> = useCallback(
@@ -180,26 +173,48 @@ const TopLevelNavigator = () => {
180173
openContextMenu({
181174
menuItems: [
182175
{ label: 'Create a Note Storage', click: goToStorageCreatePage },
183-
boostHubUserInfo == null
184-
? {
185-
label: isChecked(featureBoostHubSignIn)
186-
? 'Create a Team Account'
187-
: 'Create a Team Account (New)',
188-
click: () => {
189-
checkFeature(featureBoostHubSignIn)
190-
push('/app/boosthub/login')
176+
...(boostHubUserInfo == null
177+
? ([
178+
{
179+
type: 'separator',
191180
},
192-
}
193-
: {
194-
label: 'Create a Team',
195-
click: () => {
196-
push('/app/boosthub/teams')
181+
{
182+
label: isChecked(featureBoostHubSignIn)
183+
? 'Create a Team Account'
184+
: 'Create a Team Account (New)',
185+
click: () => {
186+
checkFeature(featureBoostHubSignIn)
187+
push('/app/boosthub/login')
188+
},
197189
},
198-
},
190+
] as MenuItemConstructorOptions[])
191+
: ([
192+
{
193+
label: 'Create a Team',
194+
click: () => {
195+
push('/app/boosthub/teams')
196+
},
197+
},
198+
{
199+
type: 'separator',
200+
},
201+
{
202+
type: 'normal',
203+
label: 'Sign Out Boost Hub',
204+
click: signOut,
205+
},
206+
] as MenuItemConstructorOptions[])),
199207
],
200208
})
201209
},
202-
[goToStorageCreatePage, isChecked, checkFeature, push, boostHubUserInfo]
210+
[
211+
goToStorageCreatePage,
212+
isChecked,
213+
checkFeature,
214+
push,
215+
boostHubUserInfo,
216+
signOut,
217+
]
203218
)
204219

205220
return (

src/lib/boosthub.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function useBoostHubStore() {
170170
teams: { id: string; name: string; domain: string; iconUrl?: string }[]
171171
}
172172
}
173-
const signOut = useCallback(async () => {
173+
const requestSignOut = useCallback(async () => {
174174
await fetchJson(boostHubSignOutUrl)
175175
}, [fetchJson])
176176

@@ -182,7 +182,7 @@ function useBoostHubStore() {
182182
webviewRef,
183183
fetchDesktopGlobalData,
184184
sendSignInRequest,
185-
signOut,
185+
requestSignOut,
186186
openDevTools,
187187
}
188188
}

0 commit comments

Comments
 (0)