Skip to content

Commit f3e5795

Browse files
committed
Add BoostHub:createCloudSpace custom event
1 parent be8ee03 commit f3e5795

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

src/components/App.tsx

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
BoostHubSubscriptionDeleteEvent,
2626
boostHubSubscriptionDeleteEventEmitter,
2727
boostHubSubscriptionUpdateEventEmitter,
28+
boostHubCreateCloudSpaceEventEmitter,
2829
} from '../lib/events'
2930
import { useRouteParams } from '../lib/routeParams'
3031
import { useStorageRouter } from '../lib/storageRouter'
@@ -173,17 +174,6 @@ const App = () => {
173174
})
174175
})
175176

176-
useEffect(() => {
177-
const createCloudSpaceHandler = () => {
178-
push('/app/boosthub/teams')
179-
}
180-
addIpcListener('create-cloud-space', createCloudSpaceHandler)
181-
182-
return () => {
183-
removeIpcListener('create-cloud-space', createCloudSpaceHandler)
184-
}
185-
}, [push])
186-
187177
useEffect(() => {
188178
const boostHubTeamCreateEventHandler = (event: BoostHubTeamCreateEvent) => {
189179
const createdTeam = event.detail.team
@@ -305,6 +295,10 @@ const App = () => {
305295
push(`/app/storages`)
306296
}
307297

298+
const boostHubCreateCloudSpaceEventHandler = () => {
299+
push('/app/boosthub/teams')
300+
}
301+
308302
boostHubSubscriptionDeleteEventEmitter.listen(
309303
boostHubSubscriptionDeleteEventHandler
310304
)
@@ -318,6 +312,9 @@ const App = () => {
318312
boostHubCreateLocalSpaceEventEmitter.listen(
319313
boostHubCreateLocalSpaceEventHandler
320314
)
315+
boostHubCreateCloudSpaceEventEmitter.listen(
316+
boostHubCreateCloudSpaceEventHandler
317+
)
321318
return () => {
322319
boostHubSubscriptionDeleteEventEmitter.unlisten(
323320
boostHubSubscriptionDeleteEventHandler
@@ -334,6 +331,9 @@ const App = () => {
334331
boostHubCreateLocalSpaceEventEmitter.unlisten(
335332
boostHubCreateLocalSpaceEventHandler
336333
)
334+
boostHubCreateCloudSpaceEventEmitter.unlisten(
335+
boostHubCreateCloudSpaceEventHandler
336+
)
337337
}
338338
}, [push, setPreferences, setGeneralStatus])
339339
const { boostHubTeams } = generalStatus
@@ -356,13 +356,25 @@ const App = () => {
356356
},
357357
[storageMap, boostHubTeams, navigateToStorage, push]
358358
)
359+
359360
useEffect(() => {
360361
addIpcListener('switch-workspace', switchWorkspaceHandler)
361362
return () => {
362363
removeIpcListener('switch-workspace', switchWorkspaceHandler)
363364
}
364365
}, [switchWorkspaceHandler])
365366

367+
useEffect(() => {
368+
const createCloudSpaceHandler = () => {
369+
boostHubCreateCloudSpaceEventEmitter.dispatch()
370+
}
371+
addIpcListener('create-cloud-space', createCloudSpaceHandler)
372+
373+
return () => {
374+
removeIpcListener('create-cloud-space', createCloudSpaceHandler)
375+
}
376+
}, [push])
377+
366378
useBoostNoteProtocol()
367379

368380
const { showingCloudIntroModal } = useCloudIntroModal()

src/components/atoms/BoostHubWebview.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ import {
3232
boosthubNotificationCountsEventEmitter,
3333
boostHubSidebarSpaceEventEmitter,
3434
boostHubAppRouterEventEmitter,
35+
boostHubCreateCloudSpaceEventEmitter,
3536
} from '../../lib/events'
3637
import { usePreferences } from '../../lib/preferences'
3738
import { openContextMenu, openExternal } from '../../lib/electronOnly'
3839
import { DidFailLoadEvent } from 'electron/main'
3940
import styled from '../../shared/lib/styled'
40-
import { useRouter } from '../../lib/router'
4141

4242
export interface WebviewControl {
4343
focus(): void
@@ -70,7 +70,6 @@ const BoostHubWebview = ({
7070
const { preferences } = usePreferences()
7171
const { signOut } = useBoostHub()
7272
const domReadyRef = useRef<boolean>(false)
73-
const { push } = useRouter()
7473
const cloudUser = preferences['cloud.user']
7574

7675
const accessToken = useMemo(() => {
@@ -146,7 +145,7 @@ const BoostHubWebview = ({
146145
const ipcMessageEventHandler = (event: IpcMessageEvent) => {
147146
switch (event.channel) {
148147
case 'new-space':
149-
push('/app/boosthub/teams')
148+
boostHubCreateCloudSpaceEventEmitter.dispatch()
150149
break
151150
case 'router':
152151
boostHubAppRouterEventEmitter.dispatch({ target: event.args[0] })

src/lib/events.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ export const boostHubCreateLocalSpaceEventEmitter = createCustomEventEmitter(
118118
'BoostHub:createLocalSpace'
119119
)
120120

121+
export const boostHubCreateCloudSpaceEventEmitter = createCustomEventEmitter(
122+
'BoostHub:createCloudSpace'
123+
)
124+
121125
export const boostHubToggleSidebarTreeEventEmitter = createCustomEventEmitter(
122126
'BoostHub:toggleSidebarTree'
123127
)

0 commit comments

Comments
 (0)