mirror of
https://github.com/immich-app/immich.git
synced 2025-01-10 13:56:47 +01:00
26 lines
951 B
TypeScript
26 lines
951 B
TypeScript
|
import { notificationController, NotificationType } from '$lib/components/shared-components/notification/notification';
|
||
|
import { api } from '@api';
|
||
|
import { handleError } from './handle-error';
|
||
|
|
||
|
export type OnDelete = (assetId: string) => void;
|
||
|
export type OnRestore = (ids: string[]) => void;
|
||
|
export type OnArchive = (ids: string[], isArchived: boolean) => void;
|
||
|
export type OnFavorite = (ids: string[], favorite: boolean) => void;
|
||
|
export type OnStack = (ids: string[]) => void;
|
||
|
|
||
|
export const deleteAssets = async (force: boolean, onAssetDelete: OnDelete, ids: string[]) => {
|
||
|
try {
|
||
|
await api.assetApi.deleteAssets({ assetBulkDeleteDto: { ids, force } });
|
||
|
for (const id of ids) {
|
||
|
onAssetDelete(id);
|
||
|
}
|
||
|
|
||
|
notificationController.show({
|
||
|
message: `${force ? 'Permanently deleted' : 'Trashed'} ${ids.length} assets`,
|
||
|
type: NotificationType.Info,
|
||
|
});
|
||
|
} catch (e) {
|
||
|
handleError(e, 'Error deleting assets');
|
||
|
}
|
||
|
};
|