2023-01-14 23:49:47 -06:00
|
|
|
<script lang="ts">
|
2024-07-31 18:25:38 +02:00
|
|
|
import { goto } from '$app/navigation';
|
|
|
|
import type { Action } from '$lib/components/asset-viewer/actions/action';
|
2023-07-01 00:50:47 -04:00
|
|
|
import Thumbnail from '$lib/components/assets/thumbnail/thumbnail.svelte';
|
2024-07-31 18:25:38 +02:00
|
|
|
import { AppRoute, AssetAction } from '$lib/constants';
|
2023-08-01 04:27:56 +03:00
|
|
|
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
|
feat(web): Scroll to asset in gridview; increase gridview perf; reduce memory; scrollbar ticks in fixed position (#10646)
* Squashed
* Change strategy - now pre-measure buckets offscreen, so don't need to worry about sub-bucket scroll preservation
* Reduce jank on scroll, delay DOM updates until after scroll
* css opt, log measure time
* Trickle out queue while scrolling, flush when stopped
* yay
* Cleanup cleanup...
* everybody...
* everywhere...
* Clean up cleanup!
* Everybody do their share
* CLEANUP!
* package-lock ?
* dynamic measure, todo
* Fix web test
* type lint
* fix e2e
* e2e test
* Better scrollbar
* Tuning, and more tunables
* Tunable tweaks, more tunables
* Scrollbar dots and viewport events
* lint
* Tweaked tunnables, use requestIdleCallback for garbage tasks, bug fixes
* New tunables, and don't update url by default
* Bug fixes
* Bug fix, with debug
* Fix flickr, fix graybox bug, reduced debug
* Refactor/cleanup
* Fix
* naming
* Final cleanup
* review comment
* Forgot to update this after naming change
* scrubber works, with debug
* cleanup
* Rename scrollbar to scrubber
* rename to
* left over rename and change to previous album bar
* bugfix addassets, comments
* missing destroy(), cleanup
---------
Co-authored-by: Alex <alex.tran1502@gmail.com>
2024-08-21 22:15:21 -04:00
|
|
|
import type { Viewport } from '$lib/stores/assets.store';
|
2024-07-31 18:25:38 +02:00
|
|
|
import { getAssetRatio } from '$lib/utils/asset-utils';
|
2024-02-14 06:38:57 -08:00
|
|
|
import { handleError } from '$lib/utils/handle-error';
|
2024-07-31 18:25:38 +02:00
|
|
|
import { navigate } from '$lib/utils/navigation';
|
|
|
|
import { calculateWidth } from '$lib/utils/timeline-util';
|
2024-02-17 11:00:55 -06:00
|
|
|
import { type AssetResponseDto } from '@immich/sdk';
|
|
|
|
import justifiedLayout from 'justified-layout';
|
feat(web): Scroll to asset in gridview; increase gridview perf; reduce memory; scrollbar ticks in fixed position (#10646)
* Squashed
* Change strategy - now pre-measure buckets offscreen, so don't need to worry about sub-bucket scroll preservation
* Reduce jank on scroll, delay DOM updates until after scroll
* css opt, log measure time
* Trickle out queue while scrolling, flush when stopped
* yay
* Cleanup cleanup...
* everybody...
* everywhere...
* Clean up cleanup!
* Everybody do their share
* CLEANUP!
* package-lock ?
* dynamic measure, todo
* Fix web test
* type lint
* fix e2e
* e2e test
* Better scrollbar
* Tuning, and more tunables
* Tunable tweaks, more tunables
* Scrollbar dots and viewport events
* lint
* Tweaked tunnables, use requestIdleCallback for garbage tasks, bug fixes
* New tunables, and don't update url by default
* Bug fixes
* Bug fix, with debug
* Fix flickr, fix graybox bug, reduced debug
* Refactor/cleanup
* Fix
* naming
* Final cleanup
* review comment
* Forgot to update this after naming change
* scrubber works, with debug
* cleanup
* Rename scrollbar to scrubber
* rename to
* left over rename and change to previous album bar
* bugfix addassets, comments
* missing destroy(), cleanup
---------
Co-authored-by: Alex <alex.tran1502@gmail.com>
2024-08-21 22:15:21 -04:00
|
|
|
import { onDestroy } from 'svelte';
|
2024-06-24 15:50:01 +02:00
|
|
|
import { t } from 'svelte-i18n';
|
2024-07-31 18:25:38 +02:00
|
|
|
import AssetViewer from '../../asset-viewer/asset-viewer.svelte';
|
|
|
|
import Portal from '../portal/portal.svelte';
|
feat(web): Scroll to asset in gridview; increase gridview perf; reduce memory; scrollbar ticks in fixed position (#10646)
* Squashed
* Change strategy - now pre-measure buckets offscreen, so don't need to worry about sub-bucket scroll preservation
* Reduce jank on scroll, delay DOM updates until after scroll
* css opt, log measure time
* Trickle out queue while scrolling, flush when stopped
* yay
* Cleanup cleanup...
* everybody...
* everywhere...
* Clean up cleanup!
* Everybody do their share
* CLEANUP!
* package-lock ?
* dynamic measure, todo
* Fix web test
* type lint
* fix e2e
* e2e test
* Better scrollbar
* Tuning, and more tunables
* Tunable tweaks, more tunables
* Scrollbar dots and viewport events
* lint
* Tweaked tunnables, use requestIdleCallback for garbage tasks, bug fixes
* New tunables, and don't update url by default
* Bug fixes
* Bug fix, with debug
* Fix flickr, fix graybox bug, reduced debug
* Refactor/cleanup
* Fix
* naming
* Final cleanup
* review comment
* Forgot to update this after naming change
* scrubber works, with debug
* cleanup
* Rename scrollbar to scrubber
* rename to
* left over rename and change to previous album bar
* bugfix addassets, comments
* missing destroy(), cleanup
---------
Co-authored-by: Alex <alex.tran1502@gmail.com>
2024-08-21 22:15:21 -04:00
|
|
|
import { handlePromiseError } from '$lib/utils';
|
2023-07-01 00:50:47 -04:00
|
|
|
|
|
|
|
export let assets: AssetResponseDto[];
|
|
|
|
export let selectedAssets: Set<AssetResponseDto> = new Set();
|
|
|
|
export let disableAssetSelect = false;
|
|
|
|
export let showArchiveIcon = false;
|
2024-02-17 11:00:55 -06:00
|
|
|
export let viewport: Viewport;
|
feat(web): Scroll to asset in gridview; increase gridview perf; reduce memory; scrollbar ticks in fixed position (#10646)
* Squashed
* Change strategy - now pre-measure buckets offscreen, so don't need to worry about sub-bucket scroll preservation
* Reduce jank on scroll, delay DOM updates until after scroll
* css opt, log measure time
* Trickle out queue while scrolling, flush when stopped
* yay
* Cleanup cleanup...
* everybody...
* everywhere...
* Clean up cleanup!
* Everybody do their share
* CLEANUP!
* package-lock ?
* dynamic measure, todo
* Fix web test
* type lint
* fix e2e
* e2e test
* Better scrollbar
* Tuning, and more tunables
* Tunable tweaks, more tunables
* Scrollbar dots and viewport events
* lint
* Tweaked tunnables, use requestIdleCallback for garbage tasks, bug fixes
* New tunables, and don't update url by default
* Bug fixes
* Bug fix, with debug
* Fix flickr, fix graybox bug, reduced debug
* Refactor/cleanup
* Fix
* naming
* Final cleanup
* review comment
* Forgot to update this after naming change
* scrubber works, with debug
* cleanup
* Rename scrollbar to scrubber
* rename to
* left over rename and change to previous album bar
* bugfix addassets, comments
* missing destroy(), cleanup
---------
Co-authored-by: Alex <alex.tran1502@gmail.com>
2024-08-21 22:15:21 -04:00
|
|
|
export let onIntersected: (() => void) | undefined = undefined;
|
2024-08-21 19:49:37 +01:00
|
|
|
export let showAssetName = false;
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2024-05-02 04:17:40 +08:00
|
|
|
let { isViewing: isViewerOpen, asset: viewingAsset, setAsset } = assetViewingStore;
|
2023-08-01 04:27:56 +03:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
let currentViewAssetIndex = 0;
|
|
|
|
$: isMultiSelectionMode = selectedAssets.size > 0;
|
|
|
|
|
2024-04-24 15:24:19 -04:00
|
|
|
const viewAssetHandler = async (asset: AssetResponseDto) => {
|
2023-07-01 00:50:47 -04:00
|
|
|
currentViewAssetIndex = assets.findIndex((a) => a.id == asset.id);
|
2024-04-24 15:24:19 -04:00
|
|
|
setAsset(assets[currentViewAssetIndex]);
|
|
|
|
await navigate({ targetRoute: 'current', assetId: $viewingAsset.id });
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
|
|
|
|
2024-03-15 17:01:35 +01:00
|
|
|
const selectAssetHandler = (asset: AssetResponseDto) => {
|
2024-02-02 04:18:00 +01:00
|
|
|
let temporary = new Set(selectedAssets);
|
2023-07-01 00:50:47 -04:00
|
|
|
|
|
|
|
if (selectedAssets.has(asset)) {
|
2024-02-02 04:18:00 +01:00
|
|
|
temporary.delete(asset);
|
2023-07-01 00:50:47 -04:00
|
|
|
} else {
|
2024-02-02 04:18:00 +01:00
|
|
|
temporary.add(asset);
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
|
|
|
|
2024-02-02 04:18:00 +01:00
|
|
|
selectedAssets = temporary;
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
|
|
|
|
2024-05-02 04:17:40 +08:00
|
|
|
const handleNext = async () => {
|
2023-07-01 00:50:47 -04:00
|
|
|
try {
|
|
|
|
if (currentViewAssetIndex < assets.length - 1) {
|
2024-04-24 15:24:19 -04:00
|
|
|
setAsset(assets[++currentViewAssetIndex]);
|
|
|
|
await navigate({ targetRoute: 'current', assetId: $viewingAsset.id });
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
2024-02-02 04:18:00 +01:00
|
|
|
} catch (error) {
|
2024-06-24 15:50:01 +02:00
|
|
|
handleError(error, $t('errors.cannot_navigate_next_asset'));
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-05-02 04:17:40 +08:00
|
|
|
const handlePrevious = async () => {
|
2023-07-01 00:50:47 -04:00
|
|
|
try {
|
|
|
|
if (currentViewAssetIndex > 0) {
|
2024-04-24 15:24:19 -04:00
|
|
|
setAsset(assets[--currentViewAssetIndex]);
|
|
|
|
await navigate({ targetRoute: 'current', assetId: $viewingAsset.id });
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
2024-02-02 04:18:00 +01:00
|
|
|
} catch (error) {
|
2024-06-24 15:50:01 +02:00
|
|
|
handleError(error, $t('errors.cannot_navigate_previous_asset'));
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-07-31 18:25:38 +02:00
|
|
|
const handleAction = async (action: Action) => {
|
|
|
|
switch (action.type) {
|
2024-05-02 04:17:40 +08:00
|
|
|
case AssetAction.ARCHIVE:
|
|
|
|
case AssetAction.DELETE:
|
|
|
|
case AssetAction.TRASH: {
|
|
|
|
assets.splice(
|
2024-07-31 18:25:38 +02:00
|
|
|
assets.findIndex((a) => a.id === action.asset.id),
|
2024-05-02 04:17:40 +08:00
|
|
|
1,
|
|
|
|
);
|
|
|
|
assets = assets;
|
|
|
|
if (assets.length === 0) {
|
|
|
|
await goto(AppRoute.PHOTOS);
|
|
|
|
} else if (currentViewAssetIndex === assets.length) {
|
|
|
|
await handlePrevious();
|
|
|
|
} else {
|
|
|
|
setAsset(assets[currentViewAssetIndex]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-11-22 10:54:58 -05:00
|
|
|
onDestroy(() => {
|
2024-05-02 04:17:40 +08:00
|
|
|
$isViewerOpen = false;
|
2023-11-22 10:54:58 -05:00
|
|
|
});
|
2024-02-17 11:00:55 -06:00
|
|
|
|
|
|
|
$: geometry = (() => {
|
|
|
|
const justifiedLayoutResult = justifiedLayout(
|
|
|
|
assets.map((asset) => getAssetRatio(asset)),
|
|
|
|
{
|
|
|
|
boxSpacing: 2,
|
|
|
|
containerWidth: Math.floor(viewport.width),
|
|
|
|
containerPadding: 0,
|
|
|
|
targetRowHeightTolerance: 0.15,
|
|
|
|
targetRowHeight: 235,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
...justifiedLayoutResult,
|
|
|
|
containerWidth: calculateWidth(justifiedLayoutResult.boxes),
|
|
|
|
};
|
|
|
|
})();
|
2023-01-14 23:49:47 -06:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if assets.length > 0}
|
2024-02-17 11:00:55 -06:00
|
|
|
<div class="relative" style="height: {geometry.containerHeight}px;width: {geometry.containerWidth}px ">
|
|
|
|
{#each assets as asset, i (i)}
|
|
|
|
<div
|
|
|
|
class="absolute"
|
|
|
|
style="width: {geometry.boxes[i].width}px; height: {geometry.boxes[i].height}px; top: {geometry.boxes[i]
|
|
|
|
.top}px; left: {geometry.boxes[i].left}px"
|
2024-08-21 19:49:37 +01:00
|
|
|
title={showAssetName ? asset.originalFileName : ''}
|
2024-02-17 11:00:55 -06:00
|
|
|
>
|
2023-07-01 00:50:47 -04:00
|
|
|
<Thumbnail
|
|
|
|
{asset}
|
|
|
|
readonly={disableAssetSelect}
|
feat(web): Scroll to asset in gridview; increase gridview perf; reduce memory; scrollbar ticks in fixed position (#10646)
* Squashed
* Change strategy - now pre-measure buckets offscreen, so don't need to worry about sub-bucket scroll preservation
* Reduce jank on scroll, delay DOM updates until after scroll
* css opt, log measure time
* Trickle out queue while scrolling, flush when stopped
* yay
* Cleanup cleanup...
* everybody...
* everywhere...
* Clean up cleanup!
* Everybody do their share
* CLEANUP!
* package-lock ?
* dynamic measure, todo
* Fix web test
* type lint
* fix e2e
* e2e test
* Better scrollbar
* Tuning, and more tunables
* Tunable tweaks, more tunables
* Scrollbar dots and viewport events
* lint
* Tweaked tunnables, use requestIdleCallback for garbage tasks, bug fixes
* New tunables, and don't update url by default
* Bug fixes
* Bug fix, with debug
* Fix flickr, fix graybox bug, reduced debug
* Refactor/cleanup
* Fix
* naming
* Final cleanup
* review comment
* Forgot to update this after naming change
* scrubber works, with debug
* cleanup
* Rename scrollbar to scrubber
* rename to
* left over rename and change to previous album bar
* bugfix addassets, comments
* missing destroy(), cleanup
---------
Co-authored-by: Alex <alex.tran1502@gmail.com>
2024-08-21 22:15:21 -04:00
|
|
|
onClick={(asset) => {
|
2024-06-11 17:27:18 +02:00
|
|
|
if (isMultiSelectionMode) {
|
|
|
|
selectAssetHandler(asset);
|
|
|
|
return;
|
|
|
|
}
|
feat(web): Scroll to asset in gridview; increase gridview perf; reduce memory; scrollbar ticks in fixed position (#10646)
* Squashed
* Change strategy - now pre-measure buckets offscreen, so don't need to worry about sub-bucket scroll preservation
* Reduce jank on scroll, delay DOM updates until after scroll
* css opt, log measure time
* Trickle out queue while scrolling, flush when stopped
* yay
* Cleanup cleanup...
* everybody...
* everywhere...
* Clean up cleanup!
* Everybody do their share
* CLEANUP!
* package-lock ?
* dynamic measure, todo
* Fix web test
* type lint
* fix e2e
* e2e test
* Better scrollbar
* Tuning, and more tunables
* Tunable tweaks, more tunables
* Scrollbar dots and viewport events
* lint
* Tweaked tunnables, use requestIdleCallback for garbage tasks, bug fixes
* New tunables, and don't update url by default
* Bug fixes
* Bug fix, with debug
* Fix flickr, fix graybox bug, reduced debug
* Refactor/cleanup
* Fix
* naming
* Final cleanup
* review comment
* Forgot to update this after naming change
* scrubber works, with debug
* cleanup
* Rename scrollbar to scrubber
* rename to
* left over rename and change to previous album bar
* bugfix addassets, comments
* missing destroy(), cleanup
---------
Co-authored-by: Alex <alex.tran1502@gmail.com>
2024-08-21 22:15:21 -04:00
|
|
|
void viewAssetHandler(asset);
|
2024-06-11 17:27:18 +02:00
|
|
|
}}
|
feat(web): Scroll to asset in gridview; increase gridview perf; reduce memory; scrollbar ticks in fixed position (#10646)
* Squashed
* Change strategy - now pre-measure buckets offscreen, so don't need to worry about sub-bucket scroll preservation
* Reduce jank on scroll, delay DOM updates until after scroll
* css opt, log measure time
* Trickle out queue while scrolling, flush when stopped
* yay
* Cleanup cleanup...
* everybody...
* everywhere...
* Clean up cleanup!
* Everybody do their share
* CLEANUP!
* package-lock ?
* dynamic measure, todo
* Fix web test
* type lint
* fix e2e
* e2e test
* Better scrollbar
* Tuning, and more tunables
* Tunable tweaks, more tunables
* Scrollbar dots and viewport events
* lint
* Tweaked tunnables, use requestIdleCallback for garbage tasks, bug fixes
* New tunables, and don't update url by default
* Bug fixes
* Bug fix, with debug
* Fix flickr, fix graybox bug, reduced debug
* Refactor/cleanup
* Fix
* naming
* Final cleanup
* review comment
* Forgot to update this after naming change
* scrubber works, with debug
* cleanup
* Rename scrollbar to scrubber
* rename to
* left over rename and change to previous album bar
* bugfix addassets, comments
* missing destroy(), cleanup
---------
Co-authored-by: Alex <alex.tran1502@gmail.com>
2024-08-21 22:15:21 -04:00
|
|
|
onSelect={(asset) => selectAssetHandler(asset)}
|
|
|
|
onIntersected={() => (i === Math.max(1, assets.length - 7) ? onIntersected?.() : void 0)}
|
2023-07-01 00:50:47 -04:00
|
|
|
selected={selectedAssets.has(asset)}
|
|
|
|
{showArchiveIcon}
|
2024-02-17 11:00:55 -06:00
|
|
|
thumbnailWidth={geometry.boxes[i].width}
|
|
|
|
thumbnailHeight={geometry.boxes[i].height}
|
2023-07-01 00:50:47 -04:00
|
|
|
/>
|
2024-08-21 19:49:37 +01:00
|
|
|
{#if showAssetName}
|
|
|
|
<div
|
|
|
|
class="absolute text-center p-1 text-xs font-mono font-semibold w-full bottom-0 bg-gradient-to-t bg-slate-50/75 overflow-clip text-ellipsis"
|
|
|
|
>
|
|
|
|
{asset.originalFileName}
|
|
|
|
</div>
|
|
|
|
{/if}
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
|
|
|
{/each}
|
|
|
|
</div>
|
2023-01-14 23:49:47 -06:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
<!-- Overlay Asset Viewer -->
|
2024-05-02 04:17:40 +08:00
|
|
|
{#if $isViewerOpen}
|
2024-04-24 15:24:19 -04:00
|
|
|
<Portal target="body">
|
feat(web): Scroll to asset in gridview; increase gridview perf; reduce memory; scrollbar ticks in fixed position (#10646)
* Squashed
* Change strategy - now pre-measure buckets offscreen, so don't need to worry about sub-bucket scroll preservation
* Reduce jank on scroll, delay DOM updates until after scroll
* css opt, log measure time
* Trickle out queue while scrolling, flush when stopped
* yay
* Cleanup cleanup...
* everybody...
* everywhere...
* Clean up cleanup!
* Everybody do their share
* CLEANUP!
* package-lock ?
* dynamic measure, todo
* Fix web test
* type lint
* fix e2e
* e2e test
* Better scrollbar
* Tuning, and more tunables
* Tunable tweaks, more tunables
* Scrollbar dots and viewport events
* lint
* Tweaked tunnables, use requestIdleCallback for garbage tasks, bug fixes
* New tunables, and don't update url by default
* Bug fixes
* Bug fix, with debug
* Fix flickr, fix graybox bug, reduced debug
* Refactor/cleanup
* Fix
* naming
* Final cleanup
* review comment
* Forgot to update this after naming change
* scrubber works, with debug
* cleanup
* Rename scrollbar to scrubber
* rename to
* left over rename and change to previous album bar
* bugfix addassets, comments
* missing destroy(), cleanup
---------
Co-authored-by: Alex <alex.tran1502@gmail.com>
2024-08-21 22:15:21 -04:00
|
|
|
<AssetViewer
|
|
|
|
asset={$viewingAsset}
|
|
|
|
onAction={handleAction}
|
|
|
|
on:previous={handlePrevious}
|
|
|
|
on:next={handleNext}
|
|
|
|
on:close={() => {
|
|
|
|
assetViewingStore.showAssetViewer(false);
|
|
|
|
handlePromiseError(navigate({ targetRoute: 'current', assetId: null }));
|
|
|
|
}}
|
|
|
|
/>
|
2024-04-24 15:24:19 -04:00
|
|
|
</Portal>
|
2023-01-14 23:49:47 -06:00
|
|
|
{/if}
|