2022-09-04 08:34:39 -05:00
|
|
|
<script lang="ts">
|
2023-07-01 00:50:47 -04:00
|
|
|
import { locale } from '$lib/stores/preferences.store';
|
2023-07-12 05:12:19 +03:00
|
|
|
import { getAssetRatio } from '$lib/utils/asset-utils';
|
2023-10-06 08:12:09 -04:00
|
|
|
import { formatGroupTitle, fromLocalDateTime, splitBucketIntoDateGroups } from '$lib/utils/timeline-util';
|
2023-07-01 00:50:47 -04:00
|
|
|
import type { AssetResponseDto } from '@api';
|
|
|
|
|
import justifiedLayout from 'justified-layout';
|
2023-07-03 10:56:58 +01:00
|
|
|
import { createEventDispatcher } from 'svelte';
|
2023-10-25 09:48:25 -04:00
|
|
|
import Icon from '$lib/components/elements/icon.svelte';
|
2023-07-01 00:50:47 -04:00
|
|
|
import { fly } from 'svelte/transition';
|
|
|
|
|
import Thumbnail from '../assets/thumbnail/thumbnail.svelte';
|
2023-08-01 04:27:56 +03:00
|
|
|
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
|
|
|
|
|
import type { AssetStore } from '$lib/stores/assets.store';
|
|
|
|
|
import type { AssetInteractionStore } from '$lib/stores/asset-interaction.store';
|
2023-08-03 11:44:12 -04:00
|
|
|
import type { Viewport } from '$lib/stores/assets.store';
|
2023-10-25 09:48:25 -04:00
|
|
|
import { mdiCheckCircle, mdiCircleOutline } from '@mdi/js';
|
2023-07-01 00:50:47 -04:00
|
|
|
|
|
|
|
|
export let assets: AssetResponseDto[];
|
|
|
|
|
export let bucketDate: string;
|
|
|
|
|
export let bucketHeight: number;
|
2023-08-05 09:58:52 -04:00
|
|
|
export let isSelectionMode = false;
|
2023-08-03 11:44:12 -04:00
|
|
|
export let viewport: Viewport;
|
2023-08-05 09:58:52 -04:00
|
|
|
export let singleSelect = false;
|
2023-10-27 15:34:01 -05:00
|
|
|
export let withStacked = false;
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2023-08-01 04:27:56 +03:00
|
|
|
export let assetStore: AssetStore;
|
|
|
|
|
export let assetInteractionStore: AssetInteractionStore;
|
|
|
|
|
|
2023-08-11 12:00:51 -04:00
|
|
|
const { selectedGroup, selectedAssets, assetSelectionCandidates, isMultiSelectState } = assetInteractionStore;
|
|
|
|
|
const dispatch = createEventDispatcher<{
|
|
|
|
|
select: { title: string; assets: AssetResponseDto[] };
|
|
|
|
|
selectAssets: AssetResponseDto;
|
|
|
|
|
selectAssetCandidates: AssetResponseDto | null;
|
|
|
|
|
shift: { heightDelta: number };
|
|
|
|
|
}>();
|
2023-07-01 00:50:47 -04:00
|
|
|
|
|
|
|
|
let isMouseOverGroup = false;
|
|
|
|
|
let actualBucketHeight: number;
|
|
|
|
|
let hoveredDateGroup = '';
|
|
|
|
|
|
|
|
|
|
interface LayoutBox {
|
|
|
|
|
top: number;
|
|
|
|
|
left: number;
|
|
|
|
|
width: number;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 05:12:19 +03:00
|
|
|
$: assetsGroupByDate = splitBucketIntoDateGroups(assets, $locale);
|
2023-07-01 00:50:47 -04:00
|
|
|
|
|
|
|
|
$: geometry = (() => {
|
|
|
|
|
const geometry = [];
|
|
|
|
|
for (let group of assetsGroupByDate) {
|
|
|
|
|
const justifiedLayoutResult = justifiedLayout(group.map(getAssetRatio), {
|
|
|
|
|
boxSpacing: 2,
|
2023-08-03 11:44:12 -04:00
|
|
|
containerWidth: Math.floor(viewport.width),
|
2023-07-01 00:50:47 -04:00
|
|
|
containerPadding: 0,
|
|
|
|
|
targetRowHeightTolerance: 0.15,
|
|
|
|
|
targetRowHeight: 235,
|
|
|
|
|
});
|
|
|
|
|
geometry.push({
|
|
|
|
|
...justifiedLayoutResult,
|
|
|
|
|
containerWidth: calculateWidth(justifiedLayoutResult.boxes),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return geometry;
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
$: {
|
2023-08-03 11:44:12 -04:00
|
|
|
if (actualBucketHeight && actualBucketHeight !== 0 && actualBucketHeight != bucketHeight) {
|
2023-08-02 21:57:11 -04:00
|
|
|
const heightDelta = assetStore.updateBucket(bucketDate, actualBucketHeight);
|
2023-07-01 00:50:47 -04:00
|
|
|
if (heightDelta !== 0) {
|
|
|
|
|
scrollTimeline(heightDelta);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function scrollTimeline(heightDelta: number) {
|
|
|
|
|
dispatch('shift', {
|
|
|
|
|
heightDelta,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const calculateWidth = (boxes: LayoutBox[]): number => {
|
|
|
|
|
let width = 0;
|
|
|
|
|
for (const box of boxes) {
|
|
|
|
|
if (box.top < 100) {
|
|
|
|
|
width = box.left + box.width;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return width;
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-11 12:00:51 -04:00
|
|
|
const assetClickHandler = (asset: AssetResponseDto, assetsInDateGroup: AssetResponseDto[], groupTitle: string) => {
|
2023-08-05 09:58:52 -04:00
|
|
|
if (isSelectionMode || $isMultiSelectState) {
|
2023-08-11 12:00:51 -04:00
|
|
|
assetSelectHandler(asset, assetsInDateGroup, groupTitle);
|
2023-07-01 00:50:47 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-25 00:03:28 -04:00
|
|
|
assetViewingStore.setAssetId(asset.id);
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
|
|
|
|
|
2023-08-11 12:00:51 -04:00
|
|
|
const handleSelectGroup = (title: string, assets: AssetResponseDto[]) => dispatch('select', { title, assets });
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2023-08-11 12:00:51 -04:00
|
|
|
const assetSelectHandler = (asset: AssetResponseDto, assetsInDateGroup: AssetResponseDto[], groupTitle: string) => {
|
|
|
|
|
dispatch('selectAssets', asset);
|
2023-07-01 00:50:47 -04:00
|
|
|
|
|
|
|
|
// Check if all assets are selected in a group to toggle the group selection's icon
|
2023-07-03 10:56:58 +01:00
|
|
|
let selectedAssetsInGroupCount = assetsInDateGroup.filter((asset) => $selectedAssets.has(asset)).length;
|
2023-07-01 00:50:47 -04:00
|
|
|
|
|
|
|
|
// if all assets are selected in a group, add the group to selected group
|
|
|
|
|
if (selectedAssetsInGroupCount == assetsInDateGroup.length) {
|
2023-08-11 12:00:51 -04:00
|
|
|
assetInteractionStore.addGroupToMultiselectGroup(groupTitle);
|
2023-07-01 00:50:47 -04:00
|
|
|
} else {
|
2023-08-11 12:00:51 -04:00
|
|
|
assetInteractionStore.removeGroupFromMultiselectGroup(groupTitle);
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-11 12:00:51 -04:00
|
|
|
const assetMouseEventHandler = (groupTitle: string, asset: AssetResponseDto | null) => {
|
2023-07-01 00:50:47 -04:00
|
|
|
// Show multi select icon on hover on date group
|
2023-08-11 12:00:51 -04:00
|
|
|
hoveredDateGroup = groupTitle;
|
2023-07-03 10:56:58 +01:00
|
|
|
|
2023-08-01 04:27:56 +03:00
|
|
|
if ($isMultiSelectState) {
|
2023-08-11 12:00:51 -04:00
|
|
|
dispatch('selectAssetCandidates', asset);
|
2023-07-03 10:56:58 +01:00
|
|
|
}
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
2022-09-04 08:34:39 -05:00
|
|
|
</script>
|
|
|
|
|
|
2023-08-03 11:44:12 -04:00
|
|
|
<section id="asset-group-by-date" class="flex flex-wrap gap-x-12" bind:clientHeight={actualBucketHeight}>
|
2023-08-11 12:00:51 -04:00
|
|
|
{#each assetsGroupByDate as groupAssets, groupIndex (groupAssets[0].id)}
|
2023-10-04 18:11:11 -04:00
|
|
|
{@const asset = groupAssets[0]}
|
2023-10-06 08:12:09 -04:00
|
|
|
{@const groupTitle = formatGroupTitle(fromLocalDateTime(asset.localDateTime).startOf('day'))}
|
2023-07-01 00:50:47 -04:00
|
|
|
<!-- Asset Group By Date -->
|
|
|
|
|
|
2023-07-15 20:13:04 -05:00
|
|
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
2023-07-01 00:50:47 -04:00
|
|
|
<div
|
2023-07-18 13:19:39 -05:00
|
|
|
class="mt-5 flex flex-col"
|
2023-07-01 00:50:47 -04:00
|
|
|
on:mouseenter={() => {
|
|
|
|
|
isMouseOverGroup = true;
|
2023-08-11 12:00:51 -04:00
|
|
|
assetMouseEventHandler(groupTitle, null);
|
2023-07-03 10:56:58 +01:00
|
|
|
}}
|
|
|
|
|
on:mouseleave={() => {
|
|
|
|
|
isMouseOverGroup = false;
|
2023-08-11 12:00:51 -04:00
|
|
|
assetMouseEventHandler(groupTitle, null);
|
2023-07-01 00:50:47 -04:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<!-- Date group title -->
|
|
|
|
|
<p
|
2023-07-18 13:19:39 -05:00
|
|
|
class="mb-2 flex h-6 place-items-center text-xs font-medium text-immich-fg dark:text-immich-dark-fg md:text-sm"
|
2023-07-01 00:50:47 -04:00
|
|
|
style="width: {geometry[groupIndex].containerWidth}px"
|
|
|
|
|
>
|
2023-08-11 12:00:51 -04:00
|
|
|
{#if !singleSelect && ((hoveredDateGroup == groupTitle && isMouseOverGroup) || $selectedGroup.has(groupTitle))}
|
2023-07-01 00:50:47 -04:00
|
|
|
<div
|
|
|
|
|
transition:fly={{ x: -24, duration: 200, opacity: 0.5 }}
|
|
|
|
|
class="inline-block px-2 hover:cursor-pointer"
|
2023-08-11 12:00:51 -04:00
|
|
|
on:click={() => handleSelectGroup(groupTitle, groupAssets)}
|
|
|
|
|
on:keydown={() => handleSelectGroup(groupTitle, groupAssets)}
|
2023-07-01 00:50:47 -04:00
|
|
|
>
|
2023-08-11 12:00:51 -04:00
|
|
|
{#if $selectedGroup.has(groupTitle)}
|
2023-10-25 09:48:25 -04:00
|
|
|
<Icon path={mdiCheckCircle} size="24" color="#4250af" />
|
2023-07-01 00:50:47 -04:00
|
|
|
{:else}
|
2023-10-25 09:48:25 -04:00
|
|
|
<Icon path={mdiCircleOutline} size="24" color="#757575" />
|
2023-07-01 00:50:47 -04:00
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
|
2023-08-11 12:00:51 -04:00
|
|
|
<span class="truncate first-letter:capitalize" title={groupTitle}>
|
|
|
|
|
{groupTitle}
|
2023-07-01 00:50:47 -04:00
|
|
|
</span>
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<!-- Image grid -->
|
|
|
|
|
<div
|
|
|
|
|
class="relative"
|
|
|
|
|
style="height: {geometry[groupIndex].containerHeight}px;width: {geometry[groupIndex].containerWidth}px"
|
|
|
|
|
>
|
2023-08-11 12:00:51 -04:00
|
|
|
{#each groupAssets as asset, index (asset.id)}
|
2023-07-01 00:50:47 -04:00
|
|
|
{@const box = geometry[groupIndex].boxes[index]}
|
|
|
|
|
<div
|
|
|
|
|
class="absolute"
|
|
|
|
|
style="width: {box.width}px; height: {box.height}px; top: {box.top}px; left: {box.left}px"
|
|
|
|
|
>
|
|
|
|
|
<Thumbnail
|
2023-10-27 15:34:01 -05:00
|
|
|
showStackedIcon={withStacked}
|
2023-07-01 00:50:47 -04:00
|
|
|
{asset}
|
|
|
|
|
{groupIndex}
|
2023-08-11 12:00:51 -04:00
|
|
|
on:click={() => assetClickHandler(asset, groupAssets, groupTitle)}
|
|
|
|
|
on:select={() => assetSelectHandler(asset, groupAssets, groupTitle)}
|
|
|
|
|
on:mouse-event={() => assetMouseEventHandler(groupTitle, asset)}
|
|
|
|
|
selected={$selectedAssets.has(asset) || $assetStore.albumAssets.has(asset.id)}
|
2023-07-03 10:56:58 +01:00
|
|
|
selectionCandidate={$assetSelectionCandidates.has(asset)}
|
2023-08-11 12:00:51 -04:00
|
|
|
disabled={$assetStore.albumAssets.has(asset.id)}
|
2023-07-01 00:50:47 -04:00
|
|
|
thumbnailWidth={box.width}
|
|
|
|
|
thumbnailHeight={box.height}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{/each}
|
2022-09-04 08:34:39 -05:00
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<style>
|
2023-07-01 00:50:47 -04:00
|
|
|
#asset-group-by-date {
|
|
|
|
|
contain: layout;
|
|
|
|
|
}
|
2022-09-04 08:34:39 -05:00
|
|
|
</style>
|