diff --git a/src/features/file/index.tsx b/src/features/file/index.tsx index 6e9737f..524f2a2 100644 --- a/src/features/file/index.tsx +++ b/src/features/file/index.tsx @@ -28,6 +28,7 @@ interface InternalFilesContextType { interface FilesContextType { readonly files: Accessor, readonly root: Accessor, + readonly loading: Accessor, open(directory: FileSystemDirectoryHandle): void; get(key: string): Accessor @@ -109,7 +110,7 @@ const serverContext = (): InternalFilesContextType => ({ export const FilesProvider: ParentComponent = (props) => { const internal = isServer ? serverContext() : clientContext(); - const [state, setState] = createStore<{ openedFiles: FileEntity[], root: FileSystemDirectoryHandle | undefined }>({ openedFiles: [], root: undefined }); + const [state, setState] = createStore<{ loading: boolean, openedFiles: FileEntity[], root: FileSystemDirectoryHandle | undefined }>({ loading: true, openedFiles: [], root: undefined }); internal.onChange(async () => { setState('openedFiles', await internal.entries()); @@ -117,19 +118,19 @@ export const FilesProvider: ParentComponent = (props) => { onMount(() => { (async () => { - const [root, files] = await Promise.all([ + const [root, openedFiles] = await Promise.all([ internal.get(ROOT), internal.entries(), ]); - setState('root', root); - setState('openedFiles', files); + setState(prev => ({ ...prev, loading: false, root, openedFiles })); })(); }); const context: FilesContextType = { files: createMemo(() => state.openedFiles), root: createMemo(() => state.root), + loading: createMemo(() => state.loading), async open(directory: FileSystemDirectoryHandle) { await internal.remove(...(await internal.keys())); diff --git a/src/routes/(editor).tsx b/src/routes/(editor).tsx index faa92bf..05b6f5b 100644 --- a/src/routes/(editor).tsx +++ b/src/routes/(editor).tsx @@ -68,7 +68,7 @@ export default function Editor(props: ParentProps) {