refactor: album delete (#23773)

This commit is contained in:
Jason Rasmussen
2025-11-10 16:10:29 -05:00
committed by GitHub
parent dea95ac2e6
commit d5c5bdffcb
4 changed files with 69 additions and 59 deletions

View File

@@ -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 });