@ -16,7 +16,7 @@
import { archiveAssets , cancelMultiselect } from '$lib/utils/asset-utils';
import { archiveAssets , cancelMultiselect } from '$lib/utils/asset-utils';
import { moveFocus } from '$lib/utils/focus-util';
import { moveFocus } from '$lib/utils/focus-util';
import { handleError } from '$lib/utils/handle-error';
import { handleError } from '$lib/utils/handle-error';
import { getJustifiedLayoutFromAssets , type CommonJustifiedLayout } from '$lib/utils/layout-utils';
import { getJustifiedLayoutFromAssets } from '$lib/utils/layout-utils';
import { navigate } from '$lib/utils/navigation';
import { navigate } from '$lib/utils/navigation';
import { isTimelineAsset , toTimelineAsset } from '$lib/utils/timeline-util';
import { isTimelineAsset , toTimelineAsset } from '$lib/utils/timeline-util';
import { AssetVisibility , type AssetResponseDto } from '@immich/sdk';
import { AssetVisibility , type AssetResponseDto } from '@immich/sdk';
@ -28,7 +28,7 @@
interface Props {
interface Props {
initialAssetId?: string;
initialAssetId?: string;
assets: ( TimelineAsset | AssetResponseDto) [];
assets: TimelineAsset[] | AssetResponseDto[];
assetInteraction: AssetInteraction;
assetInteraction: AssetInteraction;
disableAssetSelect?: boolean;
disableAssetSelect?: boolean;
showArchiveIcon?: boolean;
showArchiveIcon?: boolean;
@ -66,60 +66,26 @@
let { isViewing : isViewerOpen , asset : viewingAsset , setAssetId } = assetViewingStore;
let { isViewing : isViewerOpen , asset : viewingAsset , setAssetId } = assetViewingStore;
let geometry: CommonJustifiedLayout | undefined = $state();
const geometry = $derived(
getJustifiedLayoutFromAssets(assets, {
$effect(() => {
const _assets = assets;
updateSlidingWindow();
const rowWidth = Math.floor(viewport.width);
const rowHeight = rowWidth < 850 ? 100 : 235 ;
geometry = getJustifiedLayoutFromAssets(_assets, {
spacing: 2,
spacing: 2,
heightTolerance: 0.1 5,
heightTolerance: 0.5,
rowHeight,
rowHeight: Math.floor(viewport.width) < 850 ? 100 : 235 ,
rowWidth,
rowWidth: Math.floor(viewport.width),
});
}),
} );
);
let assetLayouts = $derived.by(() => {
const getStyle = (i: number) => {
const assetLayout = [];
const geo = geometry;
let containerHeight = 0;
return `top: ${ geo . getTop ( i )} px; left: ${ geo . getLeft ( i )} px; width: ${ geo . getWidth ( i )} px; height: ${ geo . getHeight ( i )} px;`;
let containerWidth = 0;
};
if (geometry) {
containerHeight = geometry.containerHeight;
containerWidth = geometry.containerWidth;
for (const [index, asset] of assets.entries()) {
const top = geometry.getTop(index);
const left = geometry.getLeft(index);
const width = geometry.getWidth(index);
const height = geometry.getHeight(index);
const layoutTopWithOffset = top + pageHeaderOffset;
const layoutBottom = layoutTopWithOffset + height;
const display = layoutTopWithOffset < slidingWindow.bottom & & layoutBottom > slidingWindow.top;
const layout = {
asset,
top,
left,
width,
height,
display,
};
assetLayout.push(layout);
}
}
return {
const isIntersecting = (i: number) => {
assetLayout,
const geo = geometry;
containerHeight,
const window = slidingWindow;
containerWidth,
const top = geo.getTop(i);
} ;
return top + pageHeaderOffset < window.bottom & & top + geo . getHeight ( i ) > window.top;
}) ;
};
let currentIndex = 0;
let currentIndex = 0;
if (initialAssetId && assets.length > 0) {
if (initialAssetId && assets.length > 0) {
@ -148,9 +114,9 @@
let lastIntersectedHeight = 0;
let lastIntersectedHeight = 0;
$effect(() => {
$effect(() => {
// Intersect if there's only one viewport worth of assets left to scroll.
// Intersect if there's only one viewport worth of assets left to scroll.
if (assetLayouts .containerHeight - slidingWindow.bottom < = viewport.height) {
if (geometry .containerHeight - slidingWindow.bottom < = viewport.height) {
// Notify we got to (near) the end of scroll.
// Notify we got to (near) the end of scroll.
const intersectedHeight = assetLayouts .containerHeight;
const intersectedHeight = geometry .containerHeight;
if (lastIntersectedHeight !== intersectedHeight) {
if (lastIntersectedHeight !== intersectedHeight) {
debouncedOnIntersected();
debouncedOnIntersected();
lastIntersectedHeight = intersectedHeight;
lastIntersectedHeight = intersectedHeight;
@ -264,7 +230,7 @@
isShowDeleteConfirmation = false;
isShowDeleteConfirmation = false;
await deleteAssets(
await deleteAssets(
!(isTrashEnabled & & !force),
!(isTrashEnabled & & !force),
(assetIds) => (assets = assets.filter((asset) => !assetIds.includes(asset.id))),
(assetIds) => (assets = assets.filter((asset) => !assetIds.includes(asset.id)) as TimelineAsset[] ),
assetInteraction.selectedAssets,
assetInteraction.selectedAssets,
onReload,
onReload,
);
);
@ -277,7 +243,7 @@
assetInteraction.isAllArchived ? AssetVisibility.Timeline : AssetVisibility.Archive,
assetInteraction.isAllArchived ? AssetVisibility.Timeline : AssetVisibility.Archive,
);
);
if (ids) {
if (ids) {
assets = assets.filter((asset) => !ids.includes(asset.id));
assets = assets.filter((asset) => !ids.includes(asset.id)) as TimelineAsset[] ;
deselectAllAssets();
deselectAllAssets();
}
}
};
};
@ -480,41 +446,36 @@
{ #if assets . length > 0 }
{ #if assets . length > 0 }
< div
< div
style:position="relative"
style:position="relative"
style:height={ assetLayouts . containerHeight + 'px' }
style:height={ geometry . containerHeight + 'px' }
style:width={ assetLayouts. containerWidth - 1 + 'px' }
style:width={ geometry. containerWidth + 'px' }
>
>
{ #each assetLayouts . assetLayout as layout , layoutIndex ( layout . asset . id + '-' + layoutIndex )}
{ #each assets as asset , i ( asset . id + '-' + i )}
{ @const currentAsset = layout . asset }
{ #if isIntersecting ( i )}
{ @const currentAsset = toTimelineAsset ( asset )}
{ #if layout . display }
< div class = "absolute" style:overflow = "clip" style = { getStyle ( i )} >
< div
class="absolute"
style:overflow="clip"
style="width: { layout . width } px; height: { layout . height } px; top: { layout . top } px; left: { layout . left } px"
>
< Thumbnail
< Thumbnail
readonly={ disableAssetSelect }
readonly={ disableAssetSelect }
onClick={() => {
onClick={() => {
if (assetInteraction.selectionActive) {
if (assetInteraction.selectionActive) {
handleSelectAssets(toTimelineAsset( currentAsset) );
handleSelectAssets(currentAsset);
return;
return;
}
}
void viewAssetHandler(toTimelineAsset( currentAsset) );
void viewAssetHandler(currentAsset);
}}
}}
onSelect={() => handleSelectAssets ( toTimelineAsset( currentAsset) )}
onSelect={() => handleSelectAssets ( currentAsset )}
onMouseEvent={() => assetMouseEventHandler ( toTimelineAsset( currentAsset) )}
onMouseEvent={() => assetMouseEventHandler ( currentAsset )}
{ showArchiveIcon }
{ showArchiveIcon }
asset={ toTimelineAsset( currentAsset) }
asset={ currentAsset }
selected={ assetInteraction . hasSelectedAsset ( currentAsset . id )}
selected={ assetInteraction . hasSelectedAsset ( currentAsset . id )}
selectionCandidate={ assetInteraction . hasSelectionCandidate ( currentAsset . id )}
selectionCandidate={ assetInteraction . hasSelectionCandidate ( currentAsset . id )}
thumbnailWidth={ layout. width }
thumbnailWidth={ geometry. getWidth ( i ) }
thumbnailHeight={ layout. height }
thumbnailHeight={ geometry. getHeight ( i ) }
/>
/>
{ #if showAssetName && ! isTimelineAsset ( currentA sset)}
{ #if showAssetName && ! isTimelineAsset ( a sset)}
< div
< div
class="absolute text-center p-1 text-xs font-mono font-semibold w-full bottom-0 bg-linear-to-t bg-slate-50/75 dark:bg-slate-800/75 overflow-clip text-ellipsis whitespace-pre-wrap"
class="absolute text-center p-1 text-xs font-mono font-semibold w-full bottom-0 bg-linear-to-t bg-slate-50/75 dark:bg-slate-800/75 overflow-clip text-ellipsis whitespace-pre-wrap"
>
>
{ currentA sset. originalFileName }
{ a sset. originalFileName }
< / div >
< / div >
{ /if }
{ /if }
< / div >
< / div >