mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-15 22:38:47 +00:00
파일을 업로드하는 중에, 해당되는 디렉터리에 업로드 Progress를 표시하도록 구현
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { get, type Writable } from "svelte/store";
|
||||
import type { DirectoryInfo, FileInfo } from "$lib/stores";
|
||||
import { formatFileSize } from "$lib/modules/util";
|
||||
|
||||
export { formatDateTime } from "$lib/modules/util";
|
||||
|
||||
@@ -8,17 +7,19 @@ export enum SortBy {
|
||||
NAME_DESC,
|
||||
}
|
||||
|
||||
type SortFunc = (a: DirectoryInfo | FileInfo | null, b: DirectoryInfo | FileInfo | null) => number;
|
||||
type SortFunc = (a?: string, b?: string) => number;
|
||||
|
||||
const sortByNameAsc: SortFunc = (a, b) => {
|
||||
if (a && b) return a.name!.localeCompare(b.name!);
|
||||
if (a && b) return a.localeCompare(b);
|
||||
if (a) return -1;
|
||||
if (b) return 1;
|
||||
return 0;
|
||||
};
|
||||
|
||||
const sortByNameDesc: SortFunc = (a, b) => -sortByNameAsc(a, b);
|
||||
|
||||
export const sortEntries = <T extends DirectoryInfo | FileInfo>(
|
||||
entries: Writable<T | null>[],
|
||||
export const sortEntries = <T extends { name?: string }>(
|
||||
entries: T[],
|
||||
sortBy: SortBy = SortBy.NAME_ASC,
|
||||
) => {
|
||||
let sortFunc: SortFunc;
|
||||
@@ -28,5 +29,13 @@ export const sortEntries = <T extends DirectoryInfo | FileInfo>(
|
||||
sortFunc = sortByNameDesc;
|
||||
}
|
||||
|
||||
entries.sort((a, b) => sortFunc(get(a), get(b)));
|
||||
entries.sort((a, b) => sortFunc(a.name, b.name));
|
||||
};
|
||||
|
||||
export const formatUploadProgress = (progress?: number) => {
|
||||
return `${Math.floor((progress ?? 0) * 100)}%`;
|
||||
};
|
||||
|
||||
export const formatUploadRate = (rate?: number) => {
|
||||
return `${formatFileSize((rate ?? 0) / 8)}/s`;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user