-
-
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.
feat: add a new save indicator (#101)
- Loading branch information
Showing
7 changed files
with
115 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useAppSelector, useDebouncedState } from '~renderer/hooks'; | ||
import Box from '@mui/material/Box'; | ||
import type { BoxProps } from '@mui/system/Box'; | ||
import SaveAsSharp from '@mui/icons-material/SaveAsSharp'; | ||
import { styled } from '@mui/material'; | ||
import Typography from '@mui/material/Typography'; | ||
import { useEffect } from 'react'; | ||
|
||
const NotificationsBox = styled(Box)<BoxProps>((context) => ({ | ||
position: 'fixed', | ||
bottom: 0, | ||
right: 0, | ||
height: 35, | ||
display: 'flex', | ||
alignItems: 'center', | ||
flexDirection: 'row-reverse', | ||
columnGap: '0.5em', | ||
padding: '0 0.5em', | ||
borderTop: '1px solid', | ||
borderLeft: '1px solid', | ||
borderColor: context.theme.palette.text.disabled, | ||
borderRadius: '3px 0 0 0', | ||
pointerEvents: 'none', | ||
background: context.theme.palette.background.paper, | ||
})); | ||
|
||
const fontSize = 'small'; | ||
|
||
export const NotificationsOverlay: React.FC = () => { | ||
const isDev = useAppSelector((s) => s.about.details?.isDevBuild) ?? false; | ||
const notificationsState = useAppSelector((s) => s.notifications); | ||
const [saving, setSaving, flushSaving] = useDebouncedState(false, 2_000); | ||
|
||
useEffect(() => { | ||
setSaving(notificationsState.saving); | ||
if (notificationsState.saving) { | ||
flushSaving(); | ||
} | ||
}, [setSaving, flushSaving, notificationsState.saving]); | ||
|
||
const devBuild = isDev ? ( | ||
<Typography component='div' key='dev' fontSize={fontSize}> | ||
DEV BUILD | ||
</Typography> | ||
) : null; | ||
const saveIcon = saving ? <SaveAsSharp key='save' fontSize={fontSize} /> : null; | ||
|
||
const notifications = [devBuild, saveIcon].filter((x) => x != null); | ||
|
||
return notifications.length > 0 ? <NotificationsBox>{notifications}</NotificationsBox> : <></>; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { createAction, createSlice } from '@reduxjs/toolkit'; | ||
|
||
export interface NotificationsState { | ||
saving: boolean; | ||
} | ||
|
||
const initialState = { saving: false }; | ||
|
||
export const setSaving = createAction<boolean>('setSaving'); | ||
|
||
const slice = createSlice({ | ||
name: 'notifications', | ||
initialState, | ||
reducers: {}, | ||
extraReducers: (builder) => | ||
builder.addCase(setSaving, (state, { payload: saving }) => { | ||
state.saving = saving; | ||
}), | ||
}); | ||
|
||
export default slice.reducer; |
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