Skip to content

Commit 58ffe97

Browse files
committed
Try to open boost hub team settings when team route is active
1 parent 5f7ce94 commit 58ffe97

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

src/components/App.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ import {
5050
dispatchBoostHubLoginRequestEvent,
5151
listenBoostHubAccountDeleteEvent,
5252
unlistenBoostHubAccountDeleteEvent,
53+
dispatchBoostHubToggleSettingsEvent,
5354
} from '../lib/events'
5455
import {
5556
useCheckedFeatures,
5657
featureAppModeSelect,
5758
featureBoostHubIntro,
5859
} from '../lib/checkedFeatures'
5960
import BoostHubIntroModal from '../components/organisms/BoostHubIntroModal'
61+
import { useRouteParams } from '../lib/routeParams'
6062

6163
const LoadingText = styled.div`
6264
margin: 30px;
@@ -104,6 +106,7 @@ const App = () => {
104106
} = usePreferences()
105107
const { messageBox } = useDialog()
106108
const { fetchDesktopGlobalData } = useBoostHub()
109+
const routeParams = useRouteParams()
107110

108111
useEffectOnce(() => {
109112
initialize()
@@ -212,12 +215,22 @@ const App = () => {
212215
run()
213216
})
214217

218+
const boostHubTeamsShowPageIsActive =
219+
routeParams.name === 'boosthub.teams.show'
220+
215221
useEffect(() => {
216-
addIpcListener('preferences', togglePreferencesModal)
222+
const handler = () => {
223+
if (boostHubTeamsShowPageIsActive) {
224+
dispatchBoostHubToggleSettingsEvent()
225+
} else {
226+
togglePreferencesModal()
227+
}
228+
}
229+
addIpcListener('preferences', handler)
217230
return () => {
218-
removeIpcListener('preferences', togglePreferencesModal)
231+
removeIpcListener('preferences', handler)
219232
}
220-
}, [togglePreferencesModal])
233+
}, [togglePreferencesModal, boostHubTeamsShowPageIsActive])
221234

222235
useEffect(() => {
223236
const boostHubTeamCreateEventHandler = (event: BoostHubTeamCreateEvent) => {

src/components/atoms/BoostHubWebview.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface WebviewControl {
3737
goBack(): void
3838
goForward(): void
3939
openDevTools(): void
40+
sendMessage(channel: string, ...args: any[]): void
4041
}
4142

4243
interface BoostHubWebviewProps {
@@ -82,6 +83,10 @@ const BoostHubWebview = ({
8283
webviewRef.current!.openDevTools()
8384
}, [])
8485

86+
const sendMessage = useCallback((channel: string, ...args: any[]) => {
87+
webviewRef.current!.send(channel, ...args)
88+
}, [])
89+
8590
useEffect(() => {
8691
if (controlRef == null) {
8792
return
@@ -91,8 +96,9 @@ const BoostHubWebview = ({
9196
goBack,
9297
goForward,
9398
openDevTools,
99+
sendMessage,
94100
}
95-
}, [controlRef, reload, goBack, goForward, openDevTools])
101+
}, [controlRef, reload, goBack, goForward, openDevTools, sendMessage])
96102

97103
useEffect(() => {
98104
const webview = webviewRef.current!

src/components/pages/BoostHubTeamsShowPage.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useRef, useCallback } from 'react'
1+
import React, { useState, useRef, useCallback, useEffect } from 'react'
22
import { getBoostHubTeamPageUrl } from '../../lib/boosthub'
33
import styled from '../../lib/styled'
44
import { DidNavigateInPageEvent, DidNavigateEvent } from 'electron'
@@ -20,6 +20,10 @@ import {
2020
import Icon from '../atoms/Icon'
2121
import BoostHubWebview, { WebviewControl } from '../atoms/BoostHubWebview'
2222
import copy from 'copy-to-clipboard'
23+
import {
24+
listenBoostHubToggleSettingsEvent,
25+
unlistenBoostHubToggleSettingsEvent,
26+
} from '../../lib/events'
2327

2428
interface BoostHubTeamsShowPageProps {
2529
active: boolean
@@ -86,6 +90,20 @@ const BoostHubTeamsShowPage = ({
8690
copy(url)
8791
}, [url])
8892

93+
useEffect(() => {
94+
if (!active) {
95+
return
96+
}
97+
98+
const handler = () => {
99+
webviewControlRef.current!.sendMessage('toggle-settings')
100+
}
101+
listenBoostHubToggleSettingsEvent(handler)
102+
return () => {
103+
unlistenBoostHubToggleSettingsEvent(handler)
104+
}
105+
}, [active])
106+
89107
return (
90108
<Container key={domain} className={active ? 'active' : ''}>
91109
<div className='toolbar' onContextMenu={openToolbarContextMenu}>

src/lib/events.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,11 @@ export const {
153153
listen: listenBoostHubAccountDeleteEvent,
154154
unlisten: unlistenBoostHubAccountDeleteEvent,
155155
} = createCustomEventHelper(BoostHubAccountDeleteEventName)
156+
157+
const BoostHubToggleSettingsEventName = 'BoostHub:toggleSettings'
158+
export type BoostHubToggleSettingsEvent = CustomEvent
159+
export const {
160+
dispatch: dispatchBoostHubToggleSettingsEvent,
161+
listen: listenBoostHubToggleSettingsEvent,
162+
unlisten: unlistenBoostHubToggleSettingsEvent,
163+
} = createCustomEventHelper(BoostHubToggleSettingsEventName)

0 commit comments

Comments
 (0)