mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
refactor: add to album (#26366)
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import { goto } from '$app/navigation';
|
||||
import ToastAction from '$lib/components/ToastAction.svelte';
|
||||
import { authManager } from '$lib/managers/auth-manager.svelte';
|
||||
import { downloadManager } from '$lib/managers/download-manager.svelte';
|
||||
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
|
||||
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
|
||||
import { Route } from '$lib/route';
|
||||
import type { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
|
||||
import { preferences } from '$lib/stores/user.store';
|
||||
import { downloadRequest, withError } from '$lib/utils';
|
||||
@@ -13,10 +11,7 @@ import { getFormatter } from '$lib/utils/i18n';
|
||||
import { navigate } from '$lib/utils/navigation';
|
||||
import { asQueryString } from '$lib/utils/shared-links';
|
||||
import {
|
||||
addAssetsToAlbum as addAssets,
|
||||
addAssetsToAlbums as addToAlbums,
|
||||
AssetVisibility,
|
||||
BulkIdErrorReason,
|
||||
bulkTagAssets,
|
||||
createStack,
|
||||
deleteAssets,
|
||||
@@ -41,77 +36,6 @@ import { t } from 'svelte-i18n';
|
||||
import { get } from 'svelte/store';
|
||||
import { handleError } from './handle-error';
|
||||
|
||||
export const addAssetsToAlbum = async (albumId: string, assetIds: string[], showNotification = true) => {
|
||||
const result = await addAssets({
|
||||
...authManager.params,
|
||||
id: albumId,
|
||||
bulkIdsDto: {
|
||||
ids: assetIds,
|
||||
},
|
||||
});
|
||||
const count = result.filter(({ success }) => success).length;
|
||||
const duplicateErrorCount = result.filter(({ error }) => error === 'duplicate').length;
|
||||
const $t = get(t);
|
||||
|
||||
if (showNotification) {
|
||||
let description = $t('assets_cannot_be_added_to_album_count', { values: { count: assetIds.length } });
|
||||
if (count > 0) {
|
||||
description = $t('assets_added_to_album_count', { values: { count } });
|
||||
} else if (duplicateErrorCount > 0) {
|
||||
description = $t('assets_were_part_of_album_count', { values: { count: duplicateErrorCount } });
|
||||
}
|
||||
toastManager.custom(
|
||||
{
|
||||
component: ToastAction,
|
||||
props: {
|
||||
title: $t('info'),
|
||||
color: 'primary',
|
||||
description,
|
||||
button: {
|
||||
text: $t('view_album'),
|
||||
color: 'primary',
|
||||
onClick() {
|
||||
return goto(Route.viewAlbum({ id: albumId }));
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{ timeout: 5000 },
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export const addAssetsToAlbums = async (albumIds: string[], assetIds: string[], showNotification = true) => {
|
||||
const result = await addToAlbums({
|
||||
...authManager.params,
|
||||
albumsAddAssetsDto: {
|
||||
albumIds,
|
||||
assetIds,
|
||||
},
|
||||
});
|
||||
|
||||
if (!showNotification) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (showNotification) {
|
||||
const $t = get(t);
|
||||
|
||||
if (result.error === BulkIdErrorReason.Duplicate) {
|
||||
toastManager.info($t('assets_were_part_of_albums_count', { values: { count: assetIds.length } }));
|
||||
return result;
|
||||
}
|
||||
if (result.error) {
|
||||
toastManager.warning($t('assets_cannot_be_added_to_albums', { values: { count: assetIds.length } }));
|
||||
return result;
|
||||
}
|
||||
toastManager.success(
|
||||
$t('assets_added_to_albums_count', { values: { albumTotal: albumIds.length, assetTotal: assetIds.length } }),
|
||||
);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
export const tagAssets = async ({
|
||||
assetIds,
|
||||
tagIds,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { authManager } from '$lib/managers/auth-manager.svelte';
|
||||
import { uploadManager } from '$lib/managers/upload-manager.svelte';
|
||||
import { addAssetsToAlbums } from '$lib/services/album.service';
|
||||
import { uploadAssetsStore } from '$lib/stores/upload';
|
||||
import { user } from '$lib/stores/user.store';
|
||||
import { UploadState } from '$lib/types';
|
||||
import { uploadRequest } from '$lib/utils';
|
||||
import { addAssetsToAlbum } from '$lib/utils/asset-utils';
|
||||
import { ExecutorQueue } from '$lib/utils/executor-queue';
|
||||
import { asQueryString } from '$lib/utils/shared-links';
|
||||
import {
|
||||
@@ -213,7 +213,7 @@ async function fileUploader({
|
||||
|
||||
if (albumId) {
|
||||
uploadAssetsStore.updateItem(deviceAssetId, { message: $t('asset_adding_to_album') });
|
||||
await addAssetsToAlbum(albumId, [responseData.id], false);
|
||||
await addAssetsToAlbums([albumId], [responseData.id], { notify: false });
|
||||
uploadAssetsStore.updateItem(deviceAssetId, { message: $t('asset_added_to_album') });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user