mirror of
https://github.com/immich-app/immich.git
synced 2025-07-03 21:40:00 +02:00
feat(web): add ctrl+a / ctrl+d shortcuts to select / deselect all assets (#8105)
* 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:
parent
b588a87d4a
commit
4de0b2f44e
6 changed files with 66 additions and 35 deletions
web/src/lib/utils
|
@ -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));
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue