Skip to content

Commit

Permalink
Re-write ReduxStateSync lib in Frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Sep 19, 2024
1 parent 0596bd6 commit 3b203f2
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 249 deletions.
111 changes: 22 additions & 89 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
"@dnd-kit/core": "6.1.0",
"@dnd-kit/modifiers": "6.0.1",
"@mtes-mct/monitor-ui": "23.0.0",
"@paralleldrive/cuid2": "2.2.2",
"@reduxjs/toolkit": "2.2.7",
"@sentry/react": "7.117.0",
"@tanstack/react-table": "8.20.5",
"@tanstack/react-virtual": "3.10.7",
"broadcast-channel": "7.0.0",
"comlink": "4.4.1",
"date-fns": "3.6.0",
"dayjs": "1.11.13",
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/features/SideWindow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Alert } from './Alert'
import { BeaconMalfunctionBoard } from './BeaconMalfunctionBoard'
import { BannerStack } from './components/BannerStack'
import { Menu } from './Menu'
import { sideWindowActions } from './slice'
import { useIsSuperUser } from '../../auth/hooks/useIsSuperUser'
import { MissionEventContext } from '../../context/MissionEventContext'
import { SideWindowMenuKey } from '../../domain/entities/sideWindow/constants'
Expand Down Expand Up @@ -80,6 +81,10 @@ export function SideWindow() {
dispatch(getAllCurrentReportings())
dispatch(getInfractions())
dispatch(getAllGearCodes())

window.addEventListener('beforeunload', () => {
dispatch(sideWindowActions.close())
})
}, [dispatch])

return (
Expand Down
19 changes: 19 additions & 0 deletions frontend/src/libs/ReduxStateSync/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { ReduxStateSyncOptions } from './types'

export const BROADCAST_CHANNEL_NAME = 'monitorfish-channel'

export const DEFAULT_OPTIONS: ReduxStateSyncOptions = {
actionFilter: () => true
}

export enum MessageType {
DestroyTab = 'DestroyTab',
DispatchAction = 'DispatchAction',
GetInitialState = 'GetInitialState',
SendInitialState = 'SendInitialState'
}

export enum InternalActionType {
InitializeStateFromOtherTab = '&_INITIALIZE_STATE_FROM_OTHER_TAB',
SendStateToOtherTab = '&_SEND_STATE_TO_OTHER_TAB'
}
Loading

0 comments on commit 3b203f2

Please sign in to comment.