1
0
forked from Cutlery/immich
Files
immich-quadlet/web/src/lib/services/trash.service.ts
T
Jason Rasmussen a16d233a0c chore(web): sort imports (#27922)
* feat: sort imports

* fix: something?
2026-04-21 14:51:38 -04:00

55 lines
1.6 KiB
TypeScript

import { emptyTrash, restoreTrash } from '@immich/sdk';
import { modalManager, toastManager, type ActionItem } from '@immich/ui';
import { mdiDeleteForeverOutline, mdiHistory } from '@mdi/js';
import type { MessageFormatter } from 'svelte-i18n';
import { handleError } from '$lib/utils/handle-error';
import { getFormatter } from '$lib/utils/i18n';
export const getTrashActions = ($t: MessageFormatter) => {
const RestoreAll: ActionItem = {
title: $t('restore_all'),
icon: mdiHistory,
onAction: () => handleRestoreTrash(),
};
const Empty: ActionItem = {
title: $t('empty_trash'),
icon: mdiDeleteForeverOutline,
onAction: () => handleEmptyTrash(),
};
return { RestoreAll, Empty };
};
export const handleEmptyTrash = async () => {
const $t = await getFormatter();
const confirmed = await modalManager.showDialog({ prompt: $t('empty_trash_confirmation') });
if (!confirmed) {
return;
}
try {
const { count } = await emptyTrash();
toastManager.primary($t('assets_permanently_deleted_count', { values: { count } }));
} catch (error) {
handleError(error, $t('errors.unable_to_empty_trash'));
}
};
export const handleRestoreTrash = async () => {
const $t = await getFormatter();
const confirmed = await modalManager.showDialog({ prompt: $t('assets_restore_confirmation') });
if (!confirmed) {
return;
}
try {
const { count } = await restoreTrash();
toastManager.primary($t('assets_restored_count', { values: { count } }));
} catch (error) {
handleError(error, $t('errors.unable_to_restore_trash'));
}
};