2022-09-04 08:34:39 -05:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { assetStore } from '$lib/stores/assets.store';
|
|
|
|
|
import CheckCircle from 'svelte-material-icons/CheckCircle.svelte';
|
|
|
|
|
import CircleOutline from 'svelte-material-icons/CircleOutline.svelte';
|
|
|
|
|
import { fly } from 'svelte/transition';
|
|
|
|
|
import { AssetResponseDto } from '@api';
|
2023-02-13 15:56:43 -06:00
|
|
|
import lodash from 'lodash-es';
|
2022-09-04 08:34:39 -05:00
|
|
|
import ImmichThumbnail from '../shared-components/immich-thumbnail.svelte';
|
|
|
|
|
import {
|
|
|
|
|
assetInteractionStore,
|
|
|
|
|
assetsInAlbumStoreState,
|
|
|
|
|
isMultiSelectStoreState,
|
|
|
|
|
selectedAssets,
|
|
|
|
|
selectedGroup
|
|
|
|
|
} from '$lib/stores/asset-interaction.store';
|
|
|
|
|
export let assets: AssetResponseDto[];
|
|
|
|
|
export let bucketDate: string;
|
|
|
|
|
export let bucketHeight: number;
|
2022-09-05 00:18:53 -05:00
|
|
|
export let isAlbumSelectionMode = false;
|
2022-09-04 08:34:39 -05:00
|
|
|
|
2022-12-04 22:51:22 -06:00
|
|
|
const locale = navigator.language;
|
2022-12-05 04:35:20 +13:00
|
|
|
const groupDateFormat: Intl.DateTimeFormatOptions = {
|
|
|
|
|
weekday: 'short',
|
|
|
|
|
month: 'short',
|
|
|
|
|
day: 'numeric',
|
|
|
|
|
year: 'numeric'
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-04 08:34:39 -05:00
|
|
|
let isMouseOverGroup = false;
|
|
|
|
|
let actualBucketHeight: number;
|
2022-09-08 17:30:49 +02:00
|
|
|
let hoveredDateGroup = '';
|
2023-02-13 15:56:43 -06:00
|
|
|
$: assetsGroupByDate = lodash
|
|
|
|
|
.chain(assets)
|
2022-12-05 04:35:20 +13:00
|
|
|
.groupBy((a) => new Date(a.createdAt).toLocaleDateString(locale, groupDateFormat))
|
2022-09-04 08:34:39 -05:00
|
|
|
.sortBy((group) => assets.indexOf(group[0]))
|
|
|
|
|
.value();
|
|
|
|
|
|
|
|
|
|
$: {
|
|
|
|
|
if (actualBucketHeight && actualBucketHeight != 0 && actualBucketHeight != bucketHeight) {
|
|
|
|
|
assetStore.updateBucketHeight(bucketDate, actualBucketHeight);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const assetClickHandler = (
|
|
|
|
|
asset: AssetResponseDto,
|
|
|
|
|
assetsInDateGroup: AssetResponseDto[],
|
|
|
|
|
dateGroupTitle: string
|
|
|
|
|
) => {
|
2022-09-05 00:18:53 -05:00
|
|
|
if (isAlbumSelectionMode) {
|
|
|
|
|
assetSelectHandler(asset, assetsInDateGroup, dateGroupTitle);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-04 08:34:39 -05:00
|
|
|
if ($isMultiSelectStoreState) {
|
|
|
|
|
assetSelectHandler(asset, assetsInDateGroup, dateGroupTitle);
|
|
|
|
|
} else {
|
|
|
|
|
assetInteractionStore.setViewingAsset(asset);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const selectAssetGroupHandler = (
|
|
|
|
|
selectAssetGroupHandler: AssetResponseDto[],
|
|
|
|
|
dateGroupTitle: string
|
|
|
|
|
) => {
|
|
|
|
|
if ($selectedGroup.has(dateGroupTitle)) {
|
|
|
|
|
assetInteractionStore.removeGroupFromMultiselectGroup(dateGroupTitle);
|
|
|
|
|
selectAssetGroupHandler.forEach((asset) => {
|
|
|
|
|
assetInteractionStore.removeAssetFromMultiselectGroup(asset);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
assetInteractionStore.addGroupToMultiselectGroup(dateGroupTitle);
|
|
|
|
|
selectAssetGroupHandler.forEach((asset) => {
|
|
|
|
|
assetInteractionStore.addAssetToMultiselectGroup(asset);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const assetSelectHandler = (
|
|
|
|
|
asset: AssetResponseDto,
|
|
|
|
|
assetsInDateGroup: AssetResponseDto[],
|
|
|
|
|
dateGroupTitle: string
|
|
|
|
|
) => {
|
|
|
|
|
if ($selectedAssets.has(asset)) {
|
|
|
|
|
assetInteractionStore.removeAssetFromMultiselectGroup(asset);
|
|
|
|
|
} else {
|
|
|
|
|
assetInteractionStore.addAssetToMultiselectGroup(asset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if all assets are selected in a group to toggle the group selection's icon
|
|
|
|
|
let selectedAssetsInGroupCount = 0;
|
|
|
|
|
assetsInDateGroup.forEach((asset) => {
|
|
|
|
|
if ($selectedAssets.has(asset)) {
|
|
|
|
|
selectedAssetsInGroupCount++;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// if all assets are selected in a group, add the group to selected group
|
|
|
|
|
if (selectedAssetsInGroupCount == assetsInDateGroup.length) {
|
|
|
|
|
assetInteractionStore.addGroupToMultiselectGroup(dateGroupTitle);
|
|
|
|
|
} else {
|
|
|
|
|
assetInteractionStore.removeGroupFromMultiselectGroup(dateGroupTitle);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const assetMouseEventHandler = (dateGroupTitle: string) => {
|
|
|
|
|
// Show multi select icon on hover on date group
|
|
|
|
|
hoveredDateGroup = dateGroupTitle;
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<section
|
|
|
|
|
id="asset-group-by-date"
|
|
|
|
|
class="flex flex-wrap gap-5 mt-5"
|
|
|
|
|
bind:clientHeight={actualBucketHeight}
|
|
|
|
|
>
|
|
|
|
|
{#each assetsGroupByDate as assetsInDateGroup, groupIndex (assetsInDateGroup[0].id)}
|
2022-12-04 22:51:22 -06:00
|
|
|
{@const dateGroupTitle = new Date(assetsInDateGroup[0].createdAt).toLocaleDateString(
|
|
|
|
|
locale,
|
|
|
|
|
groupDateFormat
|
|
|
|
|
)}
|
2022-09-04 08:34:39 -05:00
|
|
|
<!-- Asset Group By Date -->
|
2022-10-29 10:17:53 -05:00
|
|
|
|
2022-09-04 08:34:39 -05:00
|
|
|
<div
|
|
|
|
|
class="flex flex-col"
|
2022-10-29 10:17:53 -05:00
|
|
|
on:mouseenter={() => {
|
|
|
|
|
isMouseOverGroup = true;
|
|
|
|
|
assetMouseEventHandler(dateGroupTitle);
|
|
|
|
|
}}
|
2022-09-04 08:34:39 -05:00
|
|
|
on:mouseleave={() => (isMouseOverGroup = false)}
|
|
|
|
|
>
|
|
|
|
|
<!-- Date group title -->
|
2022-10-26 11:10:48 -05:00
|
|
|
<p
|
|
|
|
|
class="font-medium text-sm text-immich-fg dark:text-immich-dark-fg mb-2 flex place-items-center h-6"
|
|
|
|
|
>
|
2022-09-04 08:34:39 -05:00
|
|
|
{#if (hoveredDateGroup == dateGroupTitle && isMouseOverGroup) || $selectedGroup.has(dateGroupTitle)}
|
|
|
|
|
<div
|
|
|
|
|
transition:fly={{ x: -24, duration: 200, opacity: 0.5 }}
|
|
|
|
|
class="inline-block px-2 hover:cursor-pointer"
|
|
|
|
|
on:click={() => selectAssetGroupHandler(assetsInDateGroup, dateGroupTitle)}
|
2022-12-06 18:08:08 -06:00
|
|
|
on:keydown={() => selectAssetGroupHandler(assetsInDateGroup, dateGroupTitle)}
|
2022-09-04 08:34:39 -05:00
|
|
|
>
|
|
|
|
|
{#if $selectedGroup.has(dateGroupTitle)}
|
|
|
|
|
<CheckCircle size="24" color="#4250af" />
|
|
|
|
|
{:else}
|
|
|
|
|
<CircleOutline size="24" color="#757575" />
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
<span>
|
|
|
|
|
{dateGroupTitle}
|
|
|
|
|
</span>
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<!-- Image grid -->
|
|
|
|
|
<div class="flex flex-wrap gap-[2px]">
|
|
|
|
|
{#each assetsInDateGroup as asset (asset.id)}
|
|
|
|
|
<ImmichThumbnail
|
|
|
|
|
{asset}
|
|
|
|
|
{groupIndex}
|
|
|
|
|
on:click={() => assetClickHandler(asset, assetsInDateGroup, dateGroupTitle)}
|
|
|
|
|
on:select={() => assetSelectHandler(asset, assetsInDateGroup, dateGroupTitle)}
|
|
|
|
|
on:mouse-event={() => assetMouseEventHandler(dateGroupTitle)}
|
|
|
|
|
selected={$selectedAssets.has(asset)}
|
|
|
|
|
disabled={$assetsInAlbumStoreState.findIndex((a) => a.id == asset.id) != -1}
|
|
|
|
|
/>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{/each}
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
#asset-group-by-date {
|
|
|
|
|
contain: layout;
|
|
|
|
|
}
|
|
|
|
|
</style>
|