refactor(web): rename DayGroup/MonthGroup to TimelineDay/TimelineMonth

- Rename classes: DayGroup → TimelineDay, MonthGroup → TimelineMonth
- Use short variable names: dayGroup → day, monthGroup → month
- Update all method names and properties for consistency
- Convert relative imports to $lib alias convention

No functional changes.
This commit is contained in:
midzelis
2025-11-03 22:09:05 +00:00
parent d6ed52806f
commit 928b69f415
37 changed files with 517 additions and 537 deletions

View File

@@ -6,7 +6,7 @@
import SelectAllAssets from '$lib/components/timeline/actions/SelectAllAction.svelte';
import AssetSelectControlBar from '$lib/components/timeline/AssetSelectControlBar.svelte';
import Timeline from '$lib/components/timeline/Timeline.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
import { dragAndDropFilesStore } from '$lib/stores/drag-and-drop-files.store';

View File

@@ -1,5 +1,5 @@
<script lang="ts">
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import type { ScrubberMonth, ViewportTopMonth } from '$lib/managers/timeline-manager/types';
import { mobileDevice } from '$lib/stores/mobile-device.svelte';
import { getTabbable } from '$lib/utils/focus-util';
@@ -91,7 +91,7 @@
scrubberWidth = usingMobileDevice ? MOBILE_WIDTH : DESKTOP_WIDTH;
});
const toScrollFromMonthGroupPercentage = (
const toScrollFromMonthPercentage = (
scrubberMonth: ViewportTopMonth,
scrubberMonthPercent: number,
scrubOverallPercent: number,
@@ -124,7 +124,7 @@
}
};
const scrollY = $derived(
toScrollFromMonthGroupPercentage(viewportTopMonth, viewportTopMonthScrollPercent, timelineScrollPercent),
toScrollFromMonthPercentage(viewportTopMonth, viewportTopMonthScrollPercent, timelineScrollPercent),
);
const timelineFullHeight = $derived(timelineManager.scrubberTimelineHeight);
const relativeTopOffset = $derived(toScrollY(timelineTopOffset / timelineFullHeight));
@@ -280,12 +280,12 @@
const boundingClientRect = bestElement.boundingClientRect;
const sy = boundingClientRect.y;
const relativeY = y - sy;
const monthGroupPercentY = relativeY / boundingClientRect.height;
const monthPercentY = relativeY / boundingClientRect.height;
return {
isOnPaddingTop: false,
isOnPaddingBottom: false,
segment,
monthGroupPercentY,
monthPercentY,
};
}
@@ -308,7 +308,7 @@
isOnPaddingTop,
isOnPaddingBottom,
segment: undefined,
monthGroupPercentY: 0,
monthPercentY: 0,
};
};
@@ -327,7 +327,7 @@
const upper = rect?.height - (PADDING_TOP + PADDING_BOTTOM);
hoverY = clamp(clientY - rect?.top - PADDING_TOP, lower, upper);
const x = rect!.left + rect!.width / 2;
const { segment, monthGroupPercentY, isOnPaddingTop, isOnPaddingBottom } = getActive(x, clientY);
const { segment, monthPercentY, isOnPaddingTop, isOnPaddingBottom } = getActive(x, clientY);
activeSegment = segment;
isHoverOnPaddingTop = isOnPaddingTop;
isHoverOnPaddingBottom = isOnPaddingBottom;
@@ -335,7 +335,7 @@
const scrubData = {
scrubberMonth: segmentDate,
overallScrollPercent: toTimelineY(hoverY),
scrubberMonthScrollPercent: monthGroupPercentY,
scrubberMonthScrollPercent: monthPercentY,
};
if (wasDragging === false && isDragging) {
void startScrub?.(scrubData);

View File

@@ -2,17 +2,17 @@
import { afterNavigate, beforeNavigate } from '$app/navigation';
import { page } from '$app/state';
import { resizeObserver, type OnResizeCallback } from '$lib/actions/resize-observer';
import TimelineKeyboardActions from '$lib/components/timeline/actions/TimelineKeyboardActions.svelte';
import Scrubber from '$lib/components/timeline/Scrubber.svelte';
import TimelineAssetViewer from '$lib/components/timeline/TimelineAssetViewer.svelte';
import TimelineKeyboardActions from '$lib/components/timeline/actions/TimelineKeyboardActions.svelte';
import { AssetAction } from '$lib/constants';
import HotModuleReload from '$lib/elements/HotModuleReload.svelte';
import Portal from '$lib/elements/Portal.svelte';
import Skeleton from '$lib/elements/Skeleton.svelte';
import type { DayGroup } from '$lib/managers/timeline-manager/day-group.svelte';
import { isIntersecting } from '$lib/managers/timeline-manager/internal/intersection-support.svelte';
import type { MonthGroup } from '$lib/managers/timeline-manager/month-group.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineDay } from '$lib/managers/timeline-manager/TimelineDay.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import { TimelineMonth } from '$lib/managers/timeline-manager/TimelineMonth.svelte';
import type { TimelineAsset, TimelineManagerOptions, ViewportTopMonth } from '$lib/managers/timeline-manager/types';
import { assetsSnapshot } from '$lib/managers/timeline-manager/utils.svelte';
import type { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
@@ -58,11 +58,11 @@
onThumbnailClick?: (
asset: TimelineAsset,
timelineManager: TimelineManager,
dayGroup: DayGroup,
day: TimelineDay,
onClick: (
timelineManager: TimelineManager,
assets: TimelineAsset[],
groupTitle: string,
dayTitle: string,
asset: TimelineAsset,
) => void,
) => void;
@@ -130,10 +130,10 @@
timelineManager.scrollableElement = scrollableElement;
});
const getAssetPosition = (assetId: string, monthGroup: MonthGroup) => monthGroup.findAssetAbsolutePosition(assetId);
const getAssetPosition = (assetId: string, month: TimelineMonth) => month.findAssetAbsolutePosition(assetId);
const scrollToAssetPosition = (assetId: string, monthGroup: MonthGroup) => {
const position = getAssetPosition(assetId, monthGroup);
const scrollToAssetPosition = (assetId: string, month: TimelineMonth) => {
const position = getAssetPosition(assetId, month);
if (!position) {
return;
@@ -176,20 +176,20 @@
};
const scrollAndLoadAsset = async (assetId: string) => {
const monthGroup = await timelineManager.findMonthGroupForAsset(assetId);
if (!monthGroup) {
const month = await timelineManager.findMonthForAsset(assetId);
if (!month) {
return false;
}
scrollToAssetPosition(assetId, monthGroup);
scrollToAssetPosition(assetId, month);
return true;
};
const scrollToAsset = (asset: TimelineAsset) => {
const monthGroup = timelineManager.getMonthGroupByAssetId(asset.id);
if (!monthGroup) {
const month = timelineManager.getMonthByAssetId(asset.id);
if (!month) {
return false;
}
scrollToAssetPosition(asset.id, monthGroup);
scrollToAssetPosition(asset.id, month);
return true;
};
@@ -264,10 +264,10 @@
}
});
const scrollToSegmentPercentage = (segmentTop: number, segmentHeight: number, monthGroupScrollPercent: number) => {
const scrollToSegmentPercentage = (segmentTop: number, segmentHeight: number, monthScrollPercent: number) => {
const topOffset = segmentTop;
const maxScrollPercent = timelineManager.maxScrollPercent;
const delta = segmentHeight * monthGroupScrollPercent;
const delta = segmentHeight * monthScrollPercent;
const scrollToTop = (topOffset + delta) * maxScrollPercent;
timelineManager.scrollTo(scrollToTop);
@@ -296,13 +296,13 @@
scrubberMonthScrollPercent,
);
} else {
const monthGroup = timelineManager.months.find(
const month = timelineManager.months.find(
({ yearMonth: { year, month } }) => year === scrubberMonth.year && month === scrubberMonth.month,
);
if (!monthGroup) {
if (!month) {
return;
}
scrollToSegmentPercentage(monthGroup.top, monthGroup.height, scrubberMonthScrollPercent);
scrollToSegmentPercentage(month.top, month.height, scrubberMonthScrollPercent);
}
};
@@ -327,28 +327,28 @@
const monthsLength = timelineManager.months.length;
for (let i = -1; i < monthsLength + 1; i++) {
let monthGroup: ViewportTopMonth;
let monthGroupHeight = 0;
let month: ViewportTopMonth;
let monthHeight = 0;
if (i === -1) {
// lead-in
monthGroup = 'lead-in';
monthGroupHeight = timelineManager.topSectionHeight;
month = 'lead-in';
monthHeight = timelineManager.topSectionHeight;
} else if (i === monthsLength) {
// lead-out
monthGroup = 'lead-out';
monthGroupHeight = timelineManager.bottomSectionHeight;
month = 'lead-out';
monthHeight = timelineManager.bottomSectionHeight;
} else {
monthGroup = timelineManager.months[i].yearMonth;
monthGroupHeight = timelineManager.months[i].height;
month = timelineManager.months[i].yearMonth;
monthHeight = timelineManager.months[i].height;
}
let next = top - monthGroupHeight * maxScrollPercent;
let next = top - monthHeight * maxScrollPercent;
// instead of checking for < 0, add a little wiggle room for subpixel resolution
if (next < -1 && monthGroup) {
viewportTopMonth = monthGroup;
if (next < -1 && month) {
viewportTopMonth = month;
// allowing next to be at least 1 may cause percent to go negative, so ensure positive percentage
viewportTopMonthScrollPercent = Math.max(0, top / (monthGroupHeight * maxScrollPercent));
viewportTopMonthScrollPercent = Math.max(0, top / (monthHeight * maxScrollPercent));
// compensate for lost precision/rounding errors advance to the next bucket, if present
if (viewportTopMonthScrollPercent > 0.9999 && i + 1 < monthsLength - 1) {
@@ -442,8 +442,8 @@
assetInteraction.clearAssetSelectionCandidates();
if (assetInteraction.assetSelectionStart && rangeSelection) {
let startBucket = timelineManager.getMonthGroupByAssetId(assetInteraction.assetSelectionStart.id);
let endBucket = timelineManager.getMonthGroupByAssetId(asset.id);
let startBucket = timelineManager.getMonthByAssetId(assetInteraction.assetSelectionStart.id);
let endBucket = timelineManager.getMonthByAssetId(asset.id);
if (startBucket === null || endBucket === null) {
return;
@@ -451,13 +451,13 @@
// Select/deselect assets in range (start,end)
let started = false;
for (const monthGroup of timelineManager.months) {
if (monthGroup === endBucket) {
for (const month of timelineManager.months) {
if (month === endBucket) {
break;
}
if (started) {
await timelineManager.loadMonthGroup(monthGroup.yearMonth);
for (const asset of monthGroup.assetsIterator()) {
await timelineManager.loadMonth(month.yearMonth);
for (const asset of month.assetsIterator()) {
if (deselect) {
assetInteraction.removeAssetFromMultiselectGroup(asset.id);
} else {
@@ -465,29 +465,29 @@
}
}
}
if (monthGroup === startBucket) {
if (month === startBucket) {
started = true;
}
}
// Update date group selection in range [start,end]
started = false;
for (const monthGroup of timelineManager.months) {
if (monthGroup === startBucket) {
for (const month of timelineManager.months) {
if (month === startBucket) {
started = true;
}
if (started) {
// Split month group into day groups and check each group
for (const dayGroup of monthGroup.dayGroups) {
const dayGroupTitle = dayGroup.groupTitle;
if (dayGroup.getAssets().every((a) => assetInteraction.hasSelectedAsset(a.id))) {
assetInteraction.addGroupToMultiselectGroup(dayGroupTitle);
for (const day of month.days) {
const dayTitle = day.dayTitle;
if (day.getAssets().every((a) => assetInteraction.hasSelectedAsset(a.id))) {
assetInteraction.addGroupToMultiselectGroup(dayTitle);
} else {
assetInteraction.removeGroupFromMultiselectGroup(dayGroupTitle);
assetInteraction.removeGroupFromMultiselectGroup(dayTitle);
}
}
}
if (monthGroup === endBucket) {
if (month === endBucket) {
break;
}
}
@@ -531,7 +531,7 @@
$effect(() => {
if ($showAssetViewer) {
const { localDateTime } = getTimes($viewingAsset.fileCreatedAt, DateTime.local().offset / 60);
void timelineManager.loadMonthGroup({ year: localDateTime.year, month: localDateTime.month });
void timelineManager.loadMonth({ year: localDateTime.year, month: localDateTime.month });
}
});
</script>
@@ -622,23 +622,23 @@
{/if}
</section>
{#each timelineManager.months as monthGroup (monthGroup.viewId)}
{@const display = monthGroup.intersecting}
{@const absoluteHeight = monthGroup.top}
{#each timelineManager.months as month (month.viewId)}
{@const display = month.intersecting}
{@const absoluteHeight = month.top}
{#if !monthGroup.isLoaded}
{#if !month.isLoaded}
<div
style:height={monthGroup.height + 'px'}
style:height={month.height + 'px'}
style:position="absolute"
style:transform={`translate3d(0,${absoluteHeight}px,0)`}
style:width="100%"
>
<Skeleton {invisible} height={monthGroup.height} title={monthGroup.monthGroupTitle} />
<Skeleton {invisible} height={month.height} title={month.monthTitle} />
</div>
{:else if display}
<div
class="month-group"
style:height={monthGroup.height + 'px'}
style:height={month.height + 'px'}
style:position="absolute"
style:transform={`translate3d(0,${absoluteHeight}px,0)`}
style:width="100%"
@@ -650,7 +650,7 @@
{timelineManager}
{isSelectionMode}
{singleSelect}
{monthGroup}
{month}
onSelect={({ title, assets }) => handleGroupSelect(timelineManager, title, assets)}
onSelectAssetCandidates={handleSelectAssetCandidates}
onSelectAssets={handleSelectAssets}

View File

@@ -2,7 +2,7 @@
import type { Action } from '$lib/components/asset-viewer/actions/action';
import { AssetAction } from '$lib/constants';
import { authManager } from '$lib/managers/auth-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
import { updateStackedAssetInTimeline, updateUnstackedAssetInTimeline } from '$lib/utils/actions';
import { navigate } from '$lib/utils/navigation';

View File

@@ -1,19 +1,17 @@
<script lang="ts">
import Thumbnail from '$lib/components/assets/thumbnail/thumbnail.svelte';
import type { DayGroup } from '$lib/managers/timeline-manager/day-group.svelte';
import type { MonthGroup } from '$lib/managers/timeline-manager/month-group.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineDay } from '$lib/managers/timeline-manager/TimelineDay.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import { TimelineMonth } from '$lib/managers/timeline-manager/TimelineMonth.svelte';
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
import { assetSnapshot, assetsSnapshot } from '$lib/managers/timeline-manager/utils.svelte';
import type { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
import { isSelectingAllAssets } from '$lib/stores/assets-store.svelte';
import { uploadAssetsStore } from '$lib/stores/upload';
import { navigate } from '$lib/utils/navigation';
import { mdiCheckCircle, mdiCircleOutline } from '@mdi/js';
import { fromTimelinePlainDate, getDateLocaleString } from '$lib/utils/timeline-util';
import { Icon } from '@immich/ui';
import { mdiCheckCircle, mdiCircleOutline } from '@mdi/js';
import { type Snippet } from 'svelte';
import { flip } from 'svelte/animate';
import { scale } from 'svelte/transition';
@@ -25,7 +23,7 @@
singleSelect: boolean;
withStacked: boolean;
showArchiveIcon: boolean;
monthGroup: MonthGroup;
month: TimelineMonth;
timelineManager: TimelineManager;
assetInteraction: AssetInteraction;
customLayout?: Snippet<[TimelineAsset]>;
@@ -36,11 +34,11 @@
onThumbnailClick?: (
asset: TimelineAsset,
timelineManager: TimelineManager,
dayGroup: DayGroup,
day: TimelineDay,
onClick: (
timelineManager: TimelineManager,
assets: TimelineAsset[],
groupTitle: string,
dayTitle: string,
asset: TimelineAsset,
) => void,
) => void;
@@ -51,7 +49,7 @@
singleSelect,
withStacked,
showArchiveIcon,
monthGroup = $bindable(),
month = $bindable(),
assetInteraction,
timelineManager,
customLayout,
@@ -63,20 +61,18 @@
}: Props = $props();
let isMouseOverGroup = $state(false);
let hoveredDayGroup = $state();
let hoveredDay = $state();
const transitionDuration = $derived.by(() =>
monthGroup.timelineManager.suspendTransitions && !$isUploading ? 0 : 150,
);
const transitionDuration = $derived.by(() => (month.timelineManager.suspendTransitions && !$isUploading ? 0 : 150));
const scaleDuration = $derived(transitionDuration === 0 ? 0 : transitionDuration + 100);
const _onClick = (
timelineManager: TimelineManager,
assets: TimelineAsset[],
groupTitle: string,
dayTitle: string,
asset: TimelineAsset,
) => {
if (isSelectionMode || assetInteraction.selectionActive) {
assetSelectHandler(timelineManager, asset, assets, groupTitle);
assetSelectHandler(timelineManager, asset, assets, dayTitle);
return;
}
void navigate({ targetRoute: 'current', assetId: asset.id });
@@ -87,21 +83,19 @@
const assetSelectHandler = (
timelineManager: TimelineManager,
asset: TimelineAsset,
assetsInDayGroup: TimelineAsset[],
groupTitle: string,
assetsInDay: TimelineAsset[],
dayTitle: string,
) => {
onSelectAssets(asset);
// Check if all assets are selected in a group to toggle the group selection's icon
let selectedAssetsInGroupCount = assetsInDayGroup.filter((asset) =>
assetInteraction.hasSelectedAsset(asset.id),
).length;
let selectedAssetsInDayCount = assetsInDay.filter((asset) => assetInteraction.hasSelectedAsset(asset.id)).length;
// if all assets are selected in a group, add the group to selected group
if (selectedAssetsInGroupCount == assetsInDayGroup.length) {
assetInteraction.addGroupToMultiselectGroup(groupTitle);
if (selectedAssetsInDayCount == assetsInDay.length) {
assetInteraction.addGroupToMultiselectGroup(dayTitle);
} else {
assetInteraction.removeGroupFromMultiselectGroup(groupTitle);
assetInteraction.removeGroupFromMultiselectGroup(dayTitle);
}
if (timelineManager.assetCount == assetInteraction.selectedAssets.length) {
@@ -111,9 +105,9 @@
}
};
const assetMouseEventHandler = (groupTitle: string, asset: TimelineAsset | null) => {
const assetMouseEventHandler = (dayTitle: string, asset: TimelineAsset | null) => {
// Show multi select icon on hover on date group
hoveredDayGroup = groupTitle;
hoveredDay = dayTitle;
if (assetInteraction.selectionActive) {
onSelectAssetCandidates(asset);
@@ -124,52 +118,52 @@
return intersectable.filter((int) => int.intersecting);
}
const getDayGroupFullDate = (dayGroup: DayGroup): string => {
const { month, year } = dayGroup.monthGroup.yearMonth;
const getDayFullDate = (day: TimelineDay): string => {
const { month, year } = day.month.yearMonth;
const date = fromTimelinePlainDate({
year,
month,
day: dayGroup.day,
day: day.day,
});
return getDateLocaleString(date);
};
</script>
{#each filterIntersecting(monthGroup.dayGroups) as dayGroup, groupIndex (dayGroup.day)}
{@const absoluteWidth = dayGroup.left}
{#each filterIntersecting(month.days) as day, groupIndex (day.day)}
{@const absoluteWidth = day.left}
<!-- svelte-ignore a11y_no_static_element_interactions -->
<section
class={[
{ 'transition-all': !monthGroup.timelineManager.suspendTransitions },
!monthGroup.timelineManager.suspendTransitions && `delay-${transitionDuration}`,
{ 'transition-all': !month.timelineManager.suspendTransitions },
!month.timelineManager.suspendTransitions && `delay-${transitionDuration}`,
]}
data-group
style:position="absolute"
style:transform={`translate3d(${absoluteWidth}px,${dayGroup.top}px,0)`}
style:transform={`translate3d(${absoluteWidth}px,${day.top}px,0)`}
onmouseenter={() => {
isMouseOverGroup = true;
assetMouseEventHandler(dayGroup.groupTitle, null);
assetMouseEventHandler(day.dayTitle, null);
}}
onmouseleave={() => {
isMouseOverGroup = false;
assetMouseEventHandler(dayGroup.groupTitle, null);
assetMouseEventHandler(day.dayTitle, null);
}}
>
<!-- Date group title -->
<div
class="flex pt-7 pb-5 max-md:pt-5 max-md:pb-3 h-6 place-items-center text-xs font-medium text-immich-fg dark:text-immich-dark-fg md:text-sm"
style:width={dayGroup.width + 'px'}
style:width={day.width + 'px'}
>
{#if !singleSelect}
<div
class="hover:cursor-pointer transition-all duration-200 ease-out overflow-hidden w-0"
class:w-8={(hoveredDayGroup === dayGroup.groupTitle && isMouseOverGroup) ||
assetInteraction.selectedGroup.has(dayGroup.groupTitle)}
onclick={() => handleSelectGroup(dayGroup.groupTitle, assetsSnapshot(dayGroup.getAssets()))}
onkeydown={() => handleSelectGroup(dayGroup.groupTitle, assetsSnapshot(dayGroup.getAssets()))}
class:w-8={(hoveredDay === day.dayTitle && isMouseOverGroup) ||
assetInteraction.selectedGroup.has(day.dayTitle)}
onclick={() => handleSelectGroup(day.dayTitle, assetsSnapshot(day.getAssets()))}
onkeydown={() => handleSelectGroup(day.dayTitle, assetsSnapshot(day.getAssets()))}
>
{#if assetInteraction.selectedGroup.has(dayGroup.groupTitle)}
{#if assetInteraction.selectedGroup.has(day.dayTitle)}
<Icon icon={mdiCheckCircle} size="24" class="text-primary" />
{:else}
<Icon icon={mdiCircleOutline} size="24" color="#757575" />
@@ -177,19 +171,14 @@
</div>
{/if}
<span class="w-full truncate first-letter:capitalize" title={getDayGroupFullDate(dayGroup)}>
{dayGroup.groupTitle}
<span class="w-full truncate first-letter:capitalize" title={getDayFullDate(day)}>
{day.dayTitle}
</span>
</div>
<!-- Image grid -->
<div
data-image-grid
class="relative overflow-clip"
style:height={dayGroup.height + 'px'}
style:width={dayGroup.width + 'px'}
>
{#each filterIntersecting(dayGroup.viewerAssets) as viewerAsset (viewerAsset.id)}
<div data-image-grid class="relative overflow-clip" style:height={day.height + 'px'} style:width={day.width + 'px'}>
{#each filterIntersecting(day.viewerAssets) as viewerAsset (viewerAsset.id)}
{@const position = viewerAsset.position!}
{@const asset = viewerAsset.asset!}
@@ -212,17 +201,17 @@
{groupIndex}
onClick={(asset) => {
if (typeof onThumbnailClick === 'function') {
onThumbnailClick(asset, timelineManager, dayGroup, _onClick);
onThumbnailClick(asset, timelineManager, day, _onClick);
} else {
_onClick(timelineManager, dayGroup.getAssets(), dayGroup.groupTitle, asset);
_onClick(timelineManager, day.getAssets(), day.dayTitle, asset);
}
}}
onSelect={(asset) => assetSelectHandler(timelineManager, asset, dayGroup.getAssets(), dayGroup.groupTitle)}
onMouseEvent={() => assetMouseEventHandler(dayGroup.groupTitle, assetSnapshot(asset))}
onSelect={(asset) => assetSelectHandler(timelineManager, asset, day.getAssets(), day.dayTitle)}
onMouseEvent={() => assetMouseEventHandler(day.dayTitle, assetSnapshot(asset))}
selected={assetInteraction.hasSelectedAsset(asset.id) ||
dayGroup.monthGroup.timelineManager.albumAssets.has(asset.id)}
day.month.timelineManager.albumAssets.has(asset.id)}
selectionCandidate={assetInteraction.hasSelectionCandidate(asset.id)}
disabled={dayGroup.monthGroup.timelineManager.albumAssets.has(asset.id)}
disabled={day.month.timelineManager.albumAssets.has(asset.id)}
thumbnailWidth={position.width}
thumbnailHeight={position.height}
/>

View File

@@ -1,5 +1,5 @@
<script lang="ts">
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import type { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
import { isSelectingAllAssets } from '$lib/stores/assets-store.svelte';
import { cancelMultiselect, selectAllAssets } from '$lib/utils/asset-utils';

View File

@@ -7,7 +7,7 @@
setFocusTo as setFocusToInit,
} from '$lib/components/timeline/actions/focus-actions';
import { AppRoute } from '$lib/constants';
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
import NavigateToDateModal from '$lib/modals/NavigateToDateModal.svelte';
import ShortcutsModal from '$lib/modals/ShortcutsModal.svelte';

View File

@@ -1,4 +1,4 @@
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
import { moveFocus } from '$lib/utils/focus-util';
import { InvocationTracker } from '$lib/utils/invocationTracker';

View File

@@ -0,0 +1 @@
export class ScrollSegment {}

View File

@@ -1,18 +1,16 @@
import { AssetOrder } from '@immich/sdk';
import { onCreateDay } from '$lib/managers/timeline-manager/internal/TestHooks.svelte';
import { TimelineMonth } from '$lib/managers/timeline-manager/TimelineMonth.svelte';
import type { AssetOperation, Direction, TimelineAsset } from '$lib/managers/timeline-manager/types';
import { ViewerAsset } from '$lib/managers/timeline-manager/viewer-asset.svelte';
import type { CommonLayoutOptions } from '$lib/utils/layout-utils';
import { getJustifiedLayoutFromAssets } from '$lib/utils/layout-utils';
import { plainDateTimeCompare } from '$lib/utils/timeline-util';
import { AssetOrder } from '@immich/sdk';
import { onCreateDayGroup } from '$lib/managers/timeline-manager/internal/TestHooks.svelte';
import type { MonthGroup } from './month-group.svelte';
import type { AssetOperation, Direction, TimelineAsset } from './types';
import { ViewerAsset } from './viewer-asset.svelte';
export class DayGroup {
readonly monthGroup: MonthGroup;
export class TimelineDay {
readonly month: TimelineMonth;
readonly index: number;
readonly groupTitle: string;
readonly dayTitle: string;
readonly day: number;
viewerAssets: ViewerAsset[] = $state([]);
@@ -26,13 +24,13 @@ export class DayGroup {
#col = $state(0);
#deferredLayout = false;
constructor(monthGroup: MonthGroup, index: number, day: number, groupTitle: string) {
constructor(month: TimelineMonth, index: number, day: number, dayTitle: string) {
this.index = index;
this.monthGroup = monthGroup;
this.month = month;
this.day = day;
this.groupTitle = groupTitle;
this.dayTitle = dayTitle;
if (import.meta.env.DEV) {
onCreateDayGroup(this);
onCreateDay(this);
}
}
@@ -144,7 +142,7 @@ export class DayGroup {
}
unprocessedIds.delete(assetId);
processedIds.add(assetId);
if (remove || this.monthGroup.timelineManager.isExcluded(asset)) {
if (remove || this.month.timelineManager.isExcluded(asset)) {
this.viewerAssets.splice(index, 1);
changedGeometry = true;
}
@@ -153,7 +151,7 @@ export class DayGroup {
}
layout(options: CommonLayoutOptions, noDefer: boolean) {
if (!noDefer && !this.monthGroup.intersecting) {
if (!noDefer && !this.month.intersecting) {
this.#deferredLayout = true;
return;
}
@@ -167,7 +165,7 @@ export class DayGroup {
}
}
get absoluteDayGroupTop() {
return this.monthGroup.top + this.#top;
get absoluteTop() {
return this.month.top + this.#top;
}
}

View File

@@ -1,16 +1,16 @@
import { sdkMock } from '$lib/__mocks__/sdk.mock';
import type { DayGroup } from '$lib/managers/timeline-manager/day-group.svelte';
import { getMonthGroupByDate } from '$lib/managers/timeline-manager/internal/search-support.svelte';
import { getMonthByDate } from '$lib/managers/timeline-manager/internal/search-support.svelte';
import { setTestHooks } from '$lib/managers/timeline-manager/internal/TestHooks.svelte';
import type { MonthGroup } from '$lib/managers/timeline-manager/month-group.svelte';
import { TimelineDay } from '$lib/managers/timeline-manager/TimelineDay.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import { TimelineMonth } from '$lib/managers/timeline-manager/TimelineMonth.svelte';
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
import { AbortError } from '$lib/utils';
import { fromISODateTimeUTCToObject } from '$lib/utils/timeline-util';
import { AssetVisibility, type AssetResponseDto, type TimeBucketAssetResponseDto } from '@immich/sdk';
import { timelineAssetFactory, toResponseDto } from '@test-data/factories/asset-factory';
import { tick } from 'svelte';
import type { MockInstance } from 'vitest';
import { TimelineManager } from './timeline-manager.svelte';
import type { TimelineAsset } from './types';
async function getAssets(timelineManager: TimelineManager) {
const assets = [];
@@ -98,7 +98,7 @@ describe('TimelineManager', () => {
});
});
describe('loadMonthGroup', () => {
describe('loadMonth', () => {
let timelineManager: TimelineManager;
const bucketAssets: Record<string, TimelineAsset[]> = {
'2024-01-03T00:00:00.000Z': timelineAssetFactory.buildList(1).map((asset) =>
@@ -134,47 +134,47 @@ describe('TimelineManager', () => {
});
it('loads a month', async () => {
expect(getMonthGroupByDate(timelineManager, { year: 2024, month: 1 })?.getAssets().length).toEqual(0);
await timelineManager.loadMonthGroup({ year: 2024, month: 1 });
expect(getMonthByDate(timelineManager, { year: 2024, month: 1 })?.getAssets().length).toEqual(0);
await timelineManager.loadMonth({ year: 2024, month: 1 });
expect(sdkMock.getTimeBucket).toBeCalledTimes(1);
expect(getMonthGroupByDate(timelineManager, { year: 2024, month: 1 })?.getAssets().length).toEqual(3);
expect(getMonthByDate(timelineManager, { year: 2024, month: 1 })?.getAssets().length).toEqual(3);
});
it('ignores invalid months', async () => {
await timelineManager.loadMonthGroup({ year: 2023, month: 1 });
await timelineManager.loadMonth({ year: 2023, month: 1 });
expect(sdkMock.getTimeBucket).toBeCalledTimes(0);
});
it('cancels month loading', async () => {
const month = getMonthGroupByDate(timelineManager, { year: 2024, month: 1 })!;
void timelineManager.loadMonthGroup({ year: 2024, month: 1 });
const month = getMonthByDate(timelineManager, { year: 2024, month: 1 })!;
void timelineManager.loadMonth({ year: 2024, month: 1 });
const abortSpy = vi.spyOn(month!.loader!.cancelToken!, 'abort');
month?.cancel();
expect(abortSpy).toBeCalledTimes(1);
await timelineManager.loadMonthGroup({ year: 2024, month: 1 });
expect(getMonthGroupByDate(timelineManager, { year: 2024, month: 1 })?.getAssets().length).toEqual(3);
await timelineManager.loadMonth({ year: 2024, month: 1 });
expect(getMonthByDate(timelineManager, { year: 2024, month: 1 })?.getAssets().length).toEqual(3);
});
it('prevents loading months multiple times', async () => {
await Promise.all([
timelineManager.loadMonthGroup({ year: 2024, month: 1 }),
timelineManager.loadMonthGroup({ year: 2024, month: 1 }),
timelineManager.loadMonth({ year: 2024, month: 1 }),
timelineManager.loadMonth({ year: 2024, month: 1 }),
]);
expect(sdkMock.getTimeBucket).toBeCalledTimes(1);
await timelineManager.loadMonthGroup({ year: 2024, month: 1 });
await timelineManager.loadMonth({ year: 2024, month: 1 });
expect(sdkMock.getTimeBucket).toBeCalledTimes(1);
});
it('allows loading a canceled month', async () => {
const month = getMonthGroupByDate(timelineManager, { year: 2024, month: 1 })!;
const loadPromise = timelineManager.loadMonthGroup({ year: 2024, month: 1 });
const month = getMonthByDate(timelineManager, { year: 2024, month: 1 })!;
const loadPromise = timelineManager.loadMonth({ year: 2024, month: 1 });
month.cancel();
await loadPromise;
expect(month?.getAssets().length).toEqual(0);
await timelineManager.loadMonthGroup({ year: 2024, month: 1 });
await timelineManager.loadMonth({ year: 2024, month: 1 });
expect(month!.getAssets().length).toEqual(3);
});
});
@@ -244,7 +244,7 @@ describe('TimelineManager', () => {
);
timelineManager.upsertAssets([assetOne, assetTwo, assetThree]);
const month = getMonthGroupByDate(timelineManager, { year: 2024, month: 1 });
const month = getMonthByDate(timelineManager, { year: 2024, month: 1 });
expect(month).not.toBeNull();
expect(month?.getAssets().length).toEqual(3);
expect(month?.getAssets()[0].id).toEqual(assetOne.id);
@@ -319,24 +319,24 @@ describe('TimelineManager', () => {
sortAssetsFn: MockInstance;
};
type MonthMocks = {
sortDayGroupsFn: MockInstance;
sortDaysFn: MockInstance;
};
const dayGroups = new Map<DayGroup, DayMocks>();
const monthGroups = new Map<MonthGroup, MonthMocks>();
const days = new Map<TimelineDay, DayMocks>();
const months = new Map<TimelineMonth, MonthMocks>();
beforeEach(async () => {
timelineManager = new TimelineManager();
setTestHooks({
onCreateDayGroup: (dayGroup: DayGroup) => {
dayGroups.set(dayGroup, {
layoutFn: vi.spyOn(dayGroup, 'layout'),
sortAssetsFn: vi.spyOn(dayGroup, 'sortAssets'),
onCreateDay: (day: TimelineDay) => {
days.set(day, {
layoutFn: vi.spyOn(day, 'layout'),
sortAssetsFn: vi.spyOn(day, 'sortAssets'),
});
},
onCreateMonthGroup: (monthGroup: MonthGroup) => {
monthGroups.set(monthGroup, {
sortDayGroupsFn: vi.spyOn(monthGroup, 'sortDayGroups'),
onCreateMonth: (month: TimelineMonth) => {
months.set(month, {
sortDaysFn: vi.spyOn(month, 'sortDays'),
});
},
});
@@ -394,13 +394,13 @@ describe('TimelineManager', () => {
timelineManager.updateAssetOperation([month1day2asset1.id], (asset) => {
asset.localDateTime.day = asset.localDateTime.day + 1;
});
for (const [day, mocks] of dayGroups) {
if (day.day === 15 && day.monthGroup.yearMonth.month === 1) {
for (const [day, mocks] of days) {
if (day.day === 15 && day.month.yearMonth.month === 1) {
// source - should be layout once
expect.soft(mocks.layoutFn).toBeCalledTimes(1);
expect.soft(mocks.sortAssetsFn).toBeCalledTimes(1);
}
if (day.day === 16 && day.monthGroup.yearMonth.month === 1) {
if (day.day === 16 && day.month.yearMonth.month === 1) {
// target - should be layout once
expect.soft(mocks.layoutFn).toBeCalledTimes(1);
expect.soft(mocks.sortAssetsFn).toBeCalledTimes(1);
@@ -409,12 +409,12 @@ describe('TimelineManager', () => {
expect.soft(mocks.layoutFn).toBeCalledTimes(0);
expect.soft(mocks.sortAssetsFn).toBeCalledTimes(0);
}
for (const [_, mocks] of monthGroups) {
for (const [_, mocks] of months) {
// if the day itself did not change, probably no need to sort it
// in the timeline manager, the day-group identity is immutable - you will never
// "move" a whole day to another day - only the assets inside will be moved from
// one to the other.
expect.soft(mocks.sortDayGroupsFn).toBeCalledTimes(0);
expect.soft(mocks.sortDaysFn).toBeCalledTimes(0);
}
});
});
@@ -455,15 +455,15 @@ describe('TimelineManager', () => {
timelineManager.upsertAssets([asset]);
expect(timelineManager.months.length).toEqual(1);
expect(getMonthGroupByDate(timelineManager, { year: 2024, month: 1 })).not.toBeUndefined();
expect(getMonthGroupByDate(timelineManager, { year: 2024, month: 1 })?.getAssets().length).toEqual(1);
expect(getMonthByDate(timelineManager, { year: 2024, month: 1 })).not.toBeUndefined();
expect(getMonthByDate(timelineManager, { year: 2024, month: 1 })?.getAssets().length).toEqual(1);
timelineManager.upsertAssets([updatedAsset]);
expect(timelineManager.months.length).toEqual(2);
expect(getMonthGroupByDate(timelineManager, { year: 2024, month: 1 })).not.toBeUndefined();
expect(getMonthGroupByDate(timelineManager, { year: 2024, month: 1 })?.getAssets().length).toEqual(0);
expect(getMonthGroupByDate(timelineManager, { year: 2024, month: 3 })).not.toBeUndefined();
expect(getMonthGroupByDate(timelineManager, { year: 2024, month: 3 })?.getAssets().length).toEqual(1);
expect(getMonthByDate(timelineManager, { year: 2024, month: 1 })).not.toBeUndefined();
expect(getMonthByDate(timelineManager, { year: 2024, month: 1 })?.getAssets().length).toEqual(0);
expect(getMonthByDate(timelineManager, { year: 2024, month: 3 })).not.toBeUndefined();
expect(getMonthByDate(timelineManager, { year: 2024, month: 3 })?.getAssets().length).toEqual(1);
});
it('asset is removed during upsert when TimelineManager if visibility changes', async () => {
@@ -655,8 +655,8 @@ describe('TimelineManager', () => {
});
it('returns previous assetId', async () => {
await timelineManager.loadMonthGroup({ year: 2024, month: 1 });
const month = getMonthGroupByDate(timelineManager, { year: 2024, month: 1 });
await timelineManager.loadMonth({ year: 2024, month: 1 });
const month = getMonthByDate(timelineManager, { year: 2024, month: 1 });
const a = month!.getAssets()[0];
const b = month!.getAssets()[1];
@@ -665,11 +665,11 @@ describe('TimelineManager', () => {
});
it('returns previous assetId spanning multiple months', async () => {
await timelineManager.loadMonthGroup({ year: 2024, month: 2 });
await timelineManager.loadMonthGroup({ year: 2024, month: 3 });
await timelineManager.loadMonth({ year: 2024, month: 2 });
await timelineManager.loadMonth({ year: 2024, month: 3 });
const month = getMonthGroupByDate(timelineManager, { year: 2024, month: 2 });
const previousMonth = getMonthGroupByDate(timelineManager, { year: 2024, month: 3 });
const month = getMonthByDate(timelineManager, { year: 2024, month: 2 });
const previousMonth = getMonthByDate(timelineManager, { year: 2024, month: 3 });
const a = month!.getAssets()[0];
const b = previousMonth!.getAssets()[0];
const previous = await timelineManager.getLaterAsset(a);
@@ -677,23 +677,23 @@ describe('TimelineManager', () => {
});
it('loads previous month', async () => {
await timelineManager.loadMonthGroup({ year: 2024, month: 2 });
const month = getMonthGroupByDate(timelineManager, { year: 2024, month: 2 });
const previousMonth = getMonthGroupByDate(timelineManager, { year: 2024, month: 3 });
await timelineManager.loadMonth({ year: 2024, month: 2 });
const month = getMonthByDate(timelineManager, { year: 2024, month: 2 });
const previousMonth = getMonthByDate(timelineManager, { year: 2024, month: 3 });
const a = month!.getFirstAsset();
const b = previousMonth!.getFirstAsset();
const loadMonthGroupSpy = vi.spyOn(month!.loader!, 'execute');
const loadMonthSpy = vi.spyOn(month!.loader!, 'execute');
const previousMonthSpy = vi.spyOn(previousMonth!.loader!, 'execute');
const previous = await timelineManager.getLaterAsset(a);
expect(previous).toEqual(b);
expect(loadMonthGroupSpy).toBeCalledTimes(0);
expect(loadMonthSpy).toBeCalledTimes(0);
expect(previousMonthSpy).toBeCalledTimes(0);
});
it('skips removed assets', async () => {
await timelineManager.loadMonthGroup({ year: 2024, month: 1 });
await timelineManager.loadMonthGroup({ year: 2024, month: 2 });
await timelineManager.loadMonthGroup({ year: 2024, month: 3 });
await timelineManager.loadMonth({ year: 2024, month: 1 });
await timelineManager.loadMonth({ year: 2024, month: 2 });
await timelineManager.loadMonth({ year: 2024, month: 3 });
const [assetOne, assetTwo, assetThree] = await getAssets(timelineManager);
timelineManager.removeAssets([assetTwo.id]);
@@ -701,12 +701,12 @@ describe('TimelineManager', () => {
});
it('returns null when no more assets', async () => {
await timelineManager.loadMonthGroup({ year: 2024, month: 3 });
await timelineManager.loadMonth({ year: 2024, month: 3 });
expect(await timelineManager.getLaterAsset(timelineManager.months[0].getFirstAsset())).toBeUndefined();
});
});
describe('getMonthGroupIndexByAssetId', () => {
describe('getMonthIndexByAssetId', () => {
let timelineManager: TimelineManager;
beforeEach(async () => {
@@ -717,8 +717,8 @@ describe('TimelineManager', () => {
});
it('returns null for invalid months', () => {
expect(getMonthGroupByDate(timelineManager, { year: -1, month: -1 })).toBeUndefined();
expect(getMonthGroupByDate(timelineManager, { year: 2024, month: 3 })).toBeUndefined();
expect(getMonthByDate(timelineManager, { year: -1, month: -1 })).toBeUndefined();
expect(getMonthByDate(timelineManager, { year: 2024, month: 3 })).toBeUndefined();
});
it('returns the month index', () => {
@@ -734,10 +734,10 @@ describe('TimelineManager', () => {
);
timelineManager.upsertAssets([assetOne, assetTwo]);
expect(timelineManager.getMonthGroupByAssetId(assetTwo.id)?.yearMonth.year).toEqual(2024);
expect(timelineManager.getMonthGroupByAssetId(assetTwo.id)?.yearMonth.month).toEqual(2);
expect(timelineManager.getMonthGroupByAssetId(assetOne.id)?.yearMonth.year).toEqual(2024);
expect(timelineManager.getMonthGroupByAssetId(assetOne.id)?.yearMonth.month).toEqual(1);
expect(timelineManager.getMonthByAssetId(assetTwo.id)?.yearMonth.year).toEqual(2024);
expect(timelineManager.getMonthByAssetId(assetTwo.id)?.yearMonth.month).toEqual(2);
expect(timelineManager.getMonthByAssetId(assetOne.id)?.yearMonth.year).toEqual(2024);
expect(timelineManager.getMonthByAssetId(assetOne.id)?.yearMonth.month).toEqual(1);
});
it('ignores removed months', () => {
@@ -754,8 +754,8 @@ describe('TimelineManager', () => {
timelineManager.upsertAssets([assetOne, assetTwo]);
timelineManager.removeAssets([assetTwo.id]);
expect(timelineManager.getMonthGroupByAssetId(assetOne.id)?.yearMonth.year).toEqual(2024);
expect(timelineManager.getMonthGroupByAssetId(assetOne.id)?.yearMonth.month).toEqual(1);
expect(timelineManager.getMonthByAssetId(assetOne.id)?.yearMonth.year).toEqual(2024);
expect(timelineManager.getMonthByAssetId(assetOne.id)?.yearMonth.month).toEqual(1);
});
});

View File

@@ -1,18 +1,30 @@
import { VirtualScrollManager } from '$lib/managers/VirtualScrollManager/VirtualScrollManager.svelte';
import { authManager } from '$lib/managers/auth-manager.svelte';
import { TimelineDay } from '$lib/managers/timeline-manager/TimelineDay.svelte';
import { TimelineMonth } from '$lib/managers/timeline-manager/TimelineMonth.svelte';
import { GroupInsertionCache } from '$lib/managers/timeline-manager/group-insertion-cache.svelte';
import { updateIntersectionMonthGroup } from '$lib/managers/timeline-manager/internal/intersection-support.svelte';
import { updateIntersectionMonth } from '$lib/managers/timeline-manager/internal/intersection-support.svelte';
import { updateGeometry } from '$lib/managers/timeline-manager/internal/layout-support.svelte';
import { loadFromTimeBuckets } from '$lib/managers/timeline-manager/internal/load-support.svelte';
import {
findClosestGroupForDate,
findMonthGroupForAsset as findMonthGroupForAssetUtil,
findMonthGroupForDate,
findMonthForAsset as findMonthForAssetUtil,
findMonthForDate,
getAssetWithOffset,
getMonthGroupByDate,
getMonthByDate,
retrieveRange as retrieveRangeUtil,
} from '$lib/managers/timeline-manager/internal/search-support.svelte';
import { isMismatched, updateObject } from '$lib/managers/timeline-manager/internal/utils.svelte';
import { WebsocketSupport } from '$lib/managers/timeline-manager/internal/websocket-support.svelte';
import type {
AssetDescriptor,
AssetOperation,
Direction,
ScrubberMonth,
TimelineAsset,
TimelineManagerOptions,
Viewport,
} from '$lib/managers/timeline-manager/types';
import { CancellableTask } from '$lib/utils/cancellable-task';
import {
setDifferenceInPlace,
@@ -23,21 +35,9 @@ import {
import { AssetOrder, getAssetInfo, getTimeBuckets } from '@immich/sdk';
import { clamp, isEqual } from 'lodash-es';
import { SvelteDate, SvelteSet } from 'svelte/reactivity';
import { DayGroup } from './day-group.svelte';
import { isMismatched, updateObject } from './internal/utils.svelte';
import { MonthGroup } from './month-group.svelte';
import type {
AssetDescriptor,
AssetOperation,
Direction,
ScrubberMonth,
TimelineAsset,
TimelineManagerOptions,
Viewport,
} from './types';
type ViewportTopMonthIntersection = {
month: MonthGroup | undefined;
month: TimelineMonth | undefined;
// Where viewport top intersects month (0 = month top, 1 = month bottom)
viewportTopRatioInMonth: number;
// Where month bottom is in viewport (0 = viewport top, 1 = viewport bottom)
@@ -63,7 +63,7 @@ export class TimelineManager extends VirtualScrollManager {
});
isInitialized = $state(false);
months: MonthGroup[] = $state([]);
months: TimelineMonth[] = $state([]);
albumAssets: Set<string> = new SvelteSet();
scrubberMonths: ScrubberMonth[] = $state([]);
scrubberTimelineHeight: number = $state(0);
@@ -113,24 +113,24 @@ export class TimelineManager extends VirtualScrollManager {
}
async *assetsIterator(options?: {
startMonthGroup?: MonthGroup;
startDayGroup?: DayGroup;
startMonth?: TimelineMonth;
startDay?: TimelineDay;
startAsset?: TimelineAsset;
direction?: Direction;
}) {
const direction = options?.direction ?? 'earlier';
let { startDayGroup, startAsset } = options ?? {};
for (const monthGroup of this.monthGroupIterator({ direction, startMonthGroup: options?.startMonthGroup })) {
await this.loadMonthGroup(monthGroup.yearMonth, { cancelable: false });
yield* monthGroup.assetsIterator({ startDayGroup, startAsset, direction });
startDayGroup = startAsset = undefined;
let { startDay, startAsset } = options ?? {};
for (const month of this.monthIterator({ direction, startMonth: options?.startMonth })) {
await this.loadMonth(month.yearMonth, { cancelable: false });
yield* month.assetsIterator({ startDay, startAsset, direction });
startDay = startAsset = undefined;
}
}
*monthGroupIterator(options?: { direction?: Direction; startMonthGroup?: MonthGroup }) {
*monthIterator(options?: { direction?: Direction; startMonth?: TimelineMonth }) {
const isEarlier = options?.direction === 'earlier';
let startIndex = options?.startMonthGroup
? this.months.indexOf(options.startMonthGroup)
let startIndex = options?.startMonth
? this.months.indexOf(options.startMonth)
: isEarlier
? 0
: this.months.length - 1;
@@ -157,7 +157,7 @@ export class TimelineManager extends VirtualScrollManager {
this.#websocketSupport = undefined;
}
#calculateMonthBottomViewportRatio(month: MonthGroup | undefined) {
#calculateMonthBottomViewportRatio(month: TimelineMonth | undefined) {
if (!month) {
return 0;
}
@@ -167,7 +167,7 @@ export class TimelineManager extends VirtualScrollManager {
return clamp(bottomOfMonthInViewport / windowHeight, 0, 1);
}
#calculateVewportTopRatioInMonth(month: MonthGroup | undefined) {
#calculateVewportTopRatioInMonth(month: TimelineMonth | undefined) {
if (!month) {
return 0;
}
@@ -181,7 +181,7 @@ export class TimelineManager extends VirtualScrollManager {
this.#updatingIntersections = true;
for (const month of this.months) {
updateIntersectionMonthGroup(this, month);
updateIntersectionMonth(this, month);
}
const month = this.months.find((month) => month.actuallyIntersecting);
@@ -197,17 +197,17 @@ export class TimelineManager extends VirtualScrollManager {
this.#updatingIntersections = false;
}
clearDeferredLayout(month: MonthGroup) {
const hasDeferred = month.dayGroups.some((group) => group.deferredLayout);
clearDeferredLayout(month: TimelineMonth) {
const hasDeferred = month.days.some((group) => group.deferredLayout);
if (hasDeferred) {
updateGeometry(this, month, { invalidateHeight: true, noDefer: true });
for (const group of month.dayGroups) {
for (const group of month.days) {
group.deferredLayout = false;
}
}
}
async #initializeMonthGroups() {
async #initializeMonths() {
const timebuckets = await getTimeBuckets({
...authManager.params,
...this.#options,
@@ -215,7 +215,7 @@ export class TimelineManager extends VirtualScrollManager {
this.months = timebuckets.map((timeBucket) => {
const date = new SvelteDate(timeBucket.timeBucket);
return new MonthGroup(
return new TimelineMonth(
this,
{ year: date.getUTCFullYear(), month: date.getUTCMonth() + 1 },
timeBucket.count,
@@ -246,7 +246,7 @@ export class TimelineManager extends VirtualScrollManager {
this.albumAssets.clear();
await this.initTask.execute(async () => {
this.#options = options;
await this.#initializeMonthGroups();
await this.#initializeMonths();
}, true);
}
@@ -293,31 +293,31 @@ export class TimelineManager extends VirtualScrollManager {
assetCount: month.assetsCount,
year: month.yearMonth.year,
month: month.yearMonth.month,
title: month.monthGroupTitle,
title: month.monthTitle,
height: month.height,
}));
this.scrubberTimelineHeight = this.totalViewerHeight;
}
async loadMonthGroup(yearMonth: TimelineYearMonth, options?: { cancelable: boolean }): Promise<void> {
async loadMonth(yearMonth: TimelineYearMonth, options?: { cancelable: boolean }): Promise<void> {
let cancelable = true;
if (options) {
cancelable = options.cancelable;
}
const monthGroup = getMonthGroupByDate(this, yearMonth);
if (!monthGroup) {
const month = getMonthByDate(this, yearMonth);
if (!month) {
return;
}
if (monthGroup.loader?.executed) {
if (month.loader?.executed) {
return;
}
const executionStatus = await monthGroup.loader?.execute(async (signal: AbortSignal) => {
await loadFromTimeBuckets(this, monthGroup, this.#options, signal);
const executionStatus = await month.loader?.execute(async (signal: AbortSignal) => {
await loadFromTimeBuckets(this, month, this.#options, signal);
}, cancelable);
if (executionStatus === 'LOADED') {
updateGeometry(this, monthGroup, { invalidateHeight: false });
updateGeometry(this, month, { invalidateHeight: false });
this.updateIntersections();
}
}
@@ -328,14 +328,14 @@ export class TimelineManager extends VirtualScrollManager {
this.addAssetsToSegments(notExcluded);
}
async findMonthGroupForAsset(id: string) {
async findMonthForAsset(id: string) {
if (!this.isInitialized) {
await this.initTask.waitUntilCompletion();
}
let { monthGroup } = findMonthGroupForAssetUtil(this, id) ?? {};
if (monthGroup) {
return monthGroup;
let { month } = findMonthForAssetUtil(this, id) ?? {};
if (month) {
return month;
}
const response = await getAssetInfo({ ...authManager.params, id }).catch(() => null);
@@ -348,20 +348,20 @@ export class TimelineManager extends VirtualScrollManager {
return;
}
monthGroup = await this.#loadMonthGroupAtTime(asset.localDateTime, { cancelable: false });
if (monthGroup?.findAssetById({ id })) {
return monthGroup;
month = await this.#loadMonthAtTime(asset.localDateTime, { cancelable: false });
if (month?.findAssetById({ id })) {
return month;
}
}
async #loadMonthGroupAtTime(yearMonth: TimelineYearMonth, options?: { cancelable: boolean }) {
await this.loadMonthGroup(yearMonth, options);
return getMonthGroupByDate(this, yearMonth);
async #loadMonthAtTime(yearMonth: TimelineYearMonth, options?: { cancelable: boolean }) {
await this.loadMonth(yearMonth, options);
return getMonthByDate(this, yearMonth);
}
getMonthGroupByAssetId(assetId: string) {
const monthGroupInfo = findMonthGroupForAssetUtil(this, assetId);
return monthGroupInfo?.monthGroup;
getMonthByAssetId(assetId: string) {
const monthInfo = findMonthForAssetUtil(this, assetId);
return monthInfo?.month;
}
// note: the `index` input is expected to be in the range [0, assetCount). This
@@ -372,7 +372,7 @@ export class TimelineManager extends VirtualScrollManager {
let accumulatedCount = 0;
let randomMonth: MonthGroup | undefined = undefined;
let randomMonth: TimelineMonth | undefined = undefined;
for (const month of this.months) {
if (randomAssetIndex < accumulatedCount + month.assetsCount) {
randomMonth = month;
@@ -384,10 +384,10 @@ export class TimelineManager extends VirtualScrollManager {
if (!randomMonth) {
return;
}
await this.loadMonthGroup(randomMonth.yearMonth, { cancelable: false });
await this.loadMonth(randomMonth.yearMonth, { cancelable: false });
let randomDay: DayGroup | undefined = undefined;
for (const day of randomMonth.dayGroups) {
let randomDay: TimelineDay | undefined = undefined;
for (const day of randomMonth.days) {
if (randomAssetIndex < accumulatedCount + day.viewerAssets.length) {
randomDay = day;
break;
@@ -443,10 +443,10 @@ export class TimelineManager extends VirtualScrollManager {
}
protected upsertAssetIntoSegment(asset: TimelineAsset, context: GroupInsertionCache): void {
let month = getMonthGroupByDate(this, asset.localDateTime);
let month = getMonthByDate(this, asset.localDateTime);
if (!month) {
month = new MonthGroup(this, asset.localDateTime, 1, true, this.#options.order);
month = new TimelineMonth(this, asset.localDateTime, 1, true, this.#options.order);
this.months.push(month);
}
@@ -476,7 +476,7 @@ export class TimelineManager extends VirtualScrollManager {
}
// eslint-disable-next-line svelte/prefer-svelte-reactivity
const changedMonthGroups = new Set<MonthGroup>();
const changedMonths = new Set<TimelineMonth>();
// eslint-disable-next-line svelte/prefer-svelte-reactivity
const idsToProcess = new Set(ids);
// eslint-disable-next-line svelte/prefer-svelte-reactivity
@@ -493,15 +493,15 @@ export class TimelineManager extends VirtualScrollManager {
idsProcessed.add(id);
}
if (changedGeometry) {
changedMonthGroups.add(month);
changedMonths.add(month);
}
}
}
if (combinedMoveAssets.length > 0) {
this.addAssetsToSegments(combinedMoveAssets);
}
const changedGeometry = changedMonthGroups.size > 0;
for (const month of changedMonthGroups) {
const changedGeometry = changedMonths.size > 0;
for (const month of changedMonths) {
updateGeometry(this, month, { invalidateHeight: true });
}
if (changedGeometry) {
@@ -536,20 +536,20 @@ export class TimelineManager extends VirtualScrollManager {
}
async getClosestAssetToDate(dateTime: TimelineDateTime) {
let monthGroup = findMonthGroupForDate(this, dateTime);
if (!monthGroup) {
let month = findMonthForDate(this, dateTime);
if (!month) {
// if exact match not found, find closest
monthGroup = findClosestGroupForDate(this.months, dateTime);
if (!monthGroup) {
month = findClosestGroupForDate(this.months, dateTime);
if (!month) {
return;
}
}
await this.loadMonthGroup(dateTime, { cancelable: false });
const asset = monthGroup.findClosest(dateTime);
await this.loadMonth(dateTime, { cancelable: false });
const asset = month.findClosest(dateTime);
if (asset) {
return asset;
}
for await (const asset of this.assetsIterator({ startMonthGroup: monthGroup })) {
for await (const asset of this.assetsIterator({ startMonth: month })) {
return asset;
}
}
@@ -579,16 +579,16 @@ export class TimelineManager extends VirtualScrollManager {
}
protected postUpsert(context: GroupInsertionCache): void {
for (const group of context.existingDayGroups) {
for (const group of context.existingDays) {
group.sortAssets(this.#options.order);
}
for (const monthGroup of context.bucketsWithNewDayGroups) {
monthGroup.sortDayGroups();
for (const month of context.monthsWithNewDays) {
month.sortDays();
}
for (const month of context.updatedBuckets) {
month.sortDayGroups();
for (const month of context.updatedMonths) {
month.sortDays();
updateGeometry(this, month, { invalidateHeight: true });
}
}

View File

@@ -1,10 +1,15 @@
import { AssetOrder, type TimeBucketAssetResponseDto } from '@immich/sdk';
import { GroupInsertionCache } from '$lib/managers/timeline-manager/group-insertion-cache.svelte';
import { onCreateMonth } from '$lib/managers/timeline-manager/internal/TestHooks.svelte';
import { TimelineDay } from '$lib/managers/timeline-manager/TimelineDay.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import type { AssetDescriptor, AssetOperation, Direction, TimelineAsset } from '$lib/managers/timeline-manager/types';
import { ViewerAsset } from '$lib/managers/timeline-manager/viewer-asset.svelte';
import { ScrollSegment } from '$lib/managers/VirtualScrollManager/ScrollSegment.svelte';
import { CancellableTask } from '$lib/utils/cancellable-task';
import { handleError } from '$lib/utils/handle-error';
import {
formatGroupTitle,
formatMonthGroupTitle,
formatDayTitle,
formatMonthTitle,
fromTimelinePlainDate,
fromTimelinePlainDateTime,
fromTimelinePlainYearMonth,
@@ -13,22 +18,15 @@ import {
type TimelineDateTime,
type TimelineYearMonth,
} from '$lib/utils/timeline-util';
import { AssetOrder, type TimeBucketAssetResponseDto } from '@immich/sdk';
import { t } from 'svelte-i18n';
import { get } from 'svelte/store';
import { onCreateMonthGroup } from '$lib/managers/timeline-manager/internal/TestHooks.svelte';
import { DayGroup } from './day-group.svelte';
import { GroupInsertionCache } from './group-insertion-cache.svelte';
import { TimelineManager } from './timeline-manager.svelte';
import type { AssetDescriptor, AssetOperation, Direction, TimelineAsset } from './types';
import { ViewerAsset } from './viewer-asset.svelte';
export class MonthGroup {
export class TimelineMonth extends ScrollSegment {
#intersecting: boolean = $state(false);
actuallyIntersecting: boolean = $state(false);
isLoaded: boolean = $state(false);
dayGroups: DayGroup[] = $state([]);
days: TimelineDay[] = $state([]);
readonly timelineManager: TimelineManager;
#height: number = $state(0);
@@ -39,14 +37,12 @@ export class MonthGroup {
percent: number = $state(0);
assetsCount: number = $derived(
this.isLoaded
? this.dayGroups.reduce((accumulator, g) => accumulator + g.viewerAssets.length, 0)
: this.#initialCount,
this.isLoaded ? this.days.reduce((accumulator, g) => accumulator + g.viewerAssets.length, 0) : this.#initialCount,
);
loader: CancellableTask | undefined;
isHeightActual: boolean = $state(false);
readonly monthGroupTitle: string;
readonly monthTitle: string;
readonly yearMonth: TimelineYearMonth;
constructor(
@@ -56,19 +52,20 @@ export class MonthGroup {
loaded: boolean,
order: AssetOrder = AssetOrder.Desc,
) {
super();
this.timelineManager = timelineManager;
this.#initialCount = initialCount;
this.#sortOrder = order;
this.yearMonth = yearMonth;
this.monthGroupTitle = formatMonthGroupTitle(fromTimelinePlainYearMonth(yearMonth));
this.monthTitle = formatMonthTitle(fromTimelinePlainYearMonth(yearMonth));
this.loader = new CancellableTask(
() => {
this.isLoaded = true;
},
() => {
this.dayGroups = [];
this.days = [];
this.isLoaded = false;
},
this.#handleLoadError,
@@ -77,7 +74,7 @@ export class MonthGroup {
this.isLoaded = true;
}
if (import.meta.env.DEV) {
onCreateMonthGroup(this);
onCreateMonth(this);
}
}
@@ -88,7 +85,7 @@ export class MonthGroup {
}
this.#intersecting = newValue;
if (newValue) {
void this.timelineManager.loadMonthGroup(this.yearMonth);
void this.timelineManager.loadMonth(this.yearMonth);
} else {
this.cancel();
}
@@ -98,25 +95,25 @@ export class MonthGroup {
return this.#intersecting;
}
get lastDayGroup() {
return this.dayGroups.at(-1);
get lastDay() {
return this.days.at(-1);
}
getFirstAsset() {
return this.dayGroups[0]?.getFirstAsset();
return this.days[0]?.getFirstAsset();
}
getAssets() {
// eslint-disable-next-line unicorn/no-array-reduce
return this.dayGroups.reduce((accumulator: TimelineAsset[], g: DayGroup) => accumulator.concat(g.getAssets()), []);
return this.days.reduce((accumulator: TimelineAsset[], g: TimelineDay) => accumulator.concat(g.getAssets()), []);
}
sortDayGroups() {
sortDays() {
if (this.#sortOrder === AssetOrder.Asc) {
return this.dayGroups.sort((a, b) => a.day - b.day);
return this.days.sort((a, b) => a.day - b.day);
}
return this.dayGroups.sort((a, b) => b.day - a.day);
return this.days.sort((a, b) => b.day - a.day);
}
runAssetOperation(ids: Set<string>, operation: AssetOperation) {
@@ -129,17 +126,17 @@ export class MonthGroup {
changedGeometry: false,
};
}
const { dayGroups } = this;
const { days } = this;
let combinedChangedGeometry = false;
// eslint-disable-next-line svelte/prefer-svelte-reactivity
const idsToProcess = new Set(ids);
// eslint-disable-next-line svelte/prefer-svelte-reactivity
const idsProcessed = new Set<string>();
const combinedMoveAssets: TimelineAsset[] = [];
let index = dayGroups.length;
let index = days.length;
while (index--) {
if (idsToProcess.size > 0) {
const group = dayGroups[index];
const group = days[index];
const { moveAssets, processedIds, changedGeometry } = group.runAssetOperation(ids, operation);
if (moveAssets.length > 0) {
combinedMoveAssets.push(...moveAssets);
@@ -150,7 +147,7 @@ export class MonthGroup {
}
combinedChangedGeometry = combinedChangedGeometry || changedGeometry;
if (group.viewerAssets.length === 0) {
dayGroups.splice(index, 1);
days.splice(index, 1);
combinedChangedGeometry = true;
}
}
@@ -205,12 +202,12 @@ export class MonthGroup {
this.addTimelineAsset(timelineAsset, addContext);
}
if (!preSorted) {
for (const group of addContext.existingDayGroups) {
for (const group of addContext.existingDays) {
group.sortAssets(this.#sortOrder);
}
if (addContext.newDayGroups.size > 0) {
this.sortDayGroups();
if (addContext.newDays.size > 0) {
this.sortDays();
}
addContext.sort(this, this.#sortOrder);
@@ -227,20 +224,20 @@ export class MonthGroup {
return;
}
let dayGroup = addContext.getDayGroup(localDateTime) || this.findDayGroupByDay(localDateTime.day);
if (dayGroup) {
addContext.setDayGroup(dayGroup, localDateTime);
let day = addContext.getDay(localDateTime) || this.findDayByDay(localDateTime.day);
if (day) {
addContext.setDay(day, localDateTime);
} else {
const groupTitle = formatGroupTitle(fromTimelinePlainDate(localDateTime));
dayGroup = new DayGroup(this, this.dayGroups.length, localDateTime.day, groupTitle);
this.dayGroups.push(dayGroup);
addContext.setDayGroup(dayGroup, localDateTime);
addContext.newDayGroups.add(dayGroup);
const dayTitle = formatDayTitle(fromTimelinePlainDate(localDateTime));
day = new TimelineDay(this, this.days.length, localDateTime.day, dayTitle);
this.days.push(day);
addContext.setDay(day, localDateTime);
addContext.newDays.add(day);
}
const viewerAsset = new ViewerAsset(dayGroup, timelineAsset);
dayGroup.viewerAssets.push(viewerAsset);
addContext.changedDayGroups.add(dayGroup);
const viewerAsset = new ViewerAsset(day, timelineAsset);
day.viewerAssets.push(viewerAsset);
addContext.changedDays.add(day);
}
get viewId() {
@@ -256,9 +253,9 @@ export class MonthGroup {
const index = timelineManager.months.indexOf(this);
const heightDelta = height - this.#height;
this.#height = height;
const prevMonthGroup = timelineManager.months[index - 1];
if (prevMonthGroup) {
const newTop = prevMonthGroup.#top + prevMonthGroup.#height;
const prevMonth = timelineManager.months[index - 1];
if (prevMonth) {
const newTop = prevMonth.#top + prevMonth.#height;
if (this.#top !== newTop) {
this.#top = newTop;
}
@@ -267,10 +264,10 @@ export class MonthGroup {
return;
}
for (let cursor = index + 1; cursor < timelineManager.months.length; cursor++) {
const monthGroup = this.timelineManager.months[cursor];
const newTop = monthGroup.#top + heightDelta;
if (monthGroup.#top !== newTop) {
monthGroup.#top = newTop;
const month = this.timelineManager.months[cursor];
const newTop = month.#top + heightDelta;
if (month.#top !== newTop) {
month.#top = newTop;
}
}
if (!timelineManager.viewportTopMonthIntersection) {
@@ -302,21 +299,21 @@ export class MonthGroup {
handleError(error, _$t('errors.failed_to_load_assets'));
}
findDayGroupForAsset(asset: TimelineAsset) {
for (const group of this.dayGroups) {
findDayForAsset(asset: TimelineAsset) {
for (const group of this.days) {
if (group.viewerAssets.some((viewerAsset) => viewerAsset.id === asset.id)) {
return group;
}
}
}
findDayGroupByDay(day: number) {
return this.dayGroups.find((group) => group.day === day);
findDayByDay(day: number) {
return this.days.find((group) => group.day === day);
}
findAssetAbsolutePosition(assetId: string) {
this.timelineManager.clearDeferredLayout(this);
for (const group of this.dayGroups) {
for (const group of this.days) {
const viewerAsset = group.viewerAssets.find((viewAsset) => viewAsset.id === assetId);
if (viewerAsset) {
if (!viewerAsset.position) {
@@ -331,18 +328,14 @@ export class MonthGroup {
}
}
*assetsIterator(options?: { startDayGroup?: DayGroup; startAsset?: TimelineAsset; direction?: Direction }) {
*assetsIterator(options?: { startDay?: TimelineDay; startAsset?: TimelineAsset; direction?: Direction }) {
const direction = options?.direction ?? 'earlier';
let { startAsset } = options ?? {};
const isEarlier = direction === 'earlier';
let groupIndex = options?.startDayGroup
? this.dayGroups.indexOf(options.startDayGroup)
: isEarlier
? 0
: this.dayGroups.length - 1;
let groupIndex = options?.startDay ? this.days.indexOf(options.startDay) : isEarlier ? 0 : this.days.length - 1;
while (groupIndex >= 0 && groupIndex < this.dayGroups.length) {
const group = this.dayGroups[groupIndex];
while (groupIndex >= 0 && groupIndex < this.days.length) {
const group = this.days[groupIndex];
yield* group.assetsIterator({ startAsset, direction });
startAsset = undefined;
groupIndex += isEarlier ? 1 : -1;

View File

@@ -1,64 +1,64 @@
import { TimelineDay } from '$lib/managers/timeline-manager/TimelineDay.svelte';
import { TimelineMonth } from '$lib/managers/timeline-manager/TimelineMonth.svelte';
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
import { setDifference, type TimelineDate } from '$lib/utils/timeline-util';
import { AssetOrder } from '@immich/sdk';
import type { DayGroup } from './day-group.svelte';
import type { MonthGroup } from './month-group.svelte';
import type { TimelineAsset } from './types';
export class GroupInsertionCache {
#lookupCache: {
[year: number]: { [month: number]: { [day: number]: DayGroup } };
[year: number]: { [month: number]: { [day: number]: TimelineDay } };
} = {};
unprocessedAssets: TimelineAsset[] = [];
// eslint-disable-next-line svelte/prefer-svelte-reactivity
changedDayGroups = new Set<DayGroup>();
changedDays = new Set<TimelineDay>();
// eslint-disable-next-line svelte/prefer-svelte-reactivity
newDayGroups = new Set<DayGroup>();
newDays = new Set<TimelineDay>();
getDayGroup({ year, month, day }: TimelineDate): DayGroup | undefined {
getDay({ year, month, day }: TimelineDate): TimelineDay | undefined {
return this.#lookupCache[year]?.[month]?.[day];
}
setDayGroup(dayGroup: DayGroup, { year, month, day }: TimelineDate) {
setDay(day: TimelineDay, { year, month, day: dayNumber }: TimelineDate) {
if (!this.#lookupCache[year]) {
this.#lookupCache[year] = {};
}
if (!this.#lookupCache[year][month]) {
this.#lookupCache[year][month] = {};
}
this.#lookupCache[year][month][day] = dayGroup;
this.#lookupCache[year][month][dayNumber] = day;
}
get existingDayGroups() {
return setDifference(this.changedDayGroups, this.newDayGroups);
get existingDays() {
return setDifference(this.changedDays, this.newDays);
}
get updatedBuckets() {
get updatedMonths() {
// eslint-disable-next-line svelte/prefer-svelte-reactivity
const updated = new Set<MonthGroup>();
for (const group of this.changedDayGroups) {
updated.add(group.monthGroup);
const months = new Set<TimelineMonth>();
for (const day of this.changedDays) {
months.add(day.month);
}
return updated;
return months;
}
get bucketsWithNewDayGroups() {
get monthsWithNewDays() {
// eslint-disable-next-line svelte/prefer-svelte-reactivity
const updated = new Set<MonthGroup>();
for (const group of this.newDayGroups) {
updated.add(group.monthGroup);
const months = new Set<TimelineMonth>();
for (const day of this.newDays) {
months.add(day.month);
}
return updated;
return months;
}
sort(monthGroup: MonthGroup, sortOrder: AssetOrder = AssetOrder.Desc) {
for (const group of this.changedDayGroups) {
group.sortAssets(sortOrder);
sort(month: TimelineMonth, sortOrder: AssetOrder = AssetOrder.Desc) {
for (const day of this.changedDays) {
day.sortAssets(sortOrder);
}
for (const group of this.newDayGroups) {
group.sortAssets(sortOrder);
for (const day of this.newDays) {
day.sortAssets(sortOrder);
}
if (this.newDayGroups.size > 0) {
monthGroup.sortDayGroups();
if (this.newDays.size > 0) {
month.sortDays();
}
}
}

View File

@@ -1,16 +1,16 @@
import type { DayGroup } from '$lib/managers/timeline-manager/day-group.svelte';
import type { MonthGroup } from '$lib/managers/timeline-manager/month-group.svelte';
import { TimelineDay } from '$lib/managers/timeline-manager/TimelineDay.svelte';
import { TimelineMonth } from '$lib/managers/timeline-manager/TimelineMonth.svelte';
let testHooks: TestHooks | undefined = undefined;
export type TestHooks = {
onCreateMonthGroup(monthGroup: MonthGroup): unknown;
onCreateDayGroup(dayGroup: DayGroup): unknown;
onCreateMonth(month: TimelineMonth): unknown;
onCreateDay(day: TimelineDay): unknown;
};
export const setTestHooks = (hooks: TestHooks) => {
testHooks = hooks;
};
export const onCreateMonthGroup = (monthGroup: MonthGroup) => testHooks?.onCreateMonthGroup(monthGroup);
export const onCreateDayGroup = (dayGroup: DayGroup) => testHooks?.onCreateDayGroup(dayGroup);
export const onCreateMonth = (month: TimelineMonth) => testHooks?.onCreateMonth(month);
export const onCreateDay = (day: TimelineDay) => testHooks?.onCreateDay(day);

View File

@@ -1,16 +1,16 @@
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import { TimelineMonth } from '$lib/managers/timeline-manager/TimelineMonth.svelte';
import { TUNABLES } from '$lib/utils/tunables';
import type { MonthGroup } from '../month-group.svelte';
import { TimelineManager } from '../timeline-manager.svelte';
const {
TIMELINE: { INTERSECTION_EXPAND_TOP, INTERSECTION_EXPAND_BOTTOM },
} = TUNABLES;
export function updateIntersectionMonthGroup(timelineManager: TimelineManager, month: MonthGroup) {
const actuallyIntersecting = calculateMonthGroupIntersecting(timelineManager, month, 0, 0);
export function updateIntersectionMonth(timelineManager: TimelineManager, month: TimelineMonth) {
const actuallyIntersecting = calculateMonthIntersecting(timelineManager, month, 0, 0);
let preIntersecting = false;
if (!actuallyIntersecting) {
preIntersecting = calculateMonthGroupIntersecting(
preIntersecting = calculateMonthIntersecting(
timelineManager,
month,
INTERSECTION_EXPAND_TOP,
@@ -40,18 +40,18 @@ export function isIntersecting(regionTop: number, regionBottom: number, windowTo
);
}
export function calculateMonthGroupIntersecting(
export function calculateMonthIntersecting(
timelineManager: TimelineManager,
monthGroup: MonthGroup,
month: TimelineMonth,
expandTop: number,
expandBottom: number,
) {
const monthGroupTop = monthGroup.top;
const monthGroupBottom = monthGroupTop + monthGroup.height;
const monthTop = month.top;
const monthBottom = monthTop + month.height;
const topWindow = timelineManager.visibleWindow.top - expandTop;
const bottomWindow = timelineManager.visibleWindow.bottom + expandBottom;
return isIntersecting(monthGroupTop, monthGroupBottom, topWindow, bottomWindow);
return isIntersecting(monthTop, monthBottom, topWindow, bottomWindow);
}
/**

View File

@@ -1,8 +1,8 @@
import type { MonthGroup } from '../month-group.svelte';
import { TimelineManager } from '../timeline-manager.svelte';
import type { UpdateGeometryOptions } from '../types';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import { TimelineMonth } from '$lib/managers/timeline-manager/TimelineMonth.svelte';
import type { UpdateGeometryOptions } from '$lib/managers/timeline-manager/types';
export function updateGeometry(timelineManager: TimelineManager, month: MonthGroup, options: UpdateGeometryOptions) {
export function updateGeometry(timelineManager: TimelineManager, month: TimelineMonth, options: UpdateGeometryOptions) {
const { invalidateHeight, noDefer = false } = options;
if (invalidateHeight) {
month.isHeightActual = false;
@@ -17,49 +17,49 @@ export function updateGeometry(timelineManager: TimelineManager, month: MonthGro
}
return;
}
layoutMonthGroup(timelineManager, month, noDefer);
layoutMonth(timelineManager, month, noDefer);
}
export function layoutMonthGroup(timelineManager: TimelineManager, month: MonthGroup, noDefer: boolean = false) {
export function layoutMonth(timelineManager: TimelineManager, month: TimelineMonth, noDefer: boolean = false) {
let cumulativeHeight = 0;
let cumulativeWidth = 0;
let currentRowHeight = 0;
let dayGroupRow = 0;
let dayGroupCol = 0;
let dayRow = 0;
let dayCol = 0;
const options = timelineManager.justifiedLayoutOptions;
for (const dayGroup of month.dayGroups) {
dayGroup.layout(options, noDefer);
for (const day of month.days) {
day.layout(options, noDefer);
// Calculate space needed for this item (including gap if not first in row)
const spaceNeeded = dayGroup.width + (dayGroupCol > 0 ? timelineManager.gap : 0);
const spaceNeeded = day.width + (dayCol > 0 ? timelineManager.gap : 0);
const fitsInCurrentRow = cumulativeWidth + spaceNeeded <= timelineManager.viewportWidth;
if (fitsInCurrentRow) {
dayGroup.row = dayGroupRow;
dayGroup.col = dayGroupCol++;
dayGroup.left = cumulativeWidth;
dayGroup.top = cumulativeHeight;
day.row = dayRow;
day.col = dayCol++;
day.left = cumulativeWidth;
day.top = cumulativeHeight;
cumulativeWidth += dayGroup.width + timelineManager.gap;
cumulativeWidth += day.width + timelineManager.gap;
} else {
// Move to next row
cumulativeHeight += currentRowHeight;
cumulativeWidth = 0;
dayGroupRow++;
dayGroupCol = 0;
dayRow++;
dayCol = 0;
// Position at start of new row
dayGroup.row = dayGroupRow;
dayGroup.col = dayGroupCol;
dayGroup.left = 0;
dayGroup.top = cumulativeHeight;
day.row = dayRow;
day.col = dayCol;
day.left = 0;
day.top = cumulativeHeight;
dayGroupCol++;
cumulativeWidth += dayGroup.width + timelineManager.gap;
dayCol++;
cumulativeWidth += day.width + timelineManager.gap;
}
currentRowHeight = dayGroup.height + timelineManager.headerHeight;
currentRowHeight = day.height + timelineManager.headerHeight;
}
// Add the height of the final row

View File

@@ -1,21 +1,21 @@
import { authManager } from '$lib/managers/auth-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import { TimelineMonth } from '$lib/managers/timeline-manager/TimelineMonth.svelte';
import type { TimelineManagerOptions } from '$lib/managers/timeline-manager/types';
import { toISOYearMonthUTC } from '$lib/utils/timeline-util';
import { getTimeBucket } from '@immich/sdk';
import type { MonthGroup } from '../month-group.svelte';
import { TimelineManager } from '../timeline-manager.svelte';
import type { TimelineManagerOptions } from '../types';
export async function loadFromTimeBuckets(
timelineManager: TimelineManager,
monthGroup: MonthGroup,
month: TimelineMonth,
options: TimelineManagerOptions,
signal: AbortSignal,
): Promise<void> {
if (monthGroup.getFirstAsset()) {
if (month.getFirstAsset()) {
return;
}
const timeBucket = toISOYearMonthUTC(monthGroup.yearMonth);
const timeBucket = toISOYearMonthUTC(month.yearMonth);
const bucketResponse = await getTimeBucket(
{
...authManager.params,
@@ -43,10 +43,10 @@ export async function loadFromTimeBuckets(
}
}
const unprocessedAssets = monthGroup.addAssets(bucketResponse, true);
const unprocessedAssets = month.addAssets(bucketResponse, true);
if (unprocessedAssets.length > 0) {
console.error(
`Warning: getTimeBucket API returning assets not in requested month: ${monthGroup.yearMonth.month}, ${JSON.stringify(
`Warning: getTimeBucket API returning assets not in requested month: ${month.yearMonth.month}, ${JSON.stringify(
unprocessedAssets.map((unprocessed) => ({
id: unprocessed.id,
localDateTime: unprocessed.localDateTime,

View File

@@ -1,11 +1,11 @@
import { findClosestGroupForDate } from '$lib/managers/timeline-manager/internal/search-support.svelte';
import { TimelineMonth } from '$lib/managers/timeline-manager/TimelineMonth.svelte';
import { describe, expect, it } from 'vitest';
import type { MonthGroup } from '../month-group.svelte';
import { findClosestGroupForDate } from './search-support.svelte';
function createMockMonthGroup(year: number, month: number): MonthGroup {
function createMockMonth(year: number, month: number): TimelineMonth {
return {
yearMonth: { year, month },
} as MonthGroup;
} as TimelineMonth;
}
describe('findClosestGroupForDate', () => {
@@ -15,25 +15,25 @@ describe('findClosestGroupForDate', () => {
});
it('should return the only month when there is only one month', () => {
const months = [createMockMonthGroup(2024, 6)];
const months = [createMockMonth(2024, 6)];
const result = findClosestGroupForDate(months, { year: 2025, month: 1 });
expect(result?.yearMonth).toEqual({ year: 2024, month: 6 });
});
it('should return exact match when available', () => {
const months = [createMockMonthGroup(2024, 1), createMockMonthGroup(2024, 6), createMockMonthGroup(2024, 12)];
const months = [createMockMonth(2024, 1), createMockMonth(2024, 6), createMockMonth(2024, 12)];
const result = findClosestGroupForDate(months, { year: 2024, month: 6 });
expect(result?.yearMonth).toEqual({ year: 2024, month: 6 });
});
it('should find closest month when target is between two months', () => {
const months = [createMockMonthGroup(2024, 1), createMockMonthGroup(2024, 6), createMockMonthGroup(2024, 12)];
const months = [createMockMonth(2024, 1), createMockMonth(2024, 6), createMockMonth(2024, 12)];
const result = findClosestGroupForDate(months, { year: 2024, month: 4 });
expect(result?.yearMonth).toEqual({ year: 2024, month: 6 });
});
it('should handle year boundaries correctly (2023-12 vs 2024-01)', () => {
const months = [createMockMonthGroup(2023, 12), createMockMonthGroup(2024, 2)];
const months = [createMockMonth(2023, 12), createMockMonth(2024, 2)];
const result = findClosestGroupForDate(months, { year: 2024, month: 1 });
// 2024-01 is 1 month from 2023-12 and 1 month from 2024-02
// Should return first encountered with min distance (2023-12)
@@ -41,33 +41,33 @@ describe('findClosestGroupForDate', () => {
});
it('should correctly calculate distance across years', () => {
const months = [createMockMonthGroup(2022, 6), createMockMonthGroup(2024, 6)];
const months = [createMockMonth(2022, 6), createMockMonth(2024, 6)];
const result = findClosestGroupForDate(months, { year: 2023, month: 6 });
// Both are exactly 12 months away, should return first encountered
expect(result?.yearMonth).toEqual({ year: 2022, month: 6 });
});
it('should handle target before all months', () => {
const months = [createMockMonthGroup(2024, 6), createMockMonthGroup(2024, 12)];
const months = [createMockMonth(2024, 6), createMockMonth(2024, 12)];
const result = findClosestGroupForDate(months, { year: 2024, month: 1 });
expect(result?.yearMonth).toEqual({ year: 2024, month: 6 });
});
it('should handle target after all months', () => {
const months = [createMockMonthGroup(2024, 1), createMockMonthGroup(2024, 6)];
const months = [createMockMonth(2024, 1), createMockMonth(2024, 6)];
const result = findClosestGroupForDate(months, { year: 2025, month: 1 });
expect(result?.yearMonth).toEqual({ year: 2024, month: 6 });
});
it('should handle multiple years correctly', () => {
const months = [createMockMonthGroup(2020, 1), createMockMonthGroup(2022, 1), createMockMonthGroup(2024, 1)];
const months = [createMockMonth(2020, 1), createMockMonth(2022, 1), createMockMonth(2024, 1)];
const result = findClosestGroupForDate(months, { year: 2023, month: 1 });
// 2023-01 is 12 months from 2022-01 and 12 months from 2024-01
expect(result?.yearMonth).toEqual({ year: 2022, month: 1 });
});
it('should prefer closer month when one is clearly closer', () => {
const months = [createMockMonthGroup(2024, 1), createMockMonthGroup(2024, 10)];
const months = [createMockMonth(2024, 1), createMockMonth(2024, 10)];
const result = findClosestGroupForDate(months, { year: 2024, month: 11 });
// 2024-11 is 1 month from 2024-10 and 10 months from 2024-01
expect(result?.yearMonth).toEqual({ year: 2024, month: 10 });

View File

@@ -1,9 +1,9 @@
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import { TimelineMonth } from '$lib/managers/timeline-manager/TimelineMonth.svelte';
import type { AssetDescriptor, Direction, TimelineAsset } from '$lib/managers/timeline-manager/types';
import { plainDateTimeCompare, type TimelineYearMonth } from '$lib/utils/timeline-util';
import { AssetOrder } from '@immich/sdk';
import { DateTime } from 'luxon';
import type { MonthGroup } from '../month-group.svelte';
import { TimelineManager } from '../timeline-manager.svelte';
import type { AssetDescriptor, Direction, TimelineAsset } from '../types';
export async function getAssetWithOffset(
timelineManager: TimelineManager,
@@ -11,40 +11,40 @@ export async function getAssetWithOffset(
interval: 'asset' | 'day' | 'month' | 'year' = 'asset',
direction: Direction,
): Promise<TimelineAsset | undefined> {
const { asset, monthGroup } = findMonthGroupForAsset(timelineManager, assetDescriptor.id) ?? {};
if (!monthGroup || !asset) {
const { asset, month } = findMonthForAsset(timelineManager, assetDescriptor.id) ?? {};
if (!month || !asset) {
return;
}
switch (interval) {
case 'asset': {
return getAssetByAssetOffset(timelineManager, asset, monthGroup, direction);
return getAssetByAssetOffset(timelineManager, asset, month, direction);
}
case 'day': {
return getAssetByDayOffset(timelineManager, asset, monthGroup, direction);
return getAssetByDayOffset(timelineManager, asset, month, direction);
}
case 'month': {
return getAssetByMonthOffset(timelineManager, monthGroup, direction);
return getAssetByMonthOffset(timelineManager, month, direction);
}
case 'year': {
return getAssetByYearOffset(timelineManager, monthGroup, direction);
return getAssetByYearOffset(timelineManager, month, direction);
}
}
}
export function findMonthGroupForAsset(timelineManager: TimelineManager, id: string) {
export function findMonthForAsset(timelineManager: TimelineManager, id: string) {
for (const month of timelineManager.months) {
const asset = month.findAssetById({ id });
if (asset) {
return { monthGroup: month, asset };
return { month, asset };
}
}
}
export function getMonthGroupByDate(
export function getMonthByDate(
timelineManager: TimelineManager,
targetYearMonth: TimelineYearMonth,
): MonthGroup | undefined {
): TimelineMonth | undefined {
return timelineManager.months.find(
(month) => month.yearMonth.year === targetYearMonth.year && month.yearMonth.month === targetYearMonth.month,
);
@@ -53,13 +53,13 @@ export function getMonthGroupByDate(
async function getAssetByAssetOffset(
timelineManager: TimelineManager,
asset: TimelineAsset,
monthGroup: MonthGroup,
month: TimelineMonth,
direction: Direction,
) {
const dayGroup = monthGroup.findDayGroupForAsset(asset);
const day = month.findDayForAsset(asset);
for await (const targetAsset of timelineManager.assetsIterator({
startMonthGroup: monthGroup,
startDayGroup: dayGroup,
startMonth: month,
startDay: day,
startAsset: asset,
direction,
})) {
@@ -72,13 +72,13 @@ async function getAssetByAssetOffset(
async function getAssetByDayOffset(
timelineManager: TimelineManager,
asset: TimelineAsset,
monthGroup: MonthGroup,
month: TimelineMonth,
direction: Direction,
) {
const dayGroup = monthGroup.findDayGroupForAsset(asset);
const day = month.findDayForAsset(asset);
for await (const targetAsset of timelineManager.assetsIterator({
startMonthGroup: monthGroup,
startDayGroup: dayGroup,
startMonth: month,
startDay: day,
startAsset: asset,
direction,
})) {
@@ -88,44 +88,44 @@ async function getAssetByDayOffset(
}
}
async function getAssetByMonthOffset(timelineManager: TimelineManager, month: MonthGroup, direction: Direction) {
for (const targetMonth of timelineManager.monthGroupIterator({ startMonthGroup: month, direction })) {
async function getAssetByMonthOffset(timelineManager: TimelineManager, month: TimelineMonth, direction: Direction) {
for (const targetMonth of timelineManager.monthIterator({ startMonth: month, direction })) {
if (targetMonth.yearMonth.month !== month.yearMonth.month) {
const { value, done } = await timelineManager.assetsIterator({ startMonthGroup: targetMonth, direction }).next();
const { value, done } = await timelineManager.assetsIterator({ startMonth: targetMonth, direction }).next();
return done ? undefined : value;
}
}
}
async function getAssetByYearOffset(timelineManager: TimelineManager, month: MonthGroup, direction: Direction) {
for (const targetMonth of timelineManager.monthGroupIterator({ startMonthGroup: month, direction })) {
async function getAssetByYearOffset(timelineManager: TimelineManager, month: TimelineMonth, direction: Direction) {
for (const targetMonth of timelineManager.monthIterator({ startMonth: month, direction })) {
if (targetMonth.yearMonth.year !== month.yearMonth.year) {
const { value, done } = await timelineManager.assetsIterator({ startMonthGroup: targetMonth, direction }).next();
const { value, done } = await timelineManager.assetsIterator({ startMonth: targetMonth, direction }).next();
return done ? undefined : value;
}
}
}
export async function retrieveRange(timelineManager: TimelineManager, start: AssetDescriptor, end: AssetDescriptor) {
let { asset: startAsset, monthGroup: startMonthGroup } = findMonthGroupForAsset(timelineManager, start.id) ?? {};
if (!startMonthGroup || !startAsset) {
let { asset: startAsset, month: startMonth } = findMonthForAsset(timelineManager, start.id) ?? {};
if (!startMonth || !startAsset) {
return [];
}
let { asset: endAsset, monthGroup: endMonthGroup } = findMonthGroupForAsset(timelineManager, end.id) ?? {};
if (!endMonthGroup || !endAsset) {
let { asset: endAsset, month: endMonth } = findMonthForAsset(timelineManager, end.id) ?? {};
if (!endMonth || !endAsset) {
return [];
}
const assetOrder: AssetOrder = timelineManager.getAssetOrder();
if (plainDateTimeCompare(assetOrder === AssetOrder.Desc, startAsset.localDateTime, endAsset.localDateTime) < 0) {
[startAsset, endAsset] = [endAsset, startAsset];
[startMonthGroup, endMonthGroup] = [endMonthGroup, startMonthGroup];
[startMonth, endMonth] = [endMonth, startMonth];
}
const range: TimelineAsset[] = [];
const startDayGroup = startMonthGroup.findDayGroupForAsset(startAsset);
const startDay = startMonth.findDayForAsset(startAsset);
for await (const targetAsset of timelineManager.assetsIterator({
startMonthGroup,
startDayGroup,
startMonth,
startDay,
startAsset,
})) {
range.push(targetAsset);
@@ -136,7 +136,7 @@ export async function retrieveRange(timelineManager: TimelineManager, start: Ass
return range;
}
export function findMonthGroupForDate(timelineManager: TimelineManager, targetYearMonth: TimelineYearMonth) {
export function findMonthForDate(timelineManager: TimelineManager, targetYearMonth: TimelineYearMonth) {
for (const month of timelineManager.months) {
const { year, month: monthNum } = month.yearMonth;
if (monthNum === targetYearMonth.month && year === targetYearMonth.year) {
@@ -145,10 +145,10 @@ export function findMonthGroupForDate(timelineManager: TimelineManager, targetYe
}
}
export function findClosestGroupForDate(months: MonthGroup[], targetYearMonth: TimelineYearMonth) {
export function findClosestGroupForDate(months: TimelineMonth[], targetYearMonth: TimelineYearMonth) {
const targetDate = DateTime.fromObject({ year: targetYearMonth.year, month: targetYearMonth.month });
let closestMonth: MonthGroup | undefined;
let closestMonth: TimelineMonth | undefined;
let minDifference = Number.MAX_SAFE_INTEGER;
for (const month of months) {

View File

@@ -1,4 +1,4 @@
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import type { PendingChange, TimelineAsset } from '$lib/managers/timeline-manager/types';
import { websocketEvents } from '$lib/stores/websocket';
import { toTimelineAsset } from '$lib/utils/timeline-util';

View File

@@ -1,4 +1,4 @@
import type { TimelineAsset } from './types';
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
export const assetSnapshot = (asset: TimelineAsset): TimelineAsset => $state.snapshot(asset);
export const assetsSnapshot = (assets: TimelineAsset[]) => assets.map((asset) => $state.snapshot(asset));

View File

@@ -1,19 +1,18 @@
import { calculateViewerAssetIntersecting } from '$lib/managers/timeline-manager/internal/intersection-support.svelte';
import { TimelineDay } from '$lib/managers/timeline-manager/TimelineDay.svelte';
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
import type { CommonPosition } from '$lib/utils/layout-utils';
import type { DayGroup } from './day-group.svelte';
import { calculateViewerAssetIntersecting } from './internal/intersection-support.svelte';
import type { TimelineAsset } from './types';
export class ViewerAsset {
readonly #group: DayGroup;
readonly #day: TimelineDay;
intersecting = $derived.by(() => {
if (!this.position) {
return false;
}
const store = this.#group.monthGroup.timelineManager;
const positionTop = this.#group.absoluteDayGroupTop + this.position.top;
const store = this.#day.month.timelineManager;
const positionTop = this.#day.absoluteTop + this.position.top;
return calculateViewerAssetIntersecting(store, positionTop, this.position.height);
});
@@ -22,8 +21,8 @@ export class ViewerAsset {
asset: TimelineAsset = <TimelineAsset>$state();
id: string = $derived(this.asset.id);
constructor(group: DayGroup, asset: TimelineAsset) {
this.#group = group;
constructor(day: TimelineDay, asset: TimelineAsset) {
this.#day = day;
this.asset = asset;
}
}

View File

@@ -1,6 +1,6 @@
<script lang="ts">
import DateInput from '$lib/elements/DateInput.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
import { getPreferredTimeZone, getTimezones, toDatetime, type ZoneOption } from '$lib/modals/timezone-utils';
import { Button, HStack, Modal, ModalBody, ModalFooter, VStack } from '@immich/ui';

View File

@@ -1,5 +1,5 @@
import ToastAction from '$lib/components/ToastAction.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
import type { StackResponse } from '$lib/utils/asset-utils';
import { AssetVisibility, deleteAssets as deleteBulk, restoreAssets } from '@immich/sdk';

View File

@@ -3,7 +3,7 @@ import ToastAction from '$lib/components/ToastAction.svelte';
import { AppRoute } from '$lib/constants';
import { authManager } from '$lib/managers/auth-manager.svelte';
import { downloadManager } from '$lib/managers/download-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
import { assetsSnapshot } from '$lib/managers/timeline-manager/utils.svelte';
import type { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
@@ -490,17 +490,17 @@ export const selectAllAssets = async (timelineManager: TimelineManager, assetInt
isSelectingAllAssets.set(true);
try {
for (const monthGroup of timelineManager.months) {
await timelineManager.loadMonthGroup(monthGroup.yearMonth);
for (const month of timelineManager.months) {
await timelineManager.loadMonth(month.yearMonth);
if (!get(isSelectingAllAssets)) {
assetInteraction.clearMultiselect();
break; // Cancelled
}
assetInteraction.selectAssets(assetsSnapshot([...monthGroup.assetsIterator()]));
assetInteraction.selectAssets(assetsSnapshot([...month.assetsIterator()]));
for (const dateGroup of monthGroup.dayGroups) {
assetInteraction.addGroupToMultiselectGroup(dateGroup.groupTitle);
for (const dateGroup of month.days) {
assetInteraction.addGroupToMultiselectGroup(dateGroup.dayTitle);
}
}
} catch (error) {

View File

@@ -1,9 +1,9 @@
import { locale } from '$lib/stores/preferences.store';
import { parseUtcDate } from '$lib/utils/date-time';
import { formatGroupTitle, toISOYearMonthUTC } from '$lib/utils/timeline-util';
import { formatDayTitle, toISOYearMonthUTC } from '$lib/utils/timeline-util';
import { DateTime } from 'luxon';
describe('formatGroupTitle', () => {
describe('formatDayTitle', () => {
beforeAll(() => {
vi.useFakeTimers();
process.env.TZ = 'UTC';
@@ -18,63 +18,63 @@ describe('formatGroupTitle', () => {
it('formats today', () => {
const date = parseUtcDate('2024-07-27T01:00:00Z');
locale.set('en');
expect(formatGroupTitle(date)).toBe('today');
expect(formatDayTitle(date)).toBe('today');
locale.set('es');
expect(formatGroupTitle(date)).toBe('hoy');
expect(formatDayTitle(date)).toBe('hoy');
});
it('formats yesterday', () => {
const date = parseUtcDate('2024-07-26T23:59:59Z');
locale.set('en');
expect(formatGroupTitle(date)).toBe('yesterday');
expect(formatDayTitle(date)).toBe('yesterday');
locale.set('fr');
expect(formatGroupTitle(date)).toBe('hier');
expect(formatDayTitle(date)).toBe('hier');
});
it('formats last week', () => {
const date = parseUtcDate('2024-07-21T00:00:00Z');
locale.set('en');
expect(formatGroupTitle(date)).toBe('Sunday');
expect(formatDayTitle(date)).toBe('Sunday');
locale.set('ar-SA');
expect(formatGroupTitle(date)).toBe('الأحد');
expect(formatDayTitle(date)).toBe('الأحد');
});
it('formats date 7 days ago', () => {
const date = parseUtcDate('2024-07-20T00:00:00Z');
locale.set('en');
expect(formatGroupTitle(date)).toBe('Sat, Jul 20');
expect(formatDayTitle(date)).toBe('Sat, Jul 20');
locale.set('de');
expect(formatGroupTitle(date)).toBe('Sa., 20. Juli');
expect(formatDayTitle(date)).toBe('Sa., 20. Juli');
});
it('formats date this year', () => {
const date = parseUtcDate('2020-01-01T00:00:00Z');
locale.set('en');
expect(formatGroupTitle(date)).toBe('Wed, Jan 1, 2020');
expect(formatDayTitle(date)).toBe('Wed, Jan 1, 2020');
locale.set('ja');
expect(formatGroupTitle(date)).toBe('2020年1月1日(水)');
expect(formatDayTitle(date)).toBe('2020年1月1日(水)');
});
it('formats future date', () => {
const tomorrow = parseUtcDate('2024-07-28T00:00:00Z');
locale.set('en');
expect(formatGroupTitle(tomorrow)).toBe('Sun, Jul 28');
expect(formatDayTitle(tomorrow)).toBe('Sun, Jul 28');
const nextMonth = parseUtcDate('2024-08-28T00:00:00Z');
locale.set('en');
expect(formatGroupTitle(nextMonth)).toBe('Wed, Aug 28');
expect(formatDayTitle(nextMonth)).toBe('Wed, Aug 28');
const nextYear = parseUtcDate('2025-01-10T12:00:00Z');
locale.set('en');
expect(formatGroupTitle(nextYear)).toBe('Fri, Jan 10, 2025');
expect(formatDayTitle(nextYear)).toBe('Fri, Jan 10, 2025');
});
it('returns "Invalid DateTime" when date is invalid', () => {
const date = DateTime.invalid('test');
locale.set('en');
expect(formatGroupTitle(date)).toBe('Invalid DateTime');
expect(formatDayTitle(date)).toBe('Invalid DateTime');
locale.set('es');
expect(formatGroupTitle(date)).toBe('Invalid DateTime');
expect(formatDayTitle(date)).toBe('Invalid DateTime');
});
});

View File

@@ -99,7 +99,7 @@ export const toISOYearMonthUTC = ({ year, month }: TimelineYearMonth): string =>
return `${yearFull}-${monthFull}-01T00:00:00.000Z`;
};
export function formatMonthGroupTitle(_date: DateTime): string {
export function formatMonthTitle(_date: DateTime): string {
if (!_date.isValid) {
return _date.toString();
}
@@ -113,7 +113,7 @@ export function formatMonthGroupTitle(_date: DateTime): string {
);
}
export function formatGroupTitle(_date: DateTime): string {
export function formatDayTitle(_date: DateTime): string {
if (!_date.isValid) {
return _date.toString();
}

View File

@@ -29,7 +29,7 @@
import Timeline from '$lib/components/timeline/Timeline.svelte';
import { AlbumPageViewMode, AppRoute } from '$lib/constants';
import { activityManager } from '$lib/managers/activity-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
import AlbumOptionsModal from '$lib/modals/AlbumOptionsModal.svelte';
import AlbumShareModal from '$lib/modals/AlbumShareModal.svelte';
@@ -141,7 +141,7 @@
const asset =
$slideshowNavigation === SlideshowNavigation.Shuffle
? await timelineManager.getRandomAsset()
: timelineManager.months[0]?.dayGroups[0]?.viewerAssets[0]?.asset;
: timelineManager.months[0]?.days[0]?.viewerAssets[0]?.asset;
if (asset) {
handlePromiseError(setAssetId(asset.id).then(() => ($slideshowState = SlideshowState.PlaySlideshow)));
}

View File

@@ -14,7 +14,7 @@
import { AssetAction } from '$lib/constants';
import SetVisibilityAction from '$lib/components/timeline/actions/SetVisibilityAction.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
import { AssetVisibility } from '@immich/sdk';
import { mdiDotsVertical, mdiPlus } from '@mdi/js';

View File

@@ -17,7 +17,7 @@
import AssetSelectControlBar from '$lib/components/timeline/AssetSelectControlBar.svelte';
import Timeline from '$lib/components/timeline/Timeline.svelte';
import { AssetAction } from '$lib/constants';
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
import { preferences } from '$lib/stores/user.store';
import { mdiDotsVertical, mdiPlus } from '@mdi/js';

View File

@@ -12,7 +12,7 @@
import AssetSelectControlBar from '$lib/components/timeline/AssetSelectControlBar.svelte';
import Timeline from '$lib/components/timeline/Timeline.svelte';
import { AppRoute, AssetAction } from '$lib/constants';
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
import { AssetVisibility, lockAuthSession } from '@immich/sdk';
import { Button } from '@immich/ui';

View File

@@ -26,7 +26,7 @@
import AssetSelectControlBar from '$lib/components/timeline/AssetSelectControlBar.svelte';
import Timeline from '$lib/components/timeline/Timeline.svelte';
import { AppRoute, PersonPageViewMode, QueryParameter, SessionStorageKey } from '$lib/constants';
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
import PersonEditBirthDateModal from '$lib/modals/PersonEditBirthDateModal.svelte';
import PersonMergeSuggestionModal from '$lib/modals/PersonMergeSuggestionModal.svelte';

View File

@@ -22,7 +22,7 @@
import AssetSelectControlBar from '$lib/components/timeline/AssetSelectControlBar.svelte';
import Timeline from '$lib/components/timeline/Timeline.svelte';
import { AssetAction } from '$lib/constants';
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
import { isFaceEditMode } from '$lib/stores/face-edit.svelte';

View File

@@ -8,7 +8,7 @@
import Timeline from '$lib/components/timeline/Timeline.svelte';
import { AppRoute, AssetAction, QueryParameter } from '$lib/constants';
import SkipLink from '$lib/elements/SkipLink.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import TagCreateModal from '$lib/modals/TagCreateModal.svelte';
import TagEditModal from '$lib/modals/TagEditModal.svelte';
import { AssetInteraction } from '$lib/stores/asset-interaction.svelte';

View File

@@ -9,7 +9,7 @@
import AssetSelectControlBar from '$lib/components/timeline/AssetSelectControlBar.svelte';
import Timeline from '$lib/components/timeline/Timeline.svelte';
import { AppRoute } from '$lib/constants';
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
import { featureFlags, serverConfig } from '$lib/stores/server-config.store';
import { handlePromiseError } from '$lib/utils';

View File

@@ -5,8 +5,8 @@
import Timeline from '$lib/components/timeline/Timeline.svelte';
import { AssetAction } from '$lib/constants';
import { authManager } from '$lib/managers/auth-manager.svelte';
import type { DayGroup } from '$lib/managers/timeline-manager/day-group.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/timeline-manager.svelte';
import { TimelineDay } from '$lib/managers/timeline-manager/TimelineDay.svelte';
import { TimelineManager } from '$lib/managers/timeline-manager/TimelineManager.svelte';
import type { TimelineAsset } from '$lib/managers/timeline-manager/types';
import GeolocationUpdateConfirmModal from '$lib/modals/GeolocationUpdateConfirmModal.svelte';
import { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
@@ -113,11 +113,11 @@
const handleThumbnailClick = (
asset: TimelineAsset,
timelineManager: TimelineManager,
dayGroup: DayGroup,
day: TimelineDay,
onClick: (
timelineManager: TimelineManager,
assets: TimelineAsset[],
groupTitle: string,
dayTitle: string,
asset: TimelineAsset,
) => void,
) => {
@@ -129,7 +129,7 @@
location = { latitude: asset.latitude!, longitude: asset.longitude! };
void setQueryValue('at', asset.id);
} else {
onClick(timelineManager, dayGroup.getAssets(), dayGroup.groupTitle, asset);
onClick(timelineManager, day.getAssets(), day.dayTitle, asset);
}
};
</script>