refactor(web): folders store (#14305)

* refactor(web): folders store

* use typescript private
This commit is contained in:
Michel Heusschen
2024-11-23 20:22:13 +01:00
committed by GitHub
parent 454836b551
commit c33b918d74
7 changed files with 52 additions and 81 deletions
@@ -9,7 +9,7 @@
import TreeItems from '$lib/components/shared-components/tree/tree-items.svelte';
import { AppRoute, QueryParameter } from '$lib/constants';
import type { Viewport } from '$lib/stores/assets.store';
import { foldersStore } from '$lib/stores/folders.store';
import { foldersStore } from '$lib/stores/folders.svelte';
import { buildTree, normalizeTreePath } from '$lib/utils/tree-utils';
import { mdiFolder, mdiFolderHome, mdiFolderOutline } from '@mdi/js';
import { onMount } from 'svelte';
@@ -27,7 +27,7 @@
const viewport: Viewport = $state({ width: 0, height: 0 });
let pathSegments = $derived(data.path ? data.path.split('/') : []);
let tree = $derived(buildTree($foldersStore?.uniquePaths || []));
let tree = $derived(buildTree(foldersStore.uniquePaths));
let currentPath = $derived($page.url.searchParams.get(QueryParameter.PATH) || '');
let currentTreeItems = $derived(currentPath ? data.currentFolders : Object.keys(tree));
@@ -1,10 +1,9 @@
import { QueryParameter } from '$lib/constants';
import { foldersStore } from '$lib/stores/folders.store';
import { foldersStore } from '$lib/stores/folders.svelte';
import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { buildTree, normalizeTreePath } from '$lib/utils/tree-utils';
import { get } from 'svelte/store';
import type { PageLoad } from './$types';
export const load = (async ({ params, url }) => {
@@ -13,18 +12,16 @@ export const load = (async ({ params, url }) => {
const $t = await getFormatter();
await foldersStore.fetchUniquePaths();
const { uniquePaths } = get(foldersStore);
let pathAssets = null;
const path = url.searchParams.get(QueryParameter.PATH);
if (path) {
await foldersStore.fetchAssetsByPath(path);
const { assets } = get(foldersStore);
pathAssets = assets[path] || null;
pathAssets = foldersStore.assets[path] || null;
}
let tree = buildTree(uniquePaths || []);
let tree = buildTree(foldersStore.uniquePaths);
const parts = normalizeTreePath(path || '').split('/');
for (const part of parts) {
tree = tree?.[part];