1
- import React , { useMemo , useState , useCallback , useEffect } from 'react'
1
+ import React , { useMemo , useState , useEffect } from 'react'
2
2
import Router from './Router'
3
3
import GlobalStyle from './GlobalStyle'
4
4
import { ThemeProvider } from 'styled-components'
@@ -22,10 +22,7 @@ import AppNavigator from './organisms/AppNavigator'
22
22
import { useRouter } from '../lib/router'
23
23
import { values } from '../lib/db/utils'
24
24
import { localLiteStorage } from 'ltstrg'
25
- import {
26
- defaultStorageCreatedKey ,
27
- appModeChosenKey ,
28
- } from '../lib/localStorageKeys'
25
+ import { defaultStorageCreatedKey } from '../lib/localStorageKeys'
29
26
import {
30
27
getPathByName ,
31
28
addIpcListener ,
@@ -45,6 +42,12 @@ import {
45
42
unlistenBoostHubTeamCreateEvent ,
46
43
BoostHubTeamCreateEvent ,
47
44
} from '../lib/events'
45
+ import {
46
+ useCheckedFeatures ,
47
+ featureAppModeSelect ,
48
+ featureBoostHubIntro ,
49
+ } from '../lib/checkedFeatures'
50
+ import BoostHubIntroModal from '../components/organisms/BoostHubIntroModal'
48
51
49
52
const LoadingText = styled . div `
50
53
margin: 30px;
@@ -94,7 +97,6 @@ const App = () => {
94
97
const { fetchDesktopGlobalData } = useBoostHub ( )
95
98
96
99
useEffectOnce ( ( ) => {
97
- const boostHubUserInfo = preferences [ 'boosthub.user' ]
98
100
initialize ( )
99
101
. then ( async ( storageMap ) => {
100
102
const storages = values ( storageMap )
@@ -142,68 +144,66 @@ const App = () => {
142
144
. catch ( ( error ) => {
143
145
console . error ( error )
144
146
} )
145
- . then ( ( ) => {
146
- const appModeChosen = localLiteStorage . getItem ( appModeChosenKey )
147
- if ( appModeChosen !== 'true' ) {
148
- setShowAppModeModal ( true )
149
- }
150
- localLiteStorage . setItem ( appModeChosenKey , 'true' )
151
- } )
152
- . then ( async ( ) => {
153
- if ( boostHubUserInfo == null ) {
154
- return
155
- }
156
- const { user, teams } = await fetchDesktopGlobalData ( )
157
- if ( user == null ) {
158
- setPreferences ( {
159
- 'boosthub.user' : undefined ,
160
- } )
161
- setGeneralStatus ( {
162
- boostHubTeams : [ ] ,
163
- } )
164
- return
165
- // User's auth is invalidated. Should go to auth page
166
- messageBox ( {
167
- title : 'Boost Hub login is required' ,
168
- message : 'Your BoostHub session has been expired.' ,
169
- buttons : [ 'Sign In Again' , 'Cancel' ] ,
170
- defaultButtonIndex : 0 ,
171
- iconType : DialogIconTypes . Warning ,
172
- onClose : ( value : number | null ) => {
173
- if ( value === 0 ) {
174
- return
175
- }
147
+ } )
176
148
177
- setPreferences ( {
178
- 'boosthub.user' : undefined ,
179
- } )
180
- setGeneralStatus ( {
181
- boostHubTeams : [ ] ,
182
- } )
183
- } ,
184
- } )
185
- return
186
- }
187
- setPreferences ( ( previousPreferences ) => {
188
- return {
189
- ...previousPreferences ,
190
- 'boosthub.user' : {
191
- id : user . id ,
192
- uniqueName : user . uniqueName ,
193
- displayName : user . displayName ,
194
- } ,
195
- }
149
+ useEffectOnce ( ( ) => {
150
+ const run = async ( ) => {
151
+ const boostHubUserInfo = preferences [ 'boosthub.user' ]
152
+ if ( boostHubUserInfo == null ) {
153
+ return
154
+ }
155
+ const { user, teams } = await fetchDesktopGlobalData ( )
156
+ if ( user == null ) {
157
+ setPreferences ( {
158
+ 'boosthub.user' : undefined ,
196
159
} )
197
160
setGeneralStatus ( {
198
- boostHubTeams : teams . map ( ( team ) => {
199
- return {
200
- id : team . id ,
201
- name : team . name ,
202
- domain : team . domain ,
161
+ boostHubTeams : [ ] ,
162
+ } )
163
+ return
164
+ // User's auth is invalidated. Should go to auth page
165
+ messageBox ( {
166
+ title : 'Boost Hub login is required' ,
167
+ message : 'Your BoostHub session has been expired.' ,
168
+ buttons : [ 'Sign In Again' , 'Cancel' ] ,
169
+ defaultButtonIndex : 0 ,
170
+ iconType : DialogIconTypes . Warning ,
171
+ onClose : ( value : number | null ) => {
172
+ if ( value === 0 ) {
173
+ return
203
174
}
204
- } ) ,
175
+
176
+ setPreferences ( {
177
+ 'boosthub.user' : undefined ,
178
+ } )
179
+ setGeneralStatus ( {
180
+ boostHubTeams : [ ] ,
181
+ } )
182
+ } ,
205
183
} )
184
+ return
185
+ }
186
+ setPreferences ( ( previousPreferences ) => {
187
+ return {
188
+ ...previousPreferences ,
189
+ 'boosthub.user' : {
190
+ id : user . id ,
191
+ uniqueName : user . uniqueName ,
192
+ displayName : user . displayName ,
193
+ } ,
194
+ }
206
195
} )
196
+ setGeneralStatus ( {
197
+ boostHubTeams : teams . map ( ( team ) => {
198
+ return {
199
+ id : team . id ,
200
+ name : team . name ,
201
+ domain : team . domain ,
202
+ }
203
+ } ) ,
204
+ } )
205
+ }
206
+ run ( )
207
207
} )
208
208
209
209
useEffect ( ( ) => {
@@ -254,11 +254,7 @@ const App = () => {
254
254
} , [ ] )
255
255
useGlobalKeyDownHandler ( keyboardHandler )
256
256
257
- const [ showAppModeModal , setShowAppModeModal ] = useState ( false )
258
-
259
- const closeAppModeModal = useCallback ( ( ) => {
260
- setShowAppModeModal ( false )
261
- } , [ ] )
257
+ const { isChecked } = useCheckedFeatures ( )
262
258
263
259
return (
264
260
< ThemeProvider theme = { selectTheme ( preferences [ 'general.theme' ] ) } >
@@ -271,11 +267,15 @@ const App = () => {
271
267
< >
272
268
{ preferences [ 'general.showAppNavigator' ] && < AppNavigator /> }
273
269
< Router />
270
+ { ! isChecked ( featureAppModeSelect ) ? (
271
+ < AppModeModal />
272
+ ) : (
273
+ ! isChecked ( featureBoostHubIntro ) && < BoostHubIntroModal />
274
+ ) }
274
275
</ >
275
276
) : (
276
277
< LoadingText > Loading Data...</ LoadingText >
277
278
) }
278
- { showAppModeModal && < AppModeModal closeModal = { closeAppModeModal } /> }
279
279
< GlobalStyle />
280
280
< Dialog />
281
281
< PreferencesModal />
0 commit comments