mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 08:06:56 +00:00
사소한 리팩토링
This commit is contained in:
@@ -8,10 +8,11 @@
|
|||||||
count: number;
|
count: number;
|
||||||
item: Snippet<[index: number]>;
|
item: Snippet<[index: number]>;
|
||||||
itemHeight: (index: number) => number;
|
itemHeight: (index: number) => number;
|
||||||
|
itemGap?: number;
|
||||||
placeholder?: Snippet;
|
placeholder?: Snippet;
|
||||||
}
|
}
|
||||||
|
|
||||||
let { class: className, count, item, itemHeight, placeholder }: Props = $props();
|
let { class: className, count, item, itemHeight, itemGap, placeholder }: Props = $props();
|
||||||
|
|
||||||
let element: HTMLElement | undefined = $state();
|
let element: HTMLElement | undefined = $state();
|
||||||
let scrollMargin = $state(0);
|
let scrollMargin = $state(0);
|
||||||
@@ -20,6 +21,7 @@
|
|||||||
createWindowVirtualizer({
|
createWindowVirtualizer({
|
||||||
count,
|
count,
|
||||||
estimateSize: itemHeight,
|
estimateSize: itemHeight,
|
||||||
|
gap: itemGap,
|
||||||
scrollMargin,
|
scrollMargin,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -75,19 +75,14 @@
|
|||||||
<p class="font-medium">하위 카테고리의 파일</p>
|
<p class="font-medium">하위 카테고리의 파일</p>
|
||||||
</CheckBox>
|
</CheckBox>
|
||||||
</div>
|
</div>
|
||||||
<RowVirtualizer
|
<RowVirtualizer count={files.length} itemHeight={() => 48} itemGap={4}>
|
||||||
count={files.length}
|
|
||||||
itemHeight={(index) => 48 + (index + 1 < files.length ? 4 : 0)}
|
|
||||||
>
|
|
||||||
{#snippet item(index)}
|
{#snippet item(index)}
|
||||||
{@const { details } = files[index]!}
|
{@const { details } = files[index]!}
|
||||||
<div class={[index + 1 < files.length && "pb-1"]}>
|
<File
|
||||||
<File
|
info={details}
|
||||||
info={details}
|
onclick={onFileClick}
|
||||||
onclick={onFileClick}
|
onRemoveClick={!details.isRecursive ? onFileRemoveClick : undefined}
|
||||||
onRemoveClick={!details.isRecursive ? onFileRemoveClick : undefined}
|
/>
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
{/snippet}
|
{/snippet}
|
||||||
{#snippet placeholder()}
|
{#snippet placeholder()}
|
||||||
<p class="text-center text-gray-500">이 카테고리에 추가된 파일이 없어요.</p>
|
<p class="text-center text-gray-500">이 카테고리에 추가된 파일이 없어요.</p>
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ const isFileUploading = (status: FileUploadState["status"]) =>
|
|||||||
|
|
||||||
export const getUploadingFiles = (parentId?: DirectoryId) => {
|
export const getUploadingFiles = (parentId?: DirectoryId) => {
|
||||||
return uploadingFiles.filter(
|
return uploadingFiles.filter(
|
||||||
(file): file is LiveFileUploadState =>
|
(file) =>
|
||||||
(parentId === undefined || file.parentId === parentId) && isFileUploading(file.status),
|
(parentId === undefined || file.parentId === parentId) && isFileUploading(file.status),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,18 +1,29 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { onMount } from "svelte";
|
||||||
import { FullscreenDiv } from "$lib/components/atoms";
|
import { FullscreenDiv } from "$lib/components/atoms";
|
||||||
import { TopBar } from "$lib/components/molecules";
|
import { TopBar } from "$lib/components/molecules";
|
||||||
import { getDownloadingFiles, clearDownloadedFiles } from "$lib/modules/file";
|
import {
|
||||||
import { bulkGetFileInfo } from "$lib/modules/filesystem";
|
getDownloadingFiles,
|
||||||
|
clearDownloadedFiles,
|
||||||
|
type FileDownloadState,
|
||||||
|
} from "$lib/modules/file";
|
||||||
|
import { bulkGetFileInfo, type MaybeFileInfo } from "$lib/modules/filesystem";
|
||||||
import { masterKeyStore } from "$lib/stores";
|
import { masterKeyStore } from "$lib/stores";
|
||||||
import File from "./File.svelte";
|
import File from "./File.svelte";
|
||||||
|
|
||||||
const downloadingFiles = getDownloadingFiles();
|
let downloadingFiles: { info: MaybeFileInfo; state: FileDownloadState }[] = $state([]);
|
||||||
const filesPromise = $derived(
|
|
||||||
bulkGetFileInfo(
|
onMount(async () => {
|
||||||
downloadingFiles.map(({ id }) => id),
|
const states = getDownloadingFiles();
|
||||||
|
const infos = await bulkGetFileInfo(
|
||||||
|
states.map(({ id }) => id),
|
||||||
$masterKeyStore?.get(1)?.key!,
|
$masterKeyStore?.get(1)?.key!,
|
||||||
),
|
);
|
||||||
);
|
downloadingFiles = states.map((state) => ({
|
||||||
|
info: infos.get(state.id)!,
|
||||||
|
state,
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
$effect(() => clearDownloadedFiles);
|
$effect(() => clearDownloadedFiles);
|
||||||
</script>
|
</script>
|
||||||
@@ -23,14 +34,11 @@
|
|||||||
|
|
||||||
<TopBar />
|
<TopBar />
|
||||||
<FullscreenDiv>
|
<FullscreenDiv>
|
||||||
{#await filesPromise then files}
|
<div class="space-y-2 pb-4">
|
||||||
<div class="space-y-2 pb-4">
|
{#each downloadingFiles as { info, state } (info.id)}
|
||||||
{#each downloadingFiles as state}
|
{#if info.exists}
|
||||||
{@const info = files.get(state.id)!}
|
<File {info} {state} />
|
||||||
{#if info.exists}
|
{/if}
|
||||||
<File {state} {info} />
|
{/each}
|
||||||
{/if}
|
</div>
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
{/await}
|
|
||||||
</FullscreenDiv>
|
</FullscreenDiv>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { FileDownloadState } from "$lib/modules/file";
|
import type { FileDownloadState } from "$lib/modules/file";
|
||||||
import type { FileInfo } from "$lib/modules/filesystem";
|
import type { SummarizedFileInfo } from "$lib/modules/filesystem";
|
||||||
import { formatNetworkSpeed } from "$lib/utils";
|
import { formatNetworkSpeed } from "$lib/utils";
|
||||||
|
|
||||||
import IconCloud from "~icons/material-symbols/cloud";
|
import IconCloud from "~icons/material-symbols/cloud";
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
import IconError from "~icons/material-symbols/error";
|
import IconError from "~icons/material-symbols/error";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
info: FileInfo;
|
info: SummarizedFileInfo;
|
||||||
state: FileDownloadState;
|
state: FileDownloadState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,47 +33,38 @@
|
|||||||
|
|
||||||
const toEntry =
|
const toEntry =
|
||||||
<T extends Exclude<Entry["type"], "parent">>(type: T) =>
|
<T extends Exclude<Entry["type"], "parent">>(type: T) =>
|
||||||
(details: Extract<Entry, { type: T }>["details"]) => ({
|
(details: Extract<Entry, { type: T }>["details"]) => ({ type, name: details.name, details });
|
||||||
type,
|
|
||||||
name: details.name,
|
|
||||||
details,
|
|
||||||
});
|
|
||||||
|
|
||||||
let entries = $derived([
|
let entries = $derived([
|
||||||
...(showParentEntry ? ([{ type: "parent" }] as const) : []),
|
...(showParentEntry ? ([{ type: "parent" }] as const) : []),
|
||||||
...sortEntries(info.subDirectories.map(toEntry("directory"))),
|
...sortEntries(info.subDirectories.map(toEntry("directory"))),
|
||||||
...sortEntries([
|
...sortEntries([
|
||||||
...info.files.map(toEntry("file")),
|
...info.files.map(toEntry("file")),
|
||||||
...getUploadingFiles(info.id).map(toEntry("uploading-file")),
|
...(getUploadingFiles(info.id) as LiveFileUploadState[]).map(toEntry("uploading-file")),
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if entries.length > 0}
|
{#if entries.length > 0}
|
||||||
<div class="pb-[4.5rem]">
|
<div class="pb-[4.5rem]">
|
||||||
<RowVirtualizer
|
<RowVirtualizer count={entries.length} itemHeight={() => 56} itemGap={4}>
|
||||||
count={entries.length}
|
|
||||||
itemHeight={(index) => 56 + (index + 1 < entries.length ? 4 : 0)}
|
|
||||||
>
|
|
||||||
{#snippet item(index)}
|
{#snippet item(index)}
|
||||||
{@const entry = entries[index]!}
|
{@const entry = entries[index]!}
|
||||||
<div class={index + 1 < entries.length ? "pb-1" : ""}>
|
{#if entry.type === "parent"}
|
||||||
{#if entry.type === "parent"}
|
<ActionEntryButton class="h-14" onclick={onParentClick}>
|
||||||
<ActionEntryButton class="h-14" onclick={onParentClick}>
|
<DirectoryEntryLabel type="parent-directory" name=".." />
|
||||||
<DirectoryEntryLabel type="parent-directory" name=".." />
|
</ActionEntryButton>
|
||||||
</ActionEntryButton>
|
{:else if entry.type === "directory"}
|
||||||
{:else if entry.type === "directory"}
|
<SubDirectory
|
||||||
<SubDirectory
|
info={entry.details}
|
||||||
info={entry.details}
|
onclick={onEntryClick}
|
||||||
onclick={onEntryClick}
|
onOpenMenuClick={onEntryMenuClick}
|
||||||
onOpenMenuClick={onEntryMenuClick}
|
/>
|
||||||
/>
|
{:else if entry.type === "file"}
|
||||||
{:else if entry.type === "file"}
|
<File info={entry.details} onclick={onEntryClick} onOpenMenuClick={onEntryMenuClick} />
|
||||||
<File info={entry.details} onclick={onEntryClick} onOpenMenuClick={onEntryMenuClick} />
|
{:else}
|
||||||
{:else}
|
<UploadingFile state={entry.details} />
|
||||||
<UploadingFile state={entry.details} />
|
{/if}
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</RowVirtualizer>
|
</RowVirtualizer>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user