1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-28 22:51: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">
{#each Object.entries(items) as [path, tree]}
{#if path !== '\0'}
{@const value = joinPaths(parent, path)}
{@const key = value + getColor(value)}
{#key key}
<li>
<Tree {parent} value={path} {tree} {icons} {active} {getLink} {getColor} />
</li>
{/key}
{/if}
{@const value = joinPaths(parent, path)}
{@const key = value + getColor(value)}
{#key key}
<li>
<Tree {parent} value={path} {tree} {icons} {active} {getLink} {getColor} />
</li>
{/key}
{/each}
</ul>

View file

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

View file

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