1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-01 08:31:59 +00:00

use symbol instead of \0

This commit is contained in:
mertalev 2024-09-02 17:11:04 -04:00
parent 4d44628bec
commit 011520b127
No known key found for this signature in database
GPG key ID: 9181CD92C0A1C5E3
3 changed files with 16 additions and 18 deletions

View file

@ -12,14 +12,12 @@
<ul class="list-none ml-2"> <ul class="list-none ml-2">
{#each Object.entries(items) as [path, tree]} {#each Object.entries(items) as [path, tree]}
{#if path !== '\0'} {@const value = joinPaths(parent, path)}
{@const value = joinPaths(parent, path)} {@const key = value + getColor(value)}
{@const key = value + getColor(value)} {#key key}
{#key key} <li>
<li> <Tree {parent} value={path} {tree} {icons} {active} {getLink} {getColor} />
<Tree {parent} value={path} {tree} {icons} {active} {getLink} {getColor} /> </li>
</li> {/key}
{/key}
{/if}
{/each} {/each}
</ul> </ul>

View file

@ -1,5 +1,5 @@
export type RecursiveObject = { export type RecursiveObject = {
[key: string]: RecursiveObject; [key: string | symbol]: RecursiveObject;
}; };
export const normalizeTreePath = (path: string) => (path.at(-1) === '/' && path.length > 1 ? path.slice(0, -1) : path); export const normalizeTreePath = (path: string) => (path.at(-1) === '/' && path.length > 1 ? path.slice(0, -1) : path);
@ -32,14 +32,14 @@ export const getParentPath = (path: string) => {
}; };
export const isLeaf = (tree: RecursiveObject) => { export const isLeaf = (tree: RecursiveObject) => {
for (const entry in tree) { for (const _ in tree) {
if (entry !== '\0') { return false;
return false;
}
} }
return true; return true;
}; };
export const FOLDER_WITH_ASSETS_SYMBOL = Symbol('folder-with-assets');
export function buildTree(paths: string[]): RecursiveObject { export function buildTree(paths: string[]): RecursiveObject {
const root: RecursiveObject = {}; const root: RecursiveObject = {};
@ -52,7 +52,7 @@ export function buildTree(paths: string[]): RecursiveObject {
} }
current = current[part]; current = current[part];
} }
current['\0'] = {}; // mark as leaf current[FOLDER_WITH_ASSETS_SYMBOL] = {};
} }
return root; return root;
} }

View file

@ -3,7 +3,7 @@ import { foldersStore } from '$lib/stores/folders.store';
import { authenticate } from '$lib/utils/auth'; import { authenticate } from '$lib/utils/auth';
import { getFormatter } from '$lib/utils/i18n'; import { getFormatter } from '$lib/utils/i18n';
import { getAssetInfoFromParam } from '$lib/utils/navigation'; import { getAssetInfoFromParam } from '$lib/utils/navigation';
import { getPathParts, normalizeTreePath } from '$lib/utils/tree-utils'; import { FOLDER_WITH_ASSETS_SYMBOL, getPathParts, normalizeTreePath } from '$lib/utils/tree-utils';
import type { PageLoad } from './$types'; import type { PageLoad } from './$types';
export const load = (async ({ params, url }) => { export const load = (async ({ params, url }) => {
@ -27,7 +27,7 @@ export const load = (async ({ params, url }) => {
} }
// only fetch assets if the folder has assets // only fetch assets if the folder has assets
if (tree['\0']) { if (tree[FOLDER_WITH_ASSETS_SYMBOL]) {
const { assets } = await foldersStore.fetchAssetsByPath(path); const { assets } = await foldersStore.fetchAssetsByPath(path);
pathAssets = assets[path] || null; pathAssets = assets[path] || null;
} }
@ -36,7 +36,7 @@ export const load = (async ({ params, url }) => {
return { return {
asset, asset,
path, path,
currentFolders: Object.keys(tree || {}).filter((name) => name !== '\0'), currentFolders: Object.keys(tree || {}),
pathAssets, pathAssets,
meta: { meta: {
title: $t('folders'), title: $t('folders'),