Merge branch 'main' into feature/add-language

This commit is contained in:
Chris Kruining 2024-12-18 16:32:31 +01:00
commit c2b7a9ccf3
No known key found for this signature in database
GPG key ID: EB894A3560CCCAD2
5 changed files with 48 additions and 30 deletions

View file

@ -28,6 +28,7 @@ interface InternalFilesContextType {
interface FilesContextType {
readonly files: Accessor<FileEntity[]>,
readonly root: Accessor<FileSystemDirectoryHandle | undefined>,
readonly loading: Accessor<boolean>,
open(directory: FileSystemDirectoryHandle): void;
get(key: string): Accessor<FileSystemDirectoryHandle | undefined>
@ -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()));