feat(web): add archive shortcut to grid ()

* 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:
Snowknight26 2024-06-06 18:23:49 -05:00 committed by GitHub
parent c6c480c882
commit 7a46f80ddc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 84 additions and 66 deletions
web/src/lib/utils

View file

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