@@ -35,12 +35,15 @@ import { useGeneralStatus } from '../lib/generalStatus'
35
35
import { getFolderItemId } from '../lib/nav'
36
36
import AppModeModal from './organisms/AppModeModal'
37
37
import { useBoostNoteProtocol } from '../lib/protocol'
38
- import { useBoostHub } from '../lib/boosthub'
38
+ import { useBoostHub , getBoostHubTeamIconUrl } from '../lib/boosthub'
39
39
import { useDialog , DialogIconTypes } from '../lib/dialog'
40
40
import {
41
41
listenBoostHubTeamCreateEvent ,
42
42
unlistenBoostHubTeamCreateEvent ,
43
43
BoostHubTeamCreateEvent ,
44
+ BoostHubTeamUpdateEvent ,
45
+ listenBoostHubTeamUpdateEvent ,
46
+ unlistenBoostHubTeamUpdateEvent ,
44
47
} from '../lib/events'
45
48
import {
46
49
useCheckedFeatures ,
@@ -215,18 +218,55 @@ const App = () => {
215
218
} , [ togglePreferencesModal ] )
216
219
217
220
useEffect ( ( ) => {
218
- const boosthubTeamCreateEventHandler = ( event : BoostHubTeamCreateEvent ) => {
221
+ const boostHubTeamCreateEventHandler = ( event : BoostHubTeamCreateEvent ) => {
219
222
const team = event . detail . team
220
223
setGeneralStatus ( ( previousGeneralStatus ) => {
221
224
return {
222
- boostHubTeams : [ ...previousGeneralStatus . boostHubTeams ! , team ] ,
225
+ boostHubTeams : [
226
+ ...previousGeneralStatus . boostHubTeams ! ,
227
+ {
228
+ id : team . id ,
229
+ name : team . name ,
230
+ domain : team . domain ,
231
+ iconUrl :
232
+ team . icon != null
233
+ ? getBoostHubTeamIconUrl ( team . icon . location )
234
+ : undefined ,
235
+ } ,
236
+ ] ,
223
237
}
224
238
} )
225
239
push ( `/app/boosthub/teams/${ team . domain } ` )
226
240
}
227
- listenBoostHubTeamCreateEvent ( boosthubTeamCreateEventHandler )
241
+
242
+ const boostHubTeamUpdateEventHandler = ( event : BoostHubTeamUpdateEvent ) => {
243
+ const updatedTeam = event . detail . team
244
+ setGeneralStatus ( ( previousGeneralStatus ) => {
245
+ const teamMap =
246
+ previousGeneralStatus . boostHubTeams ! . reduce ( ( map , team ) => {
247
+ map . set ( team . id , team )
248
+ return map
249
+ } , new Map ( ) ) || new Map ( )
250
+ teamMap . set ( updatedTeam . id , {
251
+ id : updatedTeam . id ,
252
+ name : updatedTeam . name ,
253
+ domain : updatedTeam . domain ,
254
+ iconUrl :
255
+ updatedTeam . icon != null
256
+ ? getBoostHubTeamIconUrl ( updatedTeam . icon . location )
257
+ : undefined ,
258
+ } )
259
+ return {
260
+ boostHubTeams : [ ...teamMap . values ( ) ] ,
261
+ }
262
+ } )
263
+ }
264
+
265
+ listenBoostHubTeamCreateEvent ( boostHubTeamCreateEventHandler )
266
+ listenBoostHubTeamUpdateEvent ( boostHubTeamUpdateEventHandler )
228
267
return ( ) => {
229
- unlistenBoostHubTeamCreateEvent ( boosthubTeamCreateEventHandler )
268
+ unlistenBoostHubTeamCreateEvent ( boostHubTeamCreateEventHandler )
269
+ unlistenBoostHubTeamUpdateEvent ( boostHubTeamUpdateEventHandler )
230
270
}
231
271
} , [ push , setGeneralStatus ] )
232
272
0 commit comments