Skip to content

Commit

Permalink
Add BoostHub:createCloudSpace custom event
Browse files Browse the repository at this point in the history
  • Loading branch information
Rokt33r committed Aug 16, 2021
1 parent be8ee03 commit f3e5795
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
34 changes: 23 additions & 11 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
BoostHubSubscriptionDeleteEvent,
boostHubSubscriptionDeleteEventEmitter,
boostHubSubscriptionUpdateEventEmitter,
boostHubCreateCloudSpaceEventEmitter,
} from '../lib/events'
import { useRouteParams } from '../lib/routeParams'
import { useStorageRouter } from '../lib/storageRouter'
Expand Down Expand Up @@ -173,17 +174,6 @@ const App = () => {
})
})

useEffect(() => {
const createCloudSpaceHandler = () => {
push('/app/boosthub/teams')
}
addIpcListener('create-cloud-space', createCloudSpaceHandler)

return () => {
removeIpcListener('create-cloud-space', createCloudSpaceHandler)
}
}, [push])

useEffect(() => {
const boostHubTeamCreateEventHandler = (event: BoostHubTeamCreateEvent) => {
const createdTeam = event.detail.team
Expand Down Expand Up @@ -305,6 +295,10 @@ const App = () => {
push(`/app/storages`)
}

const boostHubCreateCloudSpaceEventHandler = () => {
push('/app/boosthub/teams')
}

boostHubSubscriptionDeleteEventEmitter.listen(
boostHubSubscriptionDeleteEventHandler
)
Expand All @@ -318,6 +312,9 @@ const App = () => {
boostHubCreateLocalSpaceEventEmitter.listen(
boostHubCreateLocalSpaceEventHandler
)
boostHubCreateCloudSpaceEventEmitter.listen(
boostHubCreateCloudSpaceEventHandler
)
return () => {
boostHubSubscriptionDeleteEventEmitter.unlisten(
boostHubSubscriptionDeleteEventHandler
Expand All @@ -334,6 +331,9 @@ const App = () => {
boostHubCreateLocalSpaceEventEmitter.unlisten(
boostHubCreateLocalSpaceEventHandler
)
boostHubCreateCloudSpaceEventEmitter.unlisten(
boostHubCreateCloudSpaceEventHandler
)
}
}, [push, setPreferences, setGeneralStatus])
const { boostHubTeams } = generalStatus
Expand All @@ -356,13 +356,25 @@ const App = () => {
},
[storageMap, boostHubTeams, navigateToStorage, push]
)

useEffect(() => {
addIpcListener('switch-workspace', switchWorkspaceHandler)
return () => {
removeIpcListener('switch-workspace', switchWorkspaceHandler)
}
}, [switchWorkspaceHandler])

useEffect(() => {
const createCloudSpaceHandler = () => {
boostHubCreateCloudSpaceEventEmitter.dispatch()
}
addIpcListener('create-cloud-space', createCloudSpaceHandler)

return () => {
removeIpcListener('create-cloud-space', createCloudSpaceHandler)
}
}, [push])

useBoostNoteProtocol()

const { showingCloudIntroModal } = useCloudIntroModal()
Expand Down
5 changes: 2 additions & 3 deletions src/components/atoms/BoostHubWebview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ import {
boosthubNotificationCountsEventEmitter,
boostHubSidebarSpaceEventEmitter,
boostHubAppRouterEventEmitter,
boostHubCreateCloudSpaceEventEmitter,
} from '../../lib/events'
import { usePreferences } from '../../lib/preferences'
import { openContextMenu, openExternal } from '../../lib/electronOnly'
import { DidFailLoadEvent } from 'electron/main'
import styled from '../../shared/lib/styled'
import { useRouter } from '../../lib/router'

export interface WebviewControl {
focus(): void
Expand Down Expand Up @@ -70,7 +70,6 @@ const BoostHubWebview = ({
const { preferences } = usePreferences()
const { signOut } = useBoostHub()
const domReadyRef = useRef<boolean>(false)
const { push } = useRouter()
const cloudUser = preferences['cloud.user']

const accessToken = useMemo(() => {
Expand Down Expand Up @@ -146,7 +145,7 @@ const BoostHubWebview = ({
const ipcMessageEventHandler = (event: IpcMessageEvent) => {
switch (event.channel) {
case 'new-space':
push('/app/boosthub/teams')
boostHubCreateCloudSpaceEventEmitter.dispatch()
break
case 'router':
boostHubAppRouterEventEmitter.dispatch({ target: event.args[0] })
Expand Down
4 changes: 4 additions & 0 deletions src/lib/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ export const boostHubCreateLocalSpaceEventEmitter = createCustomEventEmitter(
'BoostHub:createLocalSpace'
)

export const boostHubCreateCloudSpaceEventEmitter = createCustomEventEmitter(
'BoostHub:createCloudSpace'
)

export const boostHubToggleSidebarTreeEventEmitter = createCustomEventEmitter(
'BoostHub:toggleSidebarTree'
)
Expand Down

0 comments on commit f3e5795

Please sign in to comment.