Skip to content

Commit

Permalink
Manual refresh (#106)
Browse files Browse the repository at this point in the history
* feat: add a manual refresh button
* 📸 Updated screenshots

Co-authored-by: 🤖 ViteShot <viteshot-bot@zenc.io>
  • Loading branch information
mscharley and 🤖 ViteShot authored Mar 15, 2022
1 parent d068d41 commit a5aec96
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 10 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"@mui/material": "5.5.0",
"@reduxjs/toolkit": "1.8.0",
"@uiw/react-codemirror": "4.5.1",
"classnames": "^2.3.1",
"compare-versions": "4.1.3",
"electron-log": "4.4.6",
"electron-store": "8.0.1",
Expand Down
58 changes: 54 additions & 4 deletions src/renderer/components/sidebar/SidebarFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,62 @@
import { closeCurrentFile, setActiveOverlay, setFatalError, setFileListing } from '~renderer/redux';
import { useAppDispatch, useAppSelector, useDebouncedState } from '~renderer/hooks';
import cn from 'classnames';
import HelpOutlineIcon from '@mui/icons-material/HelpOutline';
import IconButton from '@mui/material/IconButton';
import Paper from '@mui/material/Paper';
import { setActiveOverlay } from '~renderer/redux';
import Settings from '@mui/icons-material/SettingsSharp';
import RefreshIcon from '@mui/icons-material/Refresh';
import SettingsIcon from '@mui/icons-material/SettingsSharp';
import { styled } from '@mui/material';
import Tooltip from '@mui/material/Tooltip';
import { useAppDispatch } from '~renderer/hooks';

export interface SidebarFooterProps {
width: string;
}

const SpinningRefreshIcon = styled(RefreshIcon)`
&.spin {
animation-name: spin;
animation-duration: 1s;
animation-timing-function: linear;
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
`;

export const SidebarFooter: React.FC<SidebarFooterProps> = ({ width }) => {
const dispatch = useAppDispatch();
const currentFile = useAppSelector((s) => s.files.currentFile);
const [spinning, setSpinning, flushSpinning] = useDebouncedState(false, 1_000);

const handleRefresh: React.MouseEventHandler = () => {
setSpinning(true);
flushSpinning();

editorApi
.listNoteFiles()
.then((fs) => {
dispatch(setFileListing(fs));

const newFiles = Object.values(fs)
.flatMap((f) => f.categories)
.flatMap((c) => c.files);
if (newFiles.find((f) => f.url === currentFile?.url) == null) {
// Currently editing file no longer exists...
dispatch(closeCurrentFile());
}

setSpinning(false);
})
.catch((e: unknown) => {
dispatch(setFatalError(e));
});
};

return (
<Paper
Expand All @@ -35,7 +80,7 @@ export const SidebarFooter: React.FC<SidebarFooterProps> = ({ width }) => {
dispatch(setActiveOverlay('configuration'));
}}
>
<Settings />
<SettingsIcon />
</IconButton>
</Tooltip>
<Tooltip title='About'>
Expand All @@ -47,6 +92,11 @@ export const SidebarFooter: React.FC<SidebarFooterProps> = ({ width }) => {
<HelpOutlineIcon />
</IconButton>
</Tooltip>
<Tooltip title='Refresh notes list'>
<IconButton onClick={handleRefresh}>
<SpinningRefreshIcon className={cn({ spin: spinning })} />
</IconButton>
</Tooltip>
</Paper>
);
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a5aec96

Please sign in to comment.