Skip to content

Commit 6624596

Browse files
committed
Handle new-space ipc event from main window renderer
1 parent 1d2284d commit 6624596

File tree

2 files changed

+64
-45
lines changed

2 files changed

+64
-45
lines changed

src/cloud/components/Application.tsx

Lines changed: 59 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
mdiWeb,
4040
} from '@mdi/js'
4141
import { buildIconUrl } from '../api/files'
42-
import { sendToHost, useElectron, usingElectron } from '../lib/stores/electron'
42+
import { sendToHost, usingElectron } from '../lib/stores/electron'
4343
import ContentLayout, {
4444
ContentLayoutProps,
4545
} from '../../shared/components/templates/ContentLayout'
@@ -110,7 +110,6 @@ const Application = ({
110110
const { push, query, goBack, goForward, pathname } = useRouter()
111111
const [popOverState, setPopOverState] = useState<PopOverState>(null)
112112
const { openSettingsTab, closeSettingsTab } = useSettings()
113-
const { usingElectron, sendToElectron } = useElectron()
114113
const { openNewDocForm, openNewFolderForm } = useCloudResourceModals()
115114
const [showFuzzyNavigation, setShowFuzzyNavigation] = useState(false)
116115
const {
@@ -290,14 +289,8 @@ const Application = ({
290289
)
291290

292291
const onSpaceClick = useCallback(() => {
293-
if (!usingElectron) {
294-
setPopOverState('spaces')
295-
return
296-
}
297-
298-
setPopOverState(null)
299-
sendToElectron('sidebar-spaces')
300-
}, [usingElectron, sendToElectron])
292+
setPopOverState('spaces')
293+
}, [])
301294

302295
const sidebarHeader = useMemo(() => {
303296
return (
@@ -493,43 +486,64 @@ const Application = ({
493486
export default Application
494487

495488
function buildSpacesBottomRows(push: (url: string) => void, t: TFunction) {
496-
return [
497-
{
498-
label: t(lngKeys.CreateNewSpace),
499-
icon: mdiPlusCircleOutline,
500-
linkProps: {
501-
href: `${process.env.BOOST_HUB_BASE_URL}/cooperate`,
502-
onClick: (event: React.MouseEvent) => {
503-
event.preventDefault()
504-
push(`/cooperate`)
489+
return usingElectron
490+
? [
491+
{
492+
label: t(lngKeys.CreateNewSpace),
493+
icon: mdiPlusCircleOutline,
494+
linkProps: {
495+
href: `${process.env.BOOST_HUB_BASE_URL}/cooperate`,
496+
onClick: (event: React.MouseEvent) => {
497+
event.preventDefault()
498+
sendToHost('new-space')
499+
},
500+
},
505501
},
506-
},
507-
},
508-
{
509-
label: t(lngKeys.DownloadDesktopApp),
510-
icon: mdiDownload,
511-
linkProps: {
512-
href: 'https://github.com/BoostIO/BoostNote.next/releases/latest',
513-
target: '_blank',
514-
rel: 'noopener noreferrer',
515-
},
516-
},
517-
{
518-
label: t(lngKeys.LogOut),
519-
icon: mdiLogoutVariant,
520-
linkProps: {
521-
href: '/api/oauth/signout',
522-
onClick: (event: React.MouseEvent) => {
523-
event.preventDefault()
524-
if (usingElectron) {
525-
sendToHost('sign-out')
526-
} else {
527-
window.location.href = `${process.env.BOOST_HUB_BASE_URL}/api/oauth/signout`
528-
}
502+
{
503+
label: t(lngKeys.LogOut),
504+
icon: mdiLogoutVariant,
505+
linkProps: {
506+
href: '/api/oauth/signout',
507+
onClick: (event: React.MouseEvent) => {
508+
event.preventDefault()
509+
sendToHost('sign-out')
510+
},
511+
},
529512
},
530-
},
531-
},
532-
]
513+
]
514+
: [
515+
{
516+
label: t(lngKeys.CreateNewSpace),
517+
icon: mdiPlusCircleOutline,
518+
linkProps: {
519+
href: `${process.env.BOOST_HUB_BASE_URL}/cooperate`,
520+
onClick: (event: React.MouseEvent) => {
521+
event.preventDefault()
522+
push(`/cooperate`)
523+
},
524+
},
525+
},
526+
{
527+
label: t(lngKeys.DownloadDesktopApp),
528+
icon: mdiDownload,
529+
linkProps: {
530+
href: 'https://github.com/BoostIO/BoostNote.next/releases/latest',
531+
target: '_blank',
532+
rel: 'noopener noreferrer',
533+
},
534+
},
535+
{
536+
label: t(lngKeys.LogOut),
537+
icon: mdiLogoutVariant,
538+
linkProps: {
539+
href: '/api/oauth/signout',
540+
onClick: (event: React.MouseEvent) => {
541+
event.preventDefault()
542+
window.location.href = `${process.env.BOOST_HUB_BASE_URL}/api/oauth/signout`
543+
},
544+
},
545+
},
546+
]
533547
}
534548

535549
function isCodeMirrorTextAreaEvent(event: KeyboardEvent) {

src/components/atoms/BoostHubWebview.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { usePreferences } from '../../lib/preferences'
3737
import { openContextMenu, openExternal } from '../../lib/electronOnly'
3838
import { DidFailLoadEvent } from 'electron/main'
3939
import styled from '../../shared/lib/styled'
40+
import { useRouter } from '../../lib/router'
4041

4142
export interface WebviewControl {
4243
focus(): void
@@ -69,6 +70,7 @@ const BoostHubWebview = ({
6970
const { preferences } = usePreferences()
7071
const { signOut } = useBoostHub()
7172
const domReadyRef = useRef<boolean>(false)
73+
const { push } = useRouter()
7274
const cloudUser = preferences['cloud.user']
7375

7476
const accessToken = useMemo(() => {
@@ -143,6 +145,9 @@ const BoostHubWebview = ({
143145

144146
const ipcMessageEventHandler = (event: IpcMessageEvent) => {
145147
switch (event.channel) {
148+
case 'new-space':
149+
push('/app/boosthub/teams')
150+
break
146151
case 'router':
147152
boostHubAppRouterEventEmitter.dispatch({ target: event.args[0] })
148153
break

0 commit comments

Comments
 (0)