2023-06-10 21:06:13 +02:00
|
|
|
<script lang="ts">
|
2023-07-01 00:50:47 -04:00
|
|
|
import CircleIconButton from '$lib/components/elements/buttons/circle-icon-button.svelte';
|
2023-08-03 11:44:12 -04:00
|
|
|
import type { AssetInteractionStore } from '$lib/stores/asset-interaction.store';
|
2024-01-01 17:18:22 +01:00
|
|
|
import { BucketPosition, type AssetStore, isSelectAllCancelled } from '$lib/stores/assets.store';
|
2023-08-03 11:44:12 -04:00
|
|
|
import { handleError } from '$lib/utils/handle-error';
|
|
|
|
|
import { get } from 'svelte/store';
|
2023-10-25 09:48:25 -04:00
|
|
|
import { mdiTimerSand, mdiSelectAll } from '@mdi/js';
|
2023-08-01 04:27:56 +03:00
|
|
|
|
|
|
|
|
export let assetStore: AssetStore;
|
|
|
|
|
export let assetInteractionStore: AssetInteractionStore;
|
2023-06-10 21:06:13 +02:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
let selecting = false;
|
2023-06-10 21:06:13 +02:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const handleSelectAll = async () => {
|
|
|
|
|
try {
|
2024-01-01 17:18:22 +01:00
|
|
|
$isSelectAllCancelled = false;
|
2023-07-01 00:50:47 -04:00
|
|
|
selecting = true;
|
2023-06-10 21:06:13 +02:00
|
|
|
|
2023-08-01 04:27:56 +03:00
|
|
|
const assetGridState = get(assetStore);
|
|
|
|
|
for (const bucket of assetGridState.buckets) {
|
2024-01-01 17:18:22 +01:00
|
|
|
if ($isSelectAllCancelled) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-03-05 16:43:24 +01:00
|
|
|
await assetStore.loadBucket(bucket.bucketDate, BucketPosition.Unknown);
|
2023-08-01 04:27:56 +03:00
|
|
|
for (const asset of bucket.assets) {
|
2023-08-11 12:00:51 -04:00
|
|
|
assetInteractionStore.selectAsset(asset);
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
|
|
|
|
}
|
2023-08-01 04:27:56 +03:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
selecting = false;
|
2024-02-02 04:18:00 +01:00
|
|
|
} catch (error) {
|
|
|
|
|
handleError(error, 'Error selecting all assets');
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
|
|
|
|
};
|
2023-06-10 21:06:13 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
{#if selecting}
|
2023-10-25 09:48:25 -04:00
|
|
|
<CircleIconButton title="Delete" icon={mdiTimerSand} />
|
2023-06-10 21:06:13 +02:00
|
|
|
{/if}
|
|
|
|
|
{#if !selecting}
|
2023-10-25 09:48:25 -04:00
|
|
|
<CircleIconButton title="Select all" icon={mdiSelectAll} on:click={handleSelectAll} />
|
2023-06-10 21:06:13 +02:00
|
|
|
{/if}
|