mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-02 18:10:18 +05:30
feat(renderer): persist last-opened folder (mc-file-store) + restore on mount
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useFileStore } from '@/stores/file-store';
|
||||
|
||||
/**
|
||||
* On mount, re-opens the last folder if one was persisted via the file store's
|
||||
* zustand persist middleware. Idempotent — re-running with the same path is a
|
||||
* no-op (openFolder's list IPC call would just re-fetch, which is acceptable).
|
||||
*/
|
||||
export function useRestoreLastFolder(): void {
|
||||
useEffect(() => {
|
||||
const { rootPath, openFolder, tree } = useFileStore.getState();
|
||||
if (rootPath && !tree) {
|
||||
void openFolder(rootPath);
|
||||
}
|
||||
// Run once on mount only. Persist hydration happens before AppShell renders.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
}
|
||||
Reference in New Issue
Block a user