mirror of
https://github.com/immich-app/immich.git
synced 2025-07-03 21:40:00 +02:00
feat(web): add archive shortcut to grid (#9499)
* feat(web): add archive shortcut to grid * Fix error * Don't unnecessarily pass parameter * Use an existing function to close the menu * Deduplicate type --------- Co-authored-by: Alex <alex.tran1502@gmail.com> Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
parent
c6c480c882
commit
7a46f80ddc
5 changed files with 84 additions and 66 deletions
web/src/lib/utils
|
@ -14,6 +14,7 @@ import {
|
|||
getAssetInfo,
|
||||
getBaseUrl,
|
||||
getDownloadInfo,
|
||||
updateAsset,
|
||||
updateAssets,
|
||||
type AlbumResponseDto,
|
||||
type AssetResponseDto,
|
||||
|
@ -23,6 +24,7 @@ import {
|
|||
type UserResponseDto,
|
||||
} from '@immich/sdk';
|
||||
import { DateTime } from 'luxon';
|
||||
import { t as translate } from 'svelte-i18n';
|
||||
import { get } from 'svelte/store';
|
||||
import { handleError } from './handle-error';
|
||||
|
||||
|
@ -397,6 +399,53 @@ export const selectAllAssets = async (assetStore: AssetStore, assetInteractionSt
|
|||
}
|
||||
};
|
||||
|
||||
export const toggleArchive = async (asset: AssetResponseDto) => {
|
||||
try {
|
||||
const data = await updateAsset({
|
||||
id: asset.id,
|
||||
updateAssetDto: {
|
||||
isArchived: !asset.isArchived,
|
||||
},
|
||||
});
|
||||
|
||||
asset.isArchived = data.isArchived;
|
||||
|
||||
notificationController.show({
|
||||
type: NotificationType.Info,
|
||||
message: asset.isArchived ? `Added to archive` : `Removed from archive`,
|
||||
});
|
||||
} catch (error) {
|
||||
handleError(error, `Unable to ${asset.isArchived ? `remove asset from` : `add asset to`} archive`);
|
||||
}
|
||||
|
||||
return asset;
|
||||
};
|
||||
|
||||
export const archiveAssets = async (assets: AssetResponseDto[], archive: boolean) => {
|
||||
const isArchived = archive;
|
||||
const ids = assets.map(({ id }) => id);
|
||||
|
||||
try {
|
||||
if (ids.length > 0) {
|
||||
await updateAssets({ assetBulkUpdateDto: { ids, isArchived } });
|
||||
}
|
||||
|
||||
for (const asset of assets) {
|
||||
asset.isArchived = isArchived;
|
||||
}
|
||||
|
||||
const t = get(translate);
|
||||
notificationController.show({
|
||||
message: `${isArchived ? t('archived') : t('unarchived')} ${ids.length}`,
|
||||
type: NotificationType.Info,
|
||||
});
|
||||
} catch (error) {
|
||||
handleError(error, `Unable to ${isArchived ? 'archive' : 'unarchive'}`);
|
||||
}
|
||||
|
||||
return ids;
|
||||
};
|
||||
|
||||
export const delay = async (ms: number) => {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue