mirror of
https://github.com/immich-app/immich.git
synced 2025-12-28 09:14:59 +03:00
refactor: album delete (#23773)
This commit is contained in:
@@ -1,7 +1,42 @@
|
||||
import { eventManager } from '$lib/managers/event-manager.svelte';
|
||||
import { downloadArchive } from '$lib/utils/asset-utils';
|
||||
import { handleError } from '$lib/utils/handle-error';
|
||||
import { getFormatter } from '$lib/utils/i18n';
|
||||
import type { AlbumResponseDto } from '@immich/sdk';
|
||||
import { modalManager } from '@immich/ui';
|
||||
import { deleteAlbum, type AlbumResponseDto } from '@immich/sdk';
|
||||
import { modalManager, toastManager } from '@immich/ui';
|
||||
|
||||
export const handleDeleteAlbum = async (album: AlbumResponseDto, options?: { prompt?: boolean; notify?: boolean }) => {
|
||||
const $t = await getFormatter();
|
||||
const { prompt = true, notify = true } = options ?? {};
|
||||
|
||||
if (prompt) {
|
||||
const confirmation =
|
||||
album.albumName.length > 0
|
||||
? $t('album_delete_confirmation', { values: { album: album.albumName } })
|
||||
: $t('unnamed_album_delete_confirmation');
|
||||
const description = $t('album_delete_confirmation_description');
|
||||
|
||||
const success = await modalManager.showDialog({ prompt: `${confirmation} ${description}` });
|
||||
if (!success) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await deleteAlbum({ id: album.id });
|
||||
|
||||
eventManager.emit('AlbumDelete', album);
|
||||
|
||||
if (notify) {
|
||||
toastManager.success();
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
handleError(error, $t('errors.unable_to_delete_album'));
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const handleDownloadAlbum = async (album: AlbumResponseDto) => {
|
||||
await downloadArchive(`${album.albumName}.zip`, { albumId: album.id });
|
||||
|
||||
Reference in New Issue
Block a user