From f3e57956df425ab6076ed1747320bcc02ecca713 Mon Sep 17 00:00:00 2001 From: Junyoung Choi Date: Mon, 16 Aug 2021 12:18:22 +0900 Subject: [PATCH] Add BoostHub:createCloudSpace custom event --- src/components/App.tsx | 34 ++++++++++++++++-------- src/components/atoms/BoostHubWebview.tsx | 5 ++-- src/lib/events.ts | 4 +++ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index 04caf18e21..f39324d6e1 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -25,6 +25,7 @@ import { BoostHubSubscriptionDeleteEvent, boostHubSubscriptionDeleteEventEmitter, boostHubSubscriptionUpdateEventEmitter, + boostHubCreateCloudSpaceEventEmitter, } from '../lib/events' import { useRouteParams } from '../lib/routeParams' import { useStorageRouter } from '../lib/storageRouter' @@ -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 @@ -305,6 +295,10 @@ const App = () => { push(`/app/storages`) } + const boostHubCreateCloudSpaceEventHandler = () => { + push('/app/boosthub/teams') + } + boostHubSubscriptionDeleteEventEmitter.listen( boostHubSubscriptionDeleteEventHandler ) @@ -318,6 +312,9 @@ const App = () => { boostHubCreateLocalSpaceEventEmitter.listen( boostHubCreateLocalSpaceEventHandler ) + boostHubCreateCloudSpaceEventEmitter.listen( + boostHubCreateCloudSpaceEventHandler + ) return () => { boostHubSubscriptionDeleteEventEmitter.unlisten( boostHubSubscriptionDeleteEventHandler @@ -334,6 +331,9 @@ const App = () => { boostHubCreateLocalSpaceEventEmitter.unlisten( boostHubCreateLocalSpaceEventHandler ) + boostHubCreateCloudSpaceEventEmitter.unlisten( + boostHubCreateCloudSpaceEventHandler + ) } }, [push, setPreferences, setGeneralStatus]) const { boostHubTeams } = generalStatus @@ -356,6 +356,7 @@ const App = () => { }, [storageMap, boostHubTeams, navigateToStorage, push] ) + useEffect(() => { addIpcListener('switch-workspace', switchWorkspaceHandler) return () => { @@ -363,6 +364,17 @@ const App = () => { } }, [switchWorkspaceHandler]) + useEffect(() => { + const createCloudSpaceHandler = () => { + boostHubCreateCloudSpaceEventEmitter.dispatch() + } + addIpcListener('create-cloud-space', createCloudSpaceHandler) + + return () => { + removeIpcListener('create-cloud-space', createCloudSpaceHandler) + } + }, [push]) + useBoostNoteProtocol() const { showingCloudIntroModal } = useCloudIntroModal() diff --git a/src/components/atoms/BoostHubWebview.tsx b/src/components/atoms/BoostHubWebview.tsx index 6efd1d53b9..28b1258948 100644 --- a/src/components/atoms/BoostHubWebview.tsx +++ b/src/components/atoms/BoostHubWebview.tsx @@ -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 @@ -70,7 +70,6 @@ const BoostHubWebview = ({ const { preferences } = usePreferences() const { signOut } = useBoostHub() const domReadyRef = useRef(false) - const { push } = useRouter() const cloudUser = preferences['cloud.user'] const accessToken = useMemo(() => { @@ -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] }) diff --git a/src/lib/events.ts b/src/lib/events.ts index b96905eb5d..3a81597143 100644 --- a/src/lib/events.ts +++ b/src/lib/events.ts @@ -118,6 +118,10 @@ export const boostHubCreateLocalSpaceEventEmitter = createCustomEventEmitter( 'BoostHub:createLocalSpace' ) +export const boostHubCreateCloudSpaceEventEmitter = createCustomEventEmitter( + 'BoostHub:createCloudSpace' +) + export const boostHubToggleSidebarTreeEventEmitter = createCustomEventEmitter( 'BoostHub:toggleSidebarTree' )