Files
immich/web/src/lib/components/photos-page/actions/select-all-assets.svelte
2023-10-25 13:48:25 +00:00

39 lines
1.2 KiB
Svelte

<script lang="ts">
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
import type { AssetInteractionStore } from '$lib/stores/asset-interaction.store';
import { BucketPosition, type AssetStore } from '$lib/stores/assets.store';
import { handleError } from '$lib/utils/handle-error';
import { get } from 'svelte/store';
import { mdiTimerSand, mdiSelectAll } from '@mdi/js';
export let assetStore: AssetStore;
export let assetInteractionStore: AssetInteractionStore;
let selecting = false;
const handleSelectAll = async () => {
try {
selecting = true;
const assetGridState = get(assetStore);
for (const bucket of assetGridState.buckets) {
await assetStore.loadBucket(bucket.bucketDate, BucketPosition.Unknown);
for (const asset of bucket.assets) {
assetInteractionStore.selectAsset(asset);
}
}
selecting = false;
} catch (e) {
handleError(e, 'Error selecting all assets');
}
};
</script>
{#if selecting}
<CircleIconButton title="Delete" icon={mdiTimerSand} />
{/if}
{#if !selecting}
<CircleIconButton title="Select all" icon={mdiSelectAll} on:click={handleSelectAll} />
{/if}