svelte refactor
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
* and only closes the dialog if it resolves. A rejection keeps the dialog open
|
||||
* and surfaces an inline error, so failed renames/deletes don't silently vanish.
|
||||
*/
|
||||
import { errorMessage } from '$lib/utils/errors';
|
||||
|
||||
export interface ConfirmOptions {
|
||||
title: string;
|
||||
message?: string;
|
||||
@@ -87,7 +89,7 @@ class DialogStore {
|
||||
else await (action as (v: string) => Promise<void> | void)(value as string);
|
||||
} catch (err) {
|
||||
this.busy = false;
|
||||
this.error = err instanceof Error ? err.message : String(err);
|
||||
this.error = errorMessage(err);
|
||||
return; // keep the dialog open
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
import type { FolderItem } from '$lib/api/types';
|
||||
import { t } from '$lib/i18n/index.svelte';
|
||||
|
||||
// Re-exported so the files view's grouping-helper barrel stays a single import
|
||||
// site; the implementation lives in the shared time util.
|
||||
export { relativeTimeAgo } from '$lib/utils/time';
|
||||
|
||||
export type ViewMode = 'grid' | 'list';
|
||||
|
||||
// ── Group-by / display helpers ───────────────────────────────────────────────
|
||||
@@ -41,28 +45,6 @@ export function dateBucket(value: number | null | undefined): string {
|
||||
return String(toDate(value).getFullYear());
|
||||
}
|
||||
|
||||
/** Locale-aware relative "time ago" for grid-card metadata lines. */
|
||||
export function relativeTimeAgo(value: number | null | undefined): string {
|
||||
if (!value) return '';
|
||||
const date = toDate(value);
|
||||
if (Number.isNaN(date.getTime())) return '';
|
||||
const diffSec = Math.round((date.getTime() - Date.now()) / 1000);
|
||||
const abs = Math.abs(diffSec);
|
||||
const rtf = new Intl.RelativeTimeFormat(undefined, { numeric: 'auto' });
|
||||
const units: Array<[Intl.RelativeTimeFormatUnit, number]> = [
|
||||
['year', 31536000],
|
||||
['month', 2592000],
|
||||
['week', 604800],
|
||||
['day', 86400],
|
||||
['hour', 3600],
|
||||
['minute', 60]
|
||||
];
|
||||
for (const [unit, secs] of units) {
|
||||
if (abs >= secs) return rtf.format(Math.round(diffSec / secs), unit);
|
||||
}
|
||||
return rtf.format(diffSec, 'second');
|
||||
}
|
||||
|
||||
/** Localise a file `category` (e.g. "Image") via files.file_types.* keys. */
|
||||
export function typeLabel(category: string | null | undefined): string {
|
||||
if (!category) return t('files.file_types.document', 'Document');
|
||||
|
||||
Reference in New Issue
Block a user