mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 16:16:55 +00:00
사소한 리팩토링
This commit is contained in:
@@ -1,18 +1,29 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from "svelte";
|
||||
import { FullscreenDiv } from "$lib/components/atoms";
|
||||
import { TopBar } from "$lib/components/molecules";
|
||||
import { getDownloadingFiles, clearDownloadedFiles } from "$lib/modules/file";
|
||||
import { bulkGetFileInfo } from "$lib/modules/filesystem";
|
||||
import {
|
||||
getDownloadingFiles,
|
||||
clearDownloadedFiles,
|
||||
type FileDownloadState,
|
||||
} from "$lib/modules/file";
|
||||
import { bulkGetFileInfo, type MaybeFileInfo } from "$lib/modules/filesystem";
|
||||
import { masterKeyStore } from "$lib/stores";
|
||||
import File from "./File.svelte";
|
||||
|
||||
const downloadingFiles = getDownloadingFiles();
|
||||
const filesPromise = $derived(
|
||||
bulkGetFileInfo(
|
||||
downloadingFiles.map(({ id }) => id),
|
||||
let downloadingFiles: { info: MaybeFileInfo; state: FileDownloadState }[] = $state([]);
|
||||
|
||||
onMount(async () => {
|
||||
const states = getDownloadingFiles();
|
||||
const infos = await bulkGetFileInfo(
|
||||
states.map(({ id }) => id),
|
||||
$masterKeyStore?.get(1)?.key!,
|
||||
),
|
||||
);
|
||||
);
|
||||
downloadingFiles = states.map((state) => ({
|
||||
info: infos.get(state.id)!,
|
||||
state,
|
||||
}));
|
||||
});
|
||||
|
||||
$effect(() => clearDownloadedFiles);
|
||||
</script>
|
||||
@@ -23,14 +34,11 @@
|
||||
|
||||
<TopBar />
|
||||
<FullscreenDiv>
|
||||
{#await filesPromise then files}
|
||||
<div class="space-y-2 pb-4">
|
||||
{#each downloadingFiles as state}
|
||||
{@const info = files.get(state.id)!}
|
||||
{#if info.exists}
|
||||
<File {state} {info} />
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
{/await}
|
||||
<div class="space-y-2 pb-4">
|
||||
{#each downloadingFiles as { info, state } (info.id)}
|
||||
{#if info.exists}
|
||||
<File {info} {state} />
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
</FullscreenDiv>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
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 IconCloud from "~icons/material-symbols/cloud";
|
||||
@@ -11,7 +11,7 @@
|
||||
import IconError from "~icons/material-symbols/error";
|
||||
|
||||
interface Props {
|
||||
info: FileInfo;
|
||||
info: SummarizedFileInfo;
|
||||
state: FileDownloadState;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,47 +33,38 @@
|
||||
|
||||
const toEntry =
|
||||
<T extends Exclude<Entry["type"], "parent">>(type: T) =>
|
||||
(details: Extract<Entry, { type: T }>["details"]) => ({
|
||||
type,
|
||||
name: details.name,
|
||||
details,
|
||||
});
|
||||
(details: Extract<Entry, { type: T }>["details"]) => ({ type, name: details.name, details });
|
||||
|
||||
let entries = $derived([
|
||||
...(showParentEntry ? ([{ type: "parent" }] as const) : []),
|
||||
...sortEntries(info.subDirectories.map(toEntry("directory"))),
|
||||
...sortEntries([
|
||||
...info.files.map(toEntry("file")),
|
||||
...getUploadingFiles(info.id).map(toEntry("uploading-file")),
|
||||
...(getUploadingFiles(info.id) as LiveFileUploadState[]).map(toEntry("uploading-file")),
|
||||
]),
|
||||
]);
|
||||
</script>
|
||||
|
||||
{#if entries.length > 0}
|
||||
<div class="pb-[4.5rem]">
|
||||
<RowVirtualizer
|
||||
count={entries.length}
|
||||
itemHeight={(index) => 56 + (index + 1 < entries.length ? 4 : 0)}
|
||||
>
|
||||
<RowVirtualizer count={entries.length} itemHeight={() => 56} itemGap={4}>
|
||||
{#snippet item(index)}
|
||||
{@const entry = entries[index]!}
|
||||
<div class={index + 1 < entries.length ? "pb-1" : ""}>
|
||||
{#if entry.type === "parent"}
|
||||
<ActionEntryButton class="h-14" onclick={onParentClick}>
|
||||
<DirectoryEntryLabel type="parent-directory" name=".." />
|
||||
</ActionEntryButton>
|
||||
{:else if entry.type === "directory"}
|
||||
<SubDirectory
|
||||
info={entry.details}
|
||||
onclick={onEntryClick}
|
||||
onOpenMenuClick={onEntryMenuClick}
|
||||
/>
|
||||
{:else if entry.type === "file"}
|
||||
<File info={entry.details} onclick={onEntryClick} onOpenMenuClick={onEntryMenuClick} />
|
||||
{:else}
|
||||
<UploadingFile state={entry.details} />
|
||||
{/if}
|
||||
</div>
|
||||
{#if entry.type === "parent"}
|
||||
<ActionEntryButton class="h-14" onclick={onParentClick}>
|
||||
<DirectoryEntryLabel type="parent-directory" name=".." />
|
||||
</ActionEntryButton>
|
||||
{:else if entry.type === "directory"}
|
||||
<SubDirectory
|
||||
info={entry.details}
|
||||
onclick={onEntryClick}
|
||||
onOpenMenuClick={onEntryMenuClick}
|
||||
/>
|
||||
{:else if entry.type === "file"}
|
||||
<File info={entry.details} onclick={onEntryClick} onOpenMenuClick={onEntryMenuClick} />
|
||||
{:else}
|
||||
<UploadingFile state={entry.details} />
|
||||
{/if}
|
||||
{/snippet}
|
||||
</RowVirtualizer>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user