feat(web): add ctrl+a / ctrl+d shortcuts to select / deselect all assets ()

* feat(web): use ctrl+a / ctrl+d to select / deselect all assets

* fix(web): use shortcutList for ctrl+a / ctrl+d

* fix(web): remove useless get()

* feat(web): asset interaction store can now select many assets at once
This commit is contained in:
Ethan Margaillan 2024-03-21 13:14:13 +01:00 committed by GitHub
parent b588a87d4a
commit 4de0b2f44e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 66 additions and 35 deletions
web/src/lib/utils

View file

@ -1,4 +1,6 @@
import { notificationController, NotificationType } from '$lib/components/shared-components/notification/notification';
import type { AssetInteractionStore } from '$lib/stores/asset-interaction.store';
import { BucketPosition, isSelectingAllAssets, type AssetStore } from '$lib/stores/assets.store';
import { downloadManager } from '$lib/stores/download';
import { downloadRequest, getKey } from '$lib/utils';
import {
@ -13,6 +15,7 @@ import {
type UserResponseDto,
} from '@immich/sdk';
import { DateTime } from 'luxon';
import { get } from 'svelte/store';
import { handleError } from './handle-error';
export const addAssetsToAlbum = async (albumId: string, assetIds: Array<string>): Promise<BulkIdResponseDto[]> =>
@ -224,6 +227,35 @@ export const getSelectedAssets = (assets: Set<AssetResponseDto>, user: UserRespo
return ids;
};
export const selectAllAssets = async (assetStore: AssetStore, assetInteractionStore: AssetInteractionStore) => {
if (get(isSelectingAllAssets)) {
// Selection is already ongoing
return;
}
isSelectingAllAssets.set(true);
try {
for (const bucket of assetStore.buckets) {
await assetStore.loadBucket(bucket.bucketDate, BucketPosition.Unknown);
if (!get(isSelectingAllAssets)) {
break; // Cancelled
}
assetInteractionStore.selectAssets(bucket.assets);
// We use setTimeout to allow the UI to update. Otherwise, this may
// cause a long delay between the start of 'select all' and the
// effective update of the UI, depending on the number of assets
// to select
await delay(0);
}
} catch (error) {
handleError(error, 'Error selecting all assets');
} finally {
isSelectingAllAssets.set(false);
}
};
export const delay = async (ms: number) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};