mirror of
https://github.com/KevinMidboe/immich.git
synced 2026-01-18 15:16:24 +00:00
feat(web): select a range of assets (#3086)
The shift key can be held to select a range of assets. Fixes: #2862
This commit is contained in:
@@ -12,6 +12,7 @@ export const assetsInAlbumStoreState = writable<AssetResponseDto[]>([]);
|
||||
export const selectedAssets = writable<Set<AssetResponseDto>>(new Set());
|
||||
export const selectedGroup = writable<Set<string>>(new Set());
|
||||
export const isMultiSelectStoreState = derived(selectedAssets, ($selectedAssets) => $selectedAssets.size > 0);
|
||||
export const assetSelectionCandidates = writable<Set<AssetResponseDto>>(new Set());
|
||||
|
||||
function createAssetInteractionStore() {
|
||||
let _assetGridState = new AssetGridState();
|
||||
@@ -19,6 +20,7 @@ function createAssetInteractionStore() {
|
||||
let _selectedAssets: Set<AssetResponseDto>;
|
||||
let _selectedGroup: Set<string>;
|
||||
let _assetsInAlbums: AssetResponseDto[];
|
||||
let _assetSelectionCandidates: Set<AssetResponseDto>;
|
||||
|
||||
// Subscriber
|
||||
assetGridState.subscribe((state) => {
|
||||
@@ -41,6 +43,10 @@ function createAssetInteractionStore() {
|
||||
_assetsInAlbums = assets;
|
||||
});
|
||||
|
||||
assetSelectionCandidates.subscribe((assets) => {
|
||||
_assetSelectionCandidates = assets;
|
||||
});
|
||||
|
||||
// Methods
|
||||
|
||||
/**
|
||||
@@ -117,14 +123,26 @@ function createAssetInteractionStore() {
|
||||
selectedGroup.set(_selectedGroup);
|
||||
};
|
||||
|
||||
const setAssetSelectionCandidates = (assets: AssetResponseDto[]) => {
|
||||
_assetSelectionCandidates = new Set(assets);
|
||||
assetSelectionCandidates.set(_assetSelectionCandidates);
|
||||
};
|
||||
|
||||
const clearAssetSelectionCandidates = () => {
|
||||
_assetSelectionCandidates.clear();
|
||||
assetSelectionCandidates.set(_assetSelectionCandidates);
|
||||
};
|
||||
|
||||
const clearMultiselect = () => {
|
||||
_selectedAssets.clear();
|
||||
_selectedGroup.clear();
|
||||
_assetSelectionCandidates.clear();
|
||||
_assetsInAlbums = [];
|
||||
|
||||
selectedAssets.set(_selectedAssets);
|
||||
selectedGroup.set(_selectedGroup);
|
||||
assetsInAlbumStoreState.set(_assetsInAlbums);
|
||||
assetSelectionCandidates.set(_assetSelectionCandidates);
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -136,6 +154,8 @@ function createAssetInteractionStore() {
|
||||
removeAssetFromMultiselectGroup,
|
||||
addGroupToMultiselectGroup,
|
||||
removeGroupFromMultiselectGroup,
|
||||
setAssetSelectionCandidates,
|
||||
clearAssetSelectionCandidates,
|
||||
clearMultiselect,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { AssetGridState, BucketPosition } from '$lib/models/asset-grid-state';
|
||||
import { api, AssetCountByTimeBucketResponseDto } from '@api';
|
||||
import { flatMap, sumBy } from 'lodash-es';
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
/**
|
||||
@@ -60,7 +59,7 @@ function createAssetStore() {
|
||||
|
||||
// Update timeline height based on calculated bucket height
|
||||
assetGridState.update((state) => {
|
||||
state.timelineHeight = sumBy(state.buckets, (d) => d.bucketHeight);
|
||||
state.timelineHeight = state.buckets.reduce((acc, b) => acc + b.bucketHeight, 0);
|
||||
return state;
|
||||
});
|
||||
};
|
||||
@@ -101,7 +100,7 @@ function createAssetStore() {
|
||||
const bucketIndex = state.buckets.findIndex((b) => b.bucketDate === bucket);
|
||||
state.buckets[bucketIndex].assets = assets;
|
||||
state.buckets[bucketIndex].position = position;
|
||||
state.assets = flatMap(state.buckets, (b) => b.assets);
|
||||
state.assets = state.buckets.flatMap((b) => b.assets);
|
||||
return state;
|
||||
});
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
@@ -123,7 +122,7 @@ function createAssetStore() {
|
||||
if (state.buckets[bucketIndex].assets.length === 0) {
|
||||
_removeBucket(state.buckets[bucketIndex].bucketDate);
|
||||
}
|
||||
state.assets = flatMap(state.buckets, (b) => b.assets);
|
||||
state.assets = state.buckets.flatMap((b) => b.assets);
|
||||
return state;
|
||||
});
|
||||
};
|
||||
@@ -132,7 +131,7 @@ function createAssetStore() {
|
||||
assetGridState.update((state) => {
|
||||
const bucketIndex = state.buckets.findIndex((b) => b.bucketDate === bucketDate);
|
||||
state.buckets.splice(bucketIndex, 1);
|
||||
state.assets = flatMap(state.buckets, (b) => b.assets);
|
||||
state.assets = state.buckets.flatMap((b) => b.assets);
|
||||
return state;
|
||||
});
|
||||
};
|
||||
@@ -180,7 +179,7 @@ function createAssetStore() {
|
||||
const assetIndex = state.buckets[bucketIndex].assets.findIndex((a) => a.id === assetId);
|
||||
state.buckets[bucketIndex].assets[assetIndex].isFavorite = isFavorite;
|
||||
|
||||
state.assets = flatMap(state.buckets, (b) => b.assets);
|
||||
state.assets = state.buckets.flatMap((b) => b.assets);
|
||||
return state;
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user