Skip to content

Commit

Permalink
fix: Fixed backup restore menu not updating after switching files
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkoelle committed May 16, 2021
1 parent c086e4d commit 5e8953d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
19 changes: 9 additions & 10 deletions app/containers/FramelessTitleBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ export default function FramelessTitleBar(props: {
releaseName: '',
});
const [openReleaseNotes, setOpenReleaseNotes] = useState(false);
const [backupPaths, setBackupPaths] = useState<string[]>([]);
// Only for force reloading menu
const [, setBackupPaths] = useState<string[]>([]);

const setBackupFilePaths = () => {
const paths = fs
.readdirSync(Path.join(remote.app.getPath('userData'), 'Backup'))
.filter((p) => p.includes(Path.basename(workspace)));
setBackupPaths(paths);
};

useEffect(() => {
const acceleratorListener = (event) => {
Expand All @@ -61,13 +69,6 @@ export default function FramelessTitleBar(props: {
};
window.addEventListener('keydown', acceleratorListener, true);

const setBackupFilePaths = () => {
const paths = fs
.readdirSync(Path.join(remote.app.getPath('userData'), 'Backup'))
.filter((p) => p.includes(Path.basename(workspace)));
setBackupPaths(paths);
};

ipcRenderer.on(BACKUP_SUCCESSFUL, setBackupFilePaths);
return () => {
ipcRenderer.removeListener(BACKUP_SUCCESSFUL, setBackupFilePaths);
Expand Down Expand Up @@ -128,7 +129,6 @@ export default function FramelessTitleBar(props: {
unsavedChanges,
recentPaths,
setOpenFileError,
backupPaths,
setOpenExportDialog,
setExportSheetId,
setReload,
Expand Down Expand Up @@ -162,7 +162,6 @@ export default function FramelessTitleBar(props: {
workspace.length > 0 ? `${Path.parse(workspace).name} - ` : ''
}correctinator v${version}${unsavedChanges ? ' •' : ''}`}
onClose={() => {
console.log('onCLose');
currentWindow.close();
}}
onMinimize={() => currentWindow.minimize()}
Expand Down
4 changes: 3 additions & 1 deletion app/menu/FileMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const buildFileMenu = (
unsavedChanges,
recentPaths,
setOpenFileError,
backupPaths,
setOpenExportDialog,
setExportSheetId
) => {
Expand All @@ -39,6 +38,9 @@ const buildFileMenu = (
dispatch(reloadState());
}
};
const backupPaths = fs
.readdirSync(Path.join(remote.app.getPath('userData'), 'Backup'))
.filter((p) => p.includes(Path.basename(workspace)));

return {
label: 'File',
Expand Down
2 changes: 0 additions & 2 deletions app/menu/Menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const buildMenu = (
unsavedChanges,
recentPaths,
setOpenFileError,
backupPaths,
setOpenExportDialog,
setExportSheetId,
setReload,
Expand All @@ -29,7 +28,6 @@ const buildMenu = (
unsavedChanges,
recentPaths,
setOpenFileError,
backupPaths,
setOpenExportDialog,
setExportSheetId
),
Expand Down

0 comments on commit 5e8953d

Please sign in to comment.