-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use banner for app update prompt (#100)
* Added new prompt for update UI * Fixed navigation progress position * Use Collapse instead of Fade * Fixed top padding for main content container * Fixed banner border bottom styles * Do not show update banner if closed until page refreshed * Removed old prompt for update * Show UpdateAppBanner on login page * features/user/updateApp → features/updateApp * Fixed banner styles, added supporting illustration * Moved subheaderElevation to SubheaderProps
- Loading branch information
Showing
13 changed files
with
181 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './ui'; | ||
export * as updateAppModel from './model'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useRegisterSW } from 'virtual:pwa-register/react'; | ||
import { | ||
type FC, | ||
type PropsWithChildren, | ||
useCallback, | ||
createContext, | ||
useContext, | ||
useMemo, | ||
} from 'react'; | ||
|
||
export interface State { | ||
updateAvailable: boolean; | ||
reload: () => Promise<void>; | ||
close: () => void; | ||
} | ||
|
||
export const Context = createContext<State>({ | ||
updateAvailable: false, | ||
reload: () => Promise.resolve(), | ||
close: () => {}, | ||
}); | ||
|
||
export const useUpdateApp = (): State => useContext(Context); | ||
|
||
export const Provider: FC<PropsWithChildren> = ({ children }) => { | ||
const registerSW = useRegisterSW({ | ||
onRegisteredSW: async (_, registration) => { | ||
await registration?.update(); | ||
}, | ||
}); | ||
|
||
const { | ||
needRefresh: [updateAvailable, setUpdateAvailable], | ||
updateServiceWorker, | ||
} = registerSW; | ||
|
||
const reload = useCallback((): Promise<void> => updateServiceWorker(true), [updateServiceWorker]); | ||
|
||
const close = useCallback((): void => { | ||
setUpdateAvailable(false); | ||
}, [setUpdateAvailable]); | ||
|
||
const state = useMemo<State>( | ||
() => ({ | ||
updateAvailable, | ||
reload, | ||
close, | ||
}), | ||
[close, updateAvailable, reload], | ||
); | ||
|
||
return <Context.Provider value={state}>{children}</Context.Provider>; | ||
}; |
62 changes: 62 additions & 0 deletions
62
src/frontend/src/features/updateApp/ui/UpdateAppBanner.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import BrowserUpdatedIcon from '@mui/icons-material/BrowserUpdated'; | ||
import { | ||
Avatar, | ||
Box, | ||
Button, | ||
Collapse, | ||
Container, | ||
Divider, | ||
Paper, | ||
Typography, | ||
} from '@mui/material'; | ||
import { type FC } from 'react'; | ||
import { useUpdateApp } from '../model'; | ||
|
||
export const UpdateAppBanner: FC = () => { | ||
const { updateAvailable, reload, close } = useUpdateApp(); | ||
|
||
return ( | ||
<Collapse in={updateAvailable}> | ||
<Container disableGutters> | ||
<Box | ||
component={Paper} | ||
role="dialog" | ||
aria-modal="false" | ||
aria-label="Update app banner" | ||
square | ||
variant="elevation" | ||
tabIndex={-1} | ||
elevation={0} | ||
pt={3} | ||
pb={1} | ||
display="flex" | ||
flexDirection={{ xs: 'column', sm: 'row' }} | ||
justifyContent={'space-between'} | ||
alignItems={{ xs: 'flex-start', sm: 'flex-end' }} | ||
gap={{ xs: 0, sm: 1, md: '90px' }} | ||
> | ||
<Box display="flex" pl={2} pr={{ xs: 2, sm: 0 }} gap={{ xs: 2, sm: 3 }}> | ||
<Avatar sx={theme => ({ bgcolor: theme.palette.primary.main })}> | ||
<BrowserUpdatedIcon /> | ||
</Avatar> | ||
<Typography paragraph marginBottom={1}> | ||
<Typography fontWeight="bold">New update available</Typography> | ||
<Typography variant="body2"> | ||
Click on reload button to update the application | ||
</Typography> | ||
</Typography> | ||
</Box> | ||
<Box display="flex" px={{ xs: 1, sm: 2 }} gap={1} alignSelf="flex-end"> | ||
<Button onClick={close} variant="text"> | ||
Close | ||
</Button> | ||
<Button onClick={reload} variant="text"> | ||
Reload | ||
</Button> | ||
</Box> | ||
</Box> | ||
</Container> | ||
<Divider /> | ||
</Collapse> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './UpdateAppBanner'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.