2023-01-14 23:49:47 -06:00
|
|
|
<script lang="ts">
|
2025-03-12 02:18:14 +11:00
|
|
|
import { type ShortcutOptions, shortcuts } from '$lib/actions/shortcut';
|
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';
|
2025-03-04 21:34:53 -05:00
|
|
|
import type { Viewport } from '$lib/stores/assets-store.svelte';
|
2024-11-19 19:19:50 +01:00
|
|
|
import { showDeleteModal } from '$lib/stores/preferences.store';
|
|
|
|
import { deleteAssets } from '$lib/utils/actions';
|
2025-03-18 10:14:46 -04:00
|
|
|
import { archiveAssets, cancelMultiselect } from '$lib/utils/asset-utils';
|
2024-11-19 19:19:50 +01:00
|
|
|
import { featureFlags } from '$lib/stores/server-config.store';
|
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';
|
2024-02-17 11:00:55 -06:00
|
|
|
import { type AssetResponseDto } from '@immich/sdk';
|
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';
|
2024-11-19 19:19:50 +01:00
|
|
|
import ShowShortcuts from '../show-shortcuts.svelte';
|
2024-07-31 18:25:38 +02:00
|
|
|
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';
|
2024-11-19 19:19:50 +01:00
|
|
|
import DeleteAssetDialog from '../../photos-page/delete-asset-dialog.svelte';
|
2024-12-14 19:30:33 +01:00
|
|
|
import type { AssetInteraction } from '$lib/stores/asset-interaction.svelte';
|
2025-03-18 10:14:46 -04:00
|
|
|
import { debounce } from 'lodash-es';
|
|
|
|
import { getJustifiedLayoutFromAssets, type CommonJustifiedLayout } from '$lib/utils/layout-utils';
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
interface Props {
|
|
|
|
assets: AssetResponseDto[];
|
2024-12-14 19:30:33 +01:00
|
|
|
assetInteraction: AssetInteraction;
|
2024-11-14 08:43:25 -06:00
|
|
|
disableAssetSelect?: boolean;
|
|
|
|
showArchiveIcon?: boolean;
|
|
|
|
viewport: Viewport;
|
|
|
|
onIntersected?: (() => void) | undefined;
|
|
|
|
showAssetName?: boolean;
|
2024-11-19 19:19:50 +01:00
|
|
|
isShowDeleteConfirmation?: boolean;
|
2024-11-14 08:43:25 -06:00
|
|
|
onPrevious?: (() => Promise<AssetResponseDto | undefined>) | undefined;
|
|
|
|
onNext?: (() => Promise<AssetResponseDto | undefined>) | undefined;
|
2025-01-14 15:24:58 +01:00
|
|
|
onRandom?: (() => Promise<AssetResponseDto | undefined>) | undefined;
|
2025-03-20 22:30:01 -05:00
|
|
|
pageHeaderOffset?: number;
|
|
|
|
slidingWindowOffset?: number;
|
2024-11-14 08:43:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
let {
|
|
|
|
assets = $bindable(),
|
2024-12-14 19:30:33 +01:00
|
|
|
assetInteraction,
|
2024-11-14 08:43:25 -06:00
|
|
|
disableAssetSelect = false,
|
|
|
|
showArchiveIcon = false,
|
|
|
|
viewport,
|
|
|
|
onIntersected = undefined,
|
|
|
|
showAssetName = false,
|
2024-11-19 19:19:50 +01:00
|
|
|
isShowDeleteConfirmation = $bindable(false),
|
2024-11-14 08:43:25 -06:00
|
|
|
onPrevious = undefined,
|
|
|
|
onNext = undefined,
|
2025-01-14 15:24:58 +01:00
|
|
|
onRandom = undefined,
|
2025-03-20 22:30:01 -05:00
|
|
|
slidingWindowOffset = 0,
|
|
|
|
pageHeaderOffset = 0,
|
2024-11-14 08:43:25 -06:00
|
|
|
}: Props = $props();
|
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
|
|
|
|
2025-03-18 10:14:46 -04:00
|
|
|
let geometry: CommonJustifiedLayout | undefined = $state();
|
|
|
|
|
|
|
|
$effect(() => {
|
|
|
|
const _assets = assets;
|
|
|
|
updateSlidingWindow();
|
|
|
|
|
2025-03-19 11:57:44 -04:00
|
|
|
const rowWidth = Math.floor(viewport.width);
|
|
|
|
const rowHeight = rowWidth < 850 ? 100 : 235;
|
|
|
|
|
2025-03-18 10:14:46 -04:00
|
|
|
geometry = getJustifiedLayoutFromAssets(_assets, {
|
|
|
|
spacing: 2,
|
|
|
|
heightTolerance: 0.15,
|
2025-03-19 11:57:44 -04:00
|
|
|
rowHeight,
|
|
|
|
rowWidth,
|
2025-03-18 10:14:46 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
let assetLayouts = $derived.by(() => {
|
|
|
|
const assetLayout = [];
|
|
|
|
let containerHeight = 0;
|
|
|
|
let containerWidth = 0;
|
|
|
|
if (geometry) {
|
|
|
|
containerHeight = geometry.containerHeight;
|
|
|
|
containerWidth = geometry.containerWidth;
|
|
|
|
for (const [i, asset] of assets.entries()) {
|
|
|
|
const layout = {
|
|
|
|
asset,
|
|
|
|
top: geometry.getTop(i),
|
|
|
|
left: geometry.getLeft(i),
|
|
|
|
width: geometry.getWidth(i),
|
|
|
|
height: geometry.getHeight(i),
|
|
|
|
};
|
|
|
|
// 54 is the content height of the asset-selection-app-bar
|
2025-03-20 22:30:01 -05:00
|
|
|
const layoutTopWithOffset = layout.top + pageHeaderOffset;
|
2025-03-18 10:14:46 -04:00
|
|
|
const layoutBottom = layoutTopWithOffset + layout.height;
|
|
|
|
|
|
|
|
const display = layoutTopWithOffset < slidingWindow.bottom && layoutBottom > slidingWindow.top;
|
|
|
|
assetLayout.push({ ...layout, display });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
assetLayout,
|
|
|
|
containerHeight,
|
|
|
|
containerWidth,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2024-11-19 19:19:50 +01:00
|
|
|
let showShortcuts = $state(false);
|
2023-07-01 00:50:47 -04:00
|
|
|
let currentViewAssetIndex = 0;
|
2024-11-19 19:19:50 +01:00
|
|
|
let shiftKeyIsDown = $state(false);
|
|
|
|
let lastAssetMouseEvent: AssetResponseDto | null = $state(null);
|
2025-03-18 10:14:46 -04:00
|
|
|
let slidingWindow = $state({ top: 0, bottom: 0 });
|
|
|
|
|
|
|
|
const updateSlidingWindow = () => {
|
|
|
|
const v = $state.snapshot(viewport);
|
2025-03-20 22:30:01 -05:00
|
|
|
const top = (document.scrollingElement?.scrollTop || 0) - slidingWindowOffset;
|
2025-03-18 10:14:46 -04:00
|
|
|
const bottom = top + v.height;
|
|
|
|
const w = {
|
|
|
|
top,
|
|
|
|
bottom,
|
|
|
|
};
|
|
|
|
slidingWindow = w;
|
|
|
|
};
|
|
|
|
const debouncedOnIntersected = debounce(() => onIntersected?.(), 750, { maxWait: 100, leading: true });
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2025-03-18 10:14:46 -04:00
|
|
|
let lastIntersectedHeight = 0;
|
|
|
|
$effect(() => {
|
|
|
|
// notify we got to (near) the end of scroll
|
|
|
|
const scrollPercentage =
|
|
|
|
((slidingWindow.bottom - viewport.height) / (viewport.height - (document.scrollingElement?.clientHeight || 0))) *
|
|
|
|
100;
|
|
|
|
|
|
|
|
if (scrollPercentage > 90) {
|
|
|
|
const intersectedHeight = geometry?.containerHeight || 0;
|
|
|
|
if (lastIntersectedHeight !== intersectedHeight) {
|
|
|
|
debouncedOnIntersected();
|
|
|
|
lastIntersectedHeight = intersectedHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
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-11-19 19:19:50 +01:00
|
|
|
const selectAllAssets = () => {
|
2024-12-14 19:30:33 +01:00
|
|
|
assetInteraction.selectAssets(assets);
|
2024-11-19 19:19:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const deselectAllAssets = () => {
|
2024-12-14 19:30:33 +01:00
|
|
|
cancelMultiselect(assetInteraction);
|
2024-11-19 19:19:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const onKeyDown = (event: KeyboardEvent) => {
|
|
|
|
if (event.key === 'Shift') {
|
|
|
|
event.preventDefault();
|
2025-03-18 10:14:46 -04:00
|
|
|
|
2024-11-19 19:19:50 +01:00
|
|
|
shiftKeyIsDown = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const onKeyUp = (event: KeyboardEvent) => {
|
|
|
|
if (event.key === 'Shift') {
|
|
|
|
event.preventDefault();
|
|
|
|
shiftKeyIsDown = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleSelectAssets = (asset: AssetResponseDto) => {
|
|
|
|
if (!asset) {
|
|
|
|
return;
|
|
|
|
}
|
2025-03-18 10:14:46 -04:00
|
|
|
const deselect = assetInteraction.hasSelectedAsset(asset.id);
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2024-11-19 19:19:50 +01:00
|
|
|
// Select/deselect already loaded assets
|
|
|
|
if (deselect) {
|
2024-12-14 19:30:33 +01:00
|
|
|
for (const candidate of assetInteraction.assetSelectionCandidates) {
|
2025-03-19 11:55:50 -04:00
|
|
|
assetInteraction.removeAssetFromMultiselectGroup(candidate.id);
|
2024-11-19 19:19:50 +01:00
|
|
|
}
|
2025-03-19 11:55:50 -04:00
|
|
|
assetInteraction.removeAssetFromMultiselectGroup(asset.id);
|
2023-07-01 00:50:47 -04:00
|
|
|
} else {
|
2024-12-14 19:30:33 +01:00
|
|
|
for (const candidate of assetInteraction.assetSelectionCandidates) {
|
|
|
|
assetInteraction.selectAsset(candidate);
|
2024-11-19 19:19:50 +01:00
|
|
|
}
|
2024-12-14 19:30:33 +01:00
|
|
|
assetInteraction.selectAsset(asset);
|
2024-11-19 19:19:50 +01:00
|
|
|
}
|
|
|
|
|
2024-12-14 19:30:33 +01:00
|
|
|
assetInteraction.clearAssetSelectionCandidates();
|
|
|
|
assetInteraction.setAssetSelectionStart(deselect ? null : asset);
|
2024-11-19 19:19:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const handleSelectAssetCandidates = (asset: AssetResponseDto | null) => {
|
|
|
|
if (asset) {
|
|
|
|
selectAssetCandidates(asset);
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
2024-11-19 19:19:50 +01:00
|
|
|
lastAssetMouseEvent = asset;
|
|
|
|
};
|
|
|
|
|
|
|
|
const selectAssetCandidates = (endAsset: AssetResponseDto) => {
|
|
|
|
if (!shiftKeyIsDown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-14 19:30:33 +01:00
|
|
|
const startAsset = assetInteraction.assetSelectionStart;
|
2024-11-19 19:19:50 +01:00
|
|
|
if (!startAsset) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let start = assets.findIndex((a) => a.id === startAsset.id);
|
|
|
|
let end = assets.findIndex((a) => a.id === endAsset.id);
|
|
|
|
|
|
|
|
if (start > end) {
|
|
|
|
[start, end] = [end, start];
|
|
|
|
}
|
|
|
|
|
2024-12-14 19:30:33 +01:00
|
|
|
assetInteraction.setAssetSelectionCandidates(assets.slice(start, end + 1));
|
2024-11-19 19:19:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const onSelectStart = (e: Event) => {
|
2024-12-14 19:30:33 +01:00
|
|
|
if (assetInteraction.selectionActive && shiftKeyIsDown) {
|
2024-11-19 19:19:50 +01:00
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const onDelete = () => {
|
2025-03-19 11:55:50 -04:00
|
|
|
const hasTrashedAsset = assetInteraction.selectedAssets.some((asset) => asset.isTrashed);
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2024-11-19 19:19:50 +01:00
|
|
|
if ($showDeleteModal && (!isTrashEnabled || hasTrashedAsset)) {
|
|
|
|
isShowDeleteConfirmation = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
handlePromiseError(trashOrDelete(hasTrashedAsset));
|
|
|
|
};
|
|
|
|
|
|
|
|
const onForceDelete = () => {
|
|
|
|
if ($showDeleteModal) {
|
|
|
|
isShowDeleteConfirmation = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
handlePromiseError(trashOrDelete(true));
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
|
|
|
|
2024-11-19 19:19:50 +01:00
|
|
|
const trashOrDelete = async (force: boolean = false) => {
|
|
|
|
isShowDeleteConfirmation = false;
|
|
|
|
await deleteAssets(
|
|
|
|
!(isTrashEnabled && !force),
|
|
|
|
(assetIds) => (assets = assets.filter((asset) => !assetIds.includes(asset.id))),
|
|
|
|
idsSelectedAssets,
|
|
|
|
);
|
2024-12-14 19:30:33 +01:00
|
|
|
assetInteraction.clearMultiselect();
|
2024-11-19 19:19:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const toggleArchive = async () => {
|
2025-03-19 11:55:50 -04:00
|
|
|
const ids = await archiveAssets(assetInteraction.selectedAssets, !assetInteraction.isAllArchived);
|
2024-11-19 19:19:50 +01:00
|
|
|
if (ids) {
|
2025-03-18 10:14:46 -04:00
|
|
|
assets = assets.filter((asset) => !ids.includes(asset.id));
|
2024-11-19 19:19:50 +01:00
|
|
|
deselectAllAssets();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2025-03-12 02:18:14 +11:00
|
|
|
const focusNextAsset = () => {
|
|
|
|
if (assetInteraction.focussedAssetId === null && assets.length > 0) {
|
|
|
|
assetInteraction.focussedAssetId = assets[0].id;
|
|
|
|
} else if (assetInteraction.focussedAssetId !== null && assets.length > 0) {
|
|
|
|
const currentIndex = assets.findIndex((a) => a.id === assetInteraction.focussedAssetId);
|
|
|
|
if (currentIndex !== -1 && currentIndex + 1 < assets.length) {
|
|
|
|
assetInteraction.focussedAssetId = assets[currentIndex + 1].id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const focusPreviousAsset = () => {
|
|
|
|
if (assetInteraction.focussedAssetId !== null && assets.length > 0) {
|
|
|
|
const currentIndex = assets.findIndex((a) => a.id === assetInteraction.focussedAssetId);
|
|
|
|
if (currentIndex >= 1) {
|
|
|
|
assetInteraction.focussedAssetId = assets[currentIndex - 1].id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-11-19 19:19:50 +01:00
|
|
|
let shortcutList = $derived(
|
|
|
|
(() => {
|
|
|
|
if ($isViewerOpen) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
const shortcuts: ShortcutOptions[] = [
|
|
|
|
{ shortcut: { key: '?', shift: true }, onShortcut: () => (showShortcuts = !showShortcuts) },
|
|
|
|
{ shortcut: { key: '/' }, onShortcut: () => goto(AppRoute.EXPLORE) },
|
|
|
|
{ shortcut: { key: 'A', ctrl: true }, onShortcut: () => selectAllAssets() },
|
2025-03-12 02:18:14 +11:00
|
|
|
{ shortcut: { key: 'ArrowRight' }, preventDefault: false, onShortcut: focusNextAsset },
|
|
|
|
{ shortcut: { key: 'ArrowLeft' }, preventDefault: false, onShortcut: focusPreviousAsset },
|
2024-11-19 19:19:50 +01:00
|
|
|
];
|
|
|
|
|
2024-12-14 19:30:33 +01:00
|
|
|
if (assetInteraction.selectionActive) {
|
2024-11-19 19:19:50 +01:00
|
|
|
shortcuts.push(
|
|
|
|
{ shortcut: { key: 'Escape' }, onShortcut: deselectAllAssets },
|
|
|
|
{ shortcut: { key: 'Delete' }, onShortcut: onDelete },
|
|
|
|
{ shortcut: { key: 'Delete', shift: true }, onShortcut: onForceDelete },
|
|
|
|
{ shortcut: { key: 'D', ctrl: true }, onShortcut: () => deselectAllAssets() },
|
|
|
|
{ shortcut: { key: 'a', shift: true }, onShortcut: toggleArchive },
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return shortcuts;
|
|
|
|
})(),
|
|
|
|
);
|
|
|
|
|
2025-01-14 15:24:58 +01:00
|
|
|
const handleNext = async (): Promise<boolean> => {
|
2023-07-01 00:50:47 -04:00
|
|
|
try {
|
2024-11-14 16:05:36 +01:00
|
|
|
let asset: AssetResponseDto | undefined;
|
|
|
|
if (onNext) {
|
|
|
|
asset = await onNext();
|
|
|
|
} else {
|
2025-01-14 15:24:58 +01:00
|
|
|
currentViewAssetIndex = currentViewAssetIndex + 1;
|
|
|
|
asset = currentViewAssetIndex < assets.length ? assets[currentViewAssetIndex] : undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!asset) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
await navigateToAsset(asset);
|
|
|
|
return true;
|
|
|
|
} catch (error) {
|
|
|
|
handleError(error, $t('errors.cannot_navigate_next_asset'));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2025-03-18 10:14:46 -04:00
|
|
|
const handleRandom = async (): Promise<AssetResponseDto | undefined> => {
|
2025-01-14 15:24:58 +01:00
|
|
|
try {
|
|
|
|
let asset: AssetResponseDto | undefined;
|
|
|
|
if (onRandom) {
|
|
|
|
asset = await onRandom();
|
|
|
|
} else {
|
|
|
|
if (assets.length > 0) {
|
|
|
|
const randomIndex = Math.floor(Math.random() * assets.length);
|
|
|
|
asset = assets[randomIndex];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!asset) {
|
2025-03-18 10:14:46 -04:00
|
|
|
return;
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
2024-11-14 16:05:36 +01:00
|
|
|
|
|
|
|
await navigateToAsset(asset);
|
2025-01-14 15:24:58 +01:00
|
|
|
return asset;
|
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'));
|
2025-03-18 10:14:46 -04:00
|
|
|
return;
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2025-01-14 15:24:58 +01:00
|
|
|
const handlePrevious = async (): Promise<boolean> => {
|
2023-07-01 00:50:47 -04:00
|
|
|
try {
|
2024-11-14 16:05:36 +01:00
|
|
|
let asset: AssetResponseDto | undefined;
|
|
|
|
if (onPrevious) {
|
|
|
|
asset = await onPrevious();
|
|
|
|
} else {
|
2025-01-14 15:24:58 +01:00
|
|
|
currentViewAssetIndex = currentViewAssetIndex - 1;
|
|
|
|
asset = currentViewAssetIndex >= 0 ? assets[currentViewAssetIndex] : undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!asset) {
|
|
|
|
return false;
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
2024-11-14 16:05:36 +01:00
|
|
|
|
|
|
|
await navigateToAsset(asset);
|
2025-01-14 15:24:58 +01:00
|
|
|
return true;
|
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'));
|
2025-01-14 15:24:58 +01:00
|
|
|
return false;
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-11-14 16:05:36 +01:00
|
|
|
const navigateToAsset = async (asset?: AssetResponseDto) => {
|
|
|
|
if (asset && asset.id !== $viewingAsset.id) {
|
|
|
|
setAsset(asset);
|
|
|
|
await navigate({ targetRoute: 'current', assetId: $viewingAsset.id });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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,
|
|
|
|
);
|
|
|
|
if (assets.length === 0) {
|
|
|
|
await goto(AppRoute.PHOTOS);
|
|
|
|
} else if (currentViewAssetIndex === assets.length) {
|
|
|
|
await handlePrevious();
|
|
|
|
} else {
|
|
|
|
setAsset(assets[currentViewAssetIndex]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-11-19 19:19:50 +01:00
|
|
|
const assetMouseEventHandler = (asset: AssetResponseDto | null) => {
|
2024-12-14 19:30:33 +01:00
|
|
|
if (assetInteraction.selectionActive) {
|
2024-11-19 19:19:50 +01:00
|
|
|
handleSelectAssetCandidates(asset);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2025-03-12 02:18:14 +11:00
|
|
|
const assetOnFocusHandler = (asset: AssetResponseDto) => {
|
|
|
|
assetInteraction.focussedAssetId = asset.id;
|
|
|
|
};
|
|
|
|
|
2024-11-19 19:19:50 +01:00
|
|
|
let isTrashEnabled = $derived($featureFlags.loaded && $featureFlags.trash);
|
2025-03-19 11:55:50 -04:00
|
|
|
let idsSelectedAssets = $derived(assetInteraction.selectedAssets.map(({ id }) => id));
|
2024-02-17 11:00:55 -06:00
|
|
|
|
2024-11-19 19:19:50 +01:00
|
|
|
$effect(() => {
|
|
|
|
if (!lastAssetMouseEvent) {
|
2024-12-14 19:30:33 +01:00
|
|
|
assetInteraction.clearAssetSelectionCandidates();
|
2024-11-19 19:19:50 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$effect(() => {
|
|
|
|
if (!shiftKeyIsDown) {
|
2024-12-14 19:30:33 +01:00
|
|
|
assetInteraction.clearAssetSelectionCandidates();
|
2024-11-19 19:19:50 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$effect(() => {
|
|
|
|
if (shiftKeyIsDown && lastAssetMouseEvent) {
|
|
|
|
selectAssetCandidates(lastAssetMouseEvent);
|
|
|
|
}
|
|
|
|
});
|
2023-01-14 23:49:47 -06:00
|
|
|
</script>
|
|
|
|
|
2025-03-18 10:14:46 -04:00
|
|
|
<svelte:window
|
|
|
|
onkeydown={onKeyDown}
|
|
|
|
onkeyup={onKeyUp}
|
|
|
|
onselectstart={onSelectStart}
|
|
|
|
use:shortcuts={shortcutList}
|
|
|
|
onscroll={() => updateSlidingWindow()}
|
|
|
|
/>
|
2024-11-19 19:19:50 +01:00
|
|
|
|
|
|
|
{#if isShowDeleteConfirmation}
|
|
|
|
<DeleteAssetDialog
|
2025-03-19 11:55:50 -04:00
|
|
|
size={assetInteraction.selectedAssets.length}
|
2024-11-19 19:19:50 +01:00
|
|
|
onCancel={() => (isShowDeleteConfirmation = false)}
|
|
|
|
onConfirm={() => handlePromiseError(trashOrDelete(true))}
|
|
|
|
/>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
{#if showShortcuts}
|
|
|
|
<ShowShortcuts onClose={() => (showShortcuts = !showShortcuts)} />
|
|
|
|
{/if}
|
|
|
|
|
2023-01-14 23:49:47 -06:00
|
|
|
{#if assets.length > 0}
|
2025-03-18 10:14:46 -04:00
|
|
|
<div
|
|
|
|
style:position="relative"
|
|
|
|
style:height={assetLayouts.containerHeight + 'px'}
|
|
|
|
style:width={assetLayouts.containerWidth - 1 + 'px'}
|
|
|
|
>
|
|
|
|
{#each assetLayouts.assetLayout as layout (layout.asset.id)}
|
|
|
|
{@const asset = layout.asset}
|
|
|
|
|
|
|
|
{#if layout.display}
|
|
|
|
<div
|
|
|
|
class="absolute"
|
|
|
|
style:overflow="clip"
|
|
|
|
style="width: {layout.width}px; height: {layout.height}px; top: {layout.top}px; left: {layout.left}px"
|
|
|
|
title={showAssetName ? asset.originalFileName : ''}
|
|
|
|
>
|
|
|
|
<Thumbnail
|
|
|
|
readonly={disableAssetSelect}
|
|
|
|
onClick={(asset) => {
|
|
|
|
if (assetInteraction.selectionActive) {
|
|
|
|
handleSelectAssets(asset);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
void viewAssetHandler(asset);
|
|
|
|
}}
|
|
|
|
onSelect={(asset) => handleSelectAssets(asset)}
|
|
|
|
onMouseEvent={() => assetMouseEventHandler(asset)}
|
|
|
|
handleFocus={() => assetOnFocusHandler(asset)}
|
|
|
|
{showArchiveIcon}
|
|
|
|
{asset}
|
|
|
|
selected={assetInteraction.hasSelectedAsset(asset.id)}
|
|
|
|
selectionCandidate={assetInteraction.hasSelectionCandidate(asset.id)}
|
2025-03-19 11:55:50 -04:00
|
|
|
focussed={assetInteraction.isFocussedAsset(asset.id)}
|
2025-03-18 10:14:46 -04:00
|
|
|
thumbnailWidth={layout.width}
|
|
|
|
thumbnailHeight={layout.height}
|
|
|
|
/>
|
|
|
|
{#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 whitespace-pre-wrap"
|
|
|
|
>
|
|
|
|
{asset.originalFileName}
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
{/if}
|
2025-02-25 09:39:56 -06:00
|
|
|
{/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}
|
2024-09-20 23:02:58 +02:00
|
|
|
onPrevious={handlePrevious}
|
|
|
|
onNext={handleNext}
|
2025-01-14 15:24:58 +01:00
|
|
|
onRandom={handleRandom}
|
2024-09-20 23:02:58 +02:00
|
|
|
onClose={() => {
|
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
|
|
|
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}
|