mirror of
https://github.com/immich-app/immich.git
synced 2024-12-29 15:11:58 +00:00
feat: Added shortcuts, shift-multi select and missing menu options to Search (Galleryviewer) (#14213)
feat: Added shortcuts, shift-multi select and missing menu options to GalleryViewer (Search, Share, Memories) Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
parent
3a2e30e30e
commit
69e50d0d27
5 changed files with 238 additions and 48 deletions
|
@ -17,6 +17,8 @@
|
||||||
import ButtonContextMenu from '$lib/components/shared-components/context-menu/button-context-menu.svelte';
|
import ButtonContextMenu from '$lib/components/shared-components/context-menu/button-context-menu.svelte';
|
||||||
import ControlAppBar from '$lib/components/shared-components/control-app-bar.svelte';
|
import ControlAppBar from '$lib/components/shared-components/control-app-bar.svelte';
|
||||||
import GalleryViewer from '$lib/components/shared-components/gallery-viewer/gallery-viewer.svelte';
|
import GalleryViewer from '$lib/components/shared-components/gallery-viewer/gallery-viewer.svelte';
|
||||||
|
import { cancelMultiselect } from '$lib/utils/asset-utils';
|
||||||
|
import { createAssetInteractionStore } from '$lib/stores/asset-interaction.store';
|
||||||
import { AppRoute, QueryParameter } from '$lib/constants';
|
import { AppRoute, QueryParameter } from '$lib/constants';
|
||||||
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
|
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
|
||||||
import { type Viewport } from '$lib/stores/assets.store';
|
import { type Viewport } from '$lib/stores/assets.store';
|
||||||
|
@ -44,7 +46,6 @@
|
||||||
import { tweened } from 'svelte/motion';
|
import { tweened } from 'svelte/motion';
|
||||||
import { derived as storeDerived } from 'svelte/store';
|
import { derived as storeDerived } from 'svelte/store';
|
||||||
import { fade } from 'svelte/transition';
|
import { fade } from 'svelte/transition';
|
||||||
import { SvelteSet } from 'svelte/reactivity';
|
|
||||||
|
|
||||||
type MemoryIndex = {
|
type MemoryIndex = {
|
||||||
memoryIndex: number;
|
memoryIndex: number;
|
||||||
|
@ -64,13 +65,14 @@
|
||||||
let memoryWrapper: HTMLElement | undefined = $state();
|
let memoryWrapper: HTMLElement | undefined = $state();
|
||||||
let galleryInView = $state(false);
|
let galleryInView = $state(false);
|
||||||
let paused = $state(false);
|
let paused = $state(false);
|
||||||
let selectedAssets: SvelteSet<AssetResponseDto> = $state(new SvelteSet());
|
|
||||||
let current: MemoryAsset | undefined = $state(undefined);
|
let current: MemoryAsset | undefined = $state(undefined);
|
||||||
// let memories: MemoryAsset[] = [];
|
// let memories: MemoryAsset[] = [];
|
||||||
let resetPromise = $state(Promise.resolve());
|
let resetPromise = $state(Promise.resolve());
|
||||||
|
|
||||||
const { isViewing } = assetViewingStore;
|
const { isViewing } = assetViewingStore;
|
||||||
const viewport: Viewport = $state({ width: 0, height: 0 });
|
const viewport: Viewport = $state({ width: 0, height: 0 });
|
||||||
|
const assetInteractionStore = createAssetInteractionStore();
|
||||||
|
const { selectedAssets } = assetInteractionStore;
|
||||||
const progressBarController = tweened<number>(0, {
|
const progressBarController = tweened<number>(0, {
|
||||||
duration: (from: number, to: number) => (to ? 5000 * (to - from) : 0),
|
duration: (from: number, to: number) => (to ? 5000 * (to - from) : 0),
|
||||||
});
|
});
|
||||||
|
@ -126,7 +128,7 @@
|
||||||
const handleNextMemory = () => handleNavigate(current?.nextMemory?.assets[0]);
|
const handleNextMemory = () => handleNavigate(current?.nextMemory?.assets[0]);
|
||||||
const handlePreviousMemory = () => handleNavigate(current?.previousMemory?.assets[0]);
|
const handlePreviousMemory = () => handleNavigate(current?.previousMemory?.assets[0]);
|
||||||
const handleEscape = async () => goto(AppRoute.PHOTOS);
|
const handleEscape = async () => goto(AppRoute.PHOTOS);
|
||||||
const handleSelectAll = () => (selectedAssets = new SvelteSet(current?.memory.assets || []));
|
const handleSelectAll = () => assetInteractionStore.selectAssets(current?.memory.assets || []);
|
||||||
const handleAction = async (action: 'reset' | 'pause' | 'play') => {
|
const handleAction = async (action: 'reset' | 'pause' | 'play') => {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'play': {
|
case 'play': {
|
||||||
|
@ -207,13 +209,10 @@
|
||||||
|
|
||||||
current = loadFromParams($memories, target);
|
current = loadFromParams($memories, target);
|
||||||
});
|
});
|
||||||
$effect(() => {
|
|
||||||
selectedAssets = galleryInView ? selectedAssets : new SvelteSet();
|
|
||||||
});
|
|
||||||
|
|
||||||
let isMultiSelectionMode = $derived(selectedAssets.size > 0);
|
let isMultiSelectionMode = $derived($selectedAssets.size > 0);
|
||||||
let isAllArchived = $derived([...selectedAssets].every((asset) => asset.isArchived));
|
let isAllArchived = $derived([...$selectedAssets].every((asset) => asset.isArchived));
|
||||||
let isAllFavorite = $derived([...selectedAssets].every((asset) => asset.isFavorite));
|
let isAllFavorite = $derived([...$selectedAssets].every((asset) => asset.isFavorite));
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
handlePromiseError(handleProgress($progressBarController));
|
handlePromiseError(handleProgress($progressBarController));
|
||||||
|
@ -238,7 +237,7 @@
|
||||||
|
|
||||||
{#if isMultiSelectionMode}
|
{#if isMultiSelectionMode}
|
||||||
<div class="sticky top-0 z-[90]">
|
<div class="sticky top-0 z-[90]">
|
||||||
<AssetSelectControlBar assets={selectedAssets} clearSelect={() => (selectedAssets = new SvelteSet())}>
|
<AssetSelectControlBar assets={$selectedAssets} clearSelect={() => cancelMultiselect(assetInteractionStore)}>
|
||||||
<CreateSharedLink />
|
<CreateSharedLink />
|
||||||
<CircleIconButton title={$t('select_all')} icon={mdiSelectAll} onclick={handleSelectAll} />
|
<CircleIconButton title={$t('select_all')} icon={mdiSelectAll} onclick={handleSelectAll} />
|
||||||
|
|
||||||
|
@ -485,7 +484,7 @@
|
||||||
onPrevious={handlePreviousAsset}
|
onPrevious={handlePreviousAsset}
|
||||||
assets={current.memory.assets}
|
assets={current.memory.assets}
|
||||||
{viewport}
|
{viewport}
|
||||||
bind:selectedAssets
|
{assetInteractionStore}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
import { downloadArchive } from '$lib/utils/asset-utils';
|
import { downloadArchive } from '$lib/utils/asset-utils';
|
||||||
import { fileUploadHandler, openFileUploadDialog } from '$lib/utils/file-uploader';
|
import { fileUploadHandler, openFileUploadDialog } from '$lib/utils/file-uploader';
|
||||||
import { handleError } from '$lib/utils/handle-error';
|
import { handleError } from '$lib/utils/handle-error';
|
||||||
import { addSharedLinkAssets, type AssetResponseDto, type SharedLinkResponseDto } from '@immich/sdk';
|
import { addSharedLinkAssets, type SharedLinkResponseDto } from '@immich/sdk';
|
||||||
import { mdiArrowLeft, mdiFileImagePlusOutline, mdiFolderDownloadOutline, mdiSelectAll } from '@mdi/js';
|
import { mdiArrowLeft, mdiFileImagePlusOutline, mdiFolderDownloadOutline, mdiSelectAll } from '@mdi/js';
|
||||||
import CircleIconButton from '../elements/buttons/circle-icon-button.svelte';
|
import CircleIconButton from '../elements/buttons/circle-icon-button.svelte';
|
||||||
import DownloadAction from '../photos-page/actions/download-action.svelte';
|
import DownloadAction from '../photos-page/actions/download-action.svelte';
|
||||||
|
@ -14,6 +14,8 @@
|
||||||
import AssetSelectControlBar from '../photos-page/asset-select-control-bar.svelte';
|
import AssetSelectControlBar from '../photos-page/asset-select-control-bar.svelte';
|
||||||
import ControlAppBar from '../shared-components/control-app-bar.svelte';
|
import ControlAppBar from '../shared-components/control-app-bar.svelte';
|
||||||
import GalleryViewer from '../shared-components/gallery-viewer/gallery-viewer.svelte';
|
import GalleryViewer from '../shared-components/gallery-viewer/gallery-viewer.svelte';
|
||||||
|
import { cancelMultiselect } from '$lib/utils/asset-utils';
|
||||||
|
import { createAssetInteractionStore } from '$lib/stores/asset-interaction.store';
|
||||||
import ImmichLogoSmallLink from '$lib/components/shared-components/immich-logo-small-link.svelte';
|
import ImmichLogoSmallLink from '$lib/components/shared-components/immich-logo-small-link.svelte';
|
||||||
import { NotificationType, notificationController } from '../shared-components/notification/notification';
|
import { NotificationType, notificationController } from '../shared-components/notification/notification';
|
||||||
import type { Viewport } from '$lib/stores/assets.store';
|
import type { Viewport } from '$lib/stores/assets.store';
|
||||||
|
@ -27,11 +29,12 @@
|
||||||
let { sharedLink = $bindable(), isOwned }: Props = $props();
|
let { sharedLink = $bindable(), isOwned }: Props = $props();
|
||||||
|
|
||||||
const viewport: Viewport = $state({ width: 0, height: 0 });
|
const viewport: Viewport = $state({ width: 0, height: 0 });
|
||||||
let selectedAssets: Set<AssetResponseDto> = $state(new Set());
|
const assetInteractionStore = createAssetInteractionStore();
|
||||||
|
const { selectedAssets } = assetInteractionStore;
|
||||||
let innerWidth: number = $state(0);
|
let innerWidth: number = $state(0);
|
||||||
|
|
||||||
let assets = $derived(sharedLink.assets);
|
let assets = $derived(sharedLink.assets);
|
||||||
let isMultiSelectionMode = $derived(selectedAssets.size > 0);
|
let isMultiSelectionMode = $derived($selectedAssets.size > 0);
|
||||||
|
|
||||||
dragAndDropFilesStore.subscribe((value) => {
|
dragAndDropFilesStore.subscribe((value) => {
|
||||||
if (value.isDragging && value.files.length > 0) {
|
if (value.isDragging && value.files.length > 0) {
|
||||||
|
@ -70,7 +73,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSelectAll = () => {
|
const handleSelectAll = () => {
|
||||||
selectedAssets = new Set(assets);
|
assetInteractionStore.selectAssets(assets);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -78,7 +81,7 @@
|
||||||
|
|
||||||
<section class="bg-immich-bg dark:bg-immich-dark-bg">
|
<section class="bg-immich-bg dark:bg-immich-dark-bg">
|
||||||
{#if isMultiSelectionMode}
|
{#if isMultiSelectionMode}
|
||||||
<AssetSelectControlBar assets={selectedAssets} clearSelect={() => (selectedAssets = new Set())}>
|
<AssetSelectControlBar assets={$selectedAssets} clearSelect={() => cancelMultiselect(assetInteractionStore)}>
|
||||||
<CircleIconButton title={$t('select_all')} icon={mdiSelectAll} onclick={handleSelectAll} />
|
<CircleIconButton title={$t('select_all')} icon={mdiSelectAll} onclick={handleSelectAll} />
|
||||||
{#if sharedLink?.allowDownload}
|
{#if sharedLink?.allowDownload}
|
||||||
<DownloadAction filename="immich-shared.zip" />
|
<DownloadAction filename="immich-shared.zip" />
|
||||||
|
@ -109,6 +112,6 @@
|
||||||
</ControlAppBar>
|
</ControlAppBar>
|
||||||
{/if}
|
{/if}
|
||||||
<section class="my-[160px] mx-4" bind:clientHeight={viewport.height} bind:clientWidth={viewport.width}>
|
<section class="my-[160px] mx-4" bind:clientHeight={viewport.height} bind:clientWidth={viewport.width}>
|
||||||
<GalleryViewer {assets} bind:selectedAssets {viewport} />
|
<GalleryViewer {assets} {assetInteractionStore} {viewport} />
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -1,50 +1,63 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { shortcuts, type ShortcutOptions } from '$lib/actions/shortcut';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import type { Action } from '$lib/components/asset-viewer/actions/action';
|
import type { Action } from '$lib/components/asset-viewer/actions/action';
|
||||||
import Thumbnail from '$lib/components/assets/thumbnail/thumbnail.svelte';
|
import Thumbnail from '$lib/components/assets/thumbnail/thumbnail.svelte';
|
||||||
import { AppRoute, AssetAction } from '$lib/constants';
|
import { AppRoute, AssetAction } from '$lib/constants';
|
||||||
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
|
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
|
||||||
|
import type { AssetInteractionStore } from '$lib/stores/asset-interaction.store';
|
||||||
import type { Viewport } from '$lib/stores/assets.store';
|
import type { Viewport } from '$lib/stores/assets.store';
|
||||||
import { getAssetRatio } from '$lib/utils/asset-utils';
|
import { showDeleteModal } from '$lib/stores/preferences.store';
|
||||||
|
import { deleteAssets } from '$lib/utils/actions';
|
||||||
|
import { archiveAssets, cancelMultiselect, getAssetRatio } from '$lib/utils/asset-utils';
|
||||||
|
import { featureFlags } from '$lib/stores/server-config.store';
|
||||||
import { handleError } from '$lib/utils/handle-error';
|
import { handleError } from '$lib/utils/handle-error';
|
||||||
import { navigate } from '$lib/utils/navigation';
|
import { navigate } from '$lib/utils/navigation';
|
||||||
import { calculateWidth } from '$lib/utils/timeline-util';
|
import { calculateWidth } from '$lib/utils/timeline-util';
|
||||||
import { type AssetResponseDto } from '@immich/sdk';
|
import { type AssetResponseDto } from '@immich/sdk';
|
||||||
import justifiedLayout from 'justified-layout';
|
import justifiedLayout from 'justified-layout';
|
||||||
import { onDestroy } from 'svelte';
|
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
import AssetViewer from '../../asset-viewer/asset-viewer.svelte';
|
import AssetViewer from '../../asset-viewer/asset-viewer.svelte';
|
||||||
|
import ShowShortcuts from '../show-shortcuts.svelte';
|
||||||
import Portal from '../portal/portal.svelte';
|
import Portal from '../portal/portal.svelte';
|
||||||
import { handlePromiseError } from '$lib/utils';
|
import { handlePromiseError } from '$lib/utils';
|
||||||
|
import DeleteAssetDialog from '../../photos-page/delete-asset-dialog.svelte';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
assets: AssetResponseDto[];
|
assets: AssetResponseDto[];
|
||||||
selectedAssets?: Set<AssetResponseDto>;
|
assetInteractionStore: AssetInteractionStore;
|
||||||
disableAssetSelect?: boolean;
|
disableAssetSelect?: boolean;
|
||||||
showArchiveIcon?: boolean;
|
showArchiveIcon?: boolean;
|
||||||
viewport: Viewport;
|
viewport: Viewport;
|
||||||
onIntersected?: (() => void) | undefined;
|
onIntersected?: (() => void) | undefined;
|
||||||
showAssetName?: boolean;
|
showAssetName?: boolean;
|
||||||
|
isShowDeleteConfirmation?: boolean;
|
||||||
onPrevious?: (() => Promise<AssetResponseDto | undefined>) | undefined;
|
onPrevious?: (() => Promise<AssetResponseDto | undefined>) | undefined;
|
||||||
onNext?: (() => Promise<AssetResponseDto | undefined>) | undefined;
|
onNext?: (() => Promise<AssetResponseDto | undefined>) | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
let {
|
let {
|
||||||
assets = $bindable(),
|
assets = $bindable(),
|
||||||
selectedAssets = $bindable(new Set()),
|
assetInteractionStore = $bindable(),
|
||||||
disableAssetSelect = false,
|
disableAssetSelect = false,
|
||||||
showArchiveIcon = false,
|
showArchiveIcon = false,
|
||||||
viewport,
|
viewport,
|
||||||
onIntersected = undefined,
|
onIntersected = undefined,
|
||||||
showAssetName = false,
|
showAssetName = false,
|
||||||
|
isShowDeleteConfirmation = $bindable(false),
|
||||||
onPrevious = undefined,
|
onPrevious = undefined,
|
||||||
onNext = undefined,
|
onNext = undefined,
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
|
|
||||||
let { isViewing: isViewerOpen, asset: viewingAsset, setAsset } = assetViewingStore;
|
let { isViewing: isViewerOpen, asset: viewingAsset, setAsset } = assetViewingStore;
|
||||||
|
|
||||||
|
const { assetSelectionCandidates, assetSelectionStart, selectedAssets, isMultiSelectState } = assetInteractionStore;
|
||||||
|
|
||||||
|
let showShortcuts = $state(false);
|
||||||
let currentViewAssetIndex = 0;
|
let currentViewAssetIndex = 0;
|
||||||
let isMultiSelectionMode = $derived(selectedAssets.size > 0);
|
let isMultiSelectionMode = $derived($selectedAssets.size > 0);
|
||||||
|
let shiftKeyIsDown = $state(false);
|
||||||
|
let lastAssetMouseEvent: AssetResponseDto | null = $state(null);
|
||||||
|
|
||||||
const viewAssetHandler = async (asset: AssetResponseDto) => {
|
const viewAssetHandler = async (asset: AssetResponseDto) => {
|
||||||
currentViewAssetIndex = assets.findIndex((a) => a.id == asset.id);
|
currentViewAssetIndex = assets.findIndex((a) => a.id == asset.id);
|
||||||
|
@ -52,18 +65,146 @@
|
||||||
await navigate({ targetRoute: 'current', assetId: $viewingAsset.id });
|
await navigate({ targetRoute: 'current', assetId: $viewingAsset.id });
|
||||||
};
|
};
|
||||||
|
|
||||||
const selectAssetHandler = (asset: AssetResponseDto) => {
|
const selectAllAssets = () => {
|
||||||
let temporary = new Set(selectedAssets);
|
assetInteractionStore.selectAssets(assets);
|
||||||
|
};
|
||||||
|
|
||||||
if (selectedAssets.has(asset)) {
|
const deselectAllAssets = () => {
|
||||||
temporary.delete(asset);
|
cancelMultiselect(assetInteractionStore);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onKeyDown = (event: KeyboardEvent) => {
|
||||||
|
if (event.key === 'Shift') {
|
||||||
|
event.preventDefault();
|
||||||
|
shiftKeyIsDown = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onKeyUp = (event: KeyboardEvent) => {
|
||||||
|
if (event.key === 'Shift') {
|
||||||
|
event.preventDefault();
|
||||||
|
shiftKeyIsDown = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSelectAssets = (asset: AssetResponseDto) => {
|
||||||
|
if (!asset) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const deselect = $selectedAssets.has(asset);
|
||||||
|
|
||||||
|
// Select/deselect already loaded assets
|
||||||
|
if (deselect) {
|
||||||
|
for (const candidate of $assetSelectionCandidates || []) {
|
||||||
|
assetInteractionStore.removeAssetFromMultiselectGroup(candidate);
|
||||||
|
}
|
||||||
|
assetInteractionStore.removeAssetFromMultiselectGroup(asset);
|
||||||
} else {
|
} else {
|
||||||
temporary.add(asset);
|
for (const candidate of $assetSelectionCandidates || []) {
|
||||||
|
assetInteractionStore.selectAsset(candidate);
|
||||||
|
}
|
||||||
|
assetInteractionStore.selectAsset(asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedAssets = temporary;
|
assetInteractionStore.clearAssetSelectionCandidates();
|
||||||
|
assetInteractionStore.setAssetSelectionStart(deselect ? null : asset);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleSelectAssetCandidates = (asset: AssetResponseDto | null) => {
|
||||||
|
if (asset) {
|
||||||
|
selectAssetCandidates(asset);
|
||||||
|
}
|
||||||
|
lastAssetMouseEvent = asset;
|
||||||
|
};
|
||||||
|
|
||||||
|
const selectAssetCandidates = (endAsset: AssetResponseDto) => {
|
||||||
|
if (!shiftKeyIsDown) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const startAsset = $assetSelectionStart;
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
|
||||||
|
assetInteractionStore.setAssetSelectionCandidates(assets.slice(start, end + 1));
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSelectStart = (e: Event) => {
|
||||||
|
if ($isMultiSelectState && shiftKeyIsDown) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDelete = () => {
|
||||||
|
const hasTrashedAsset = Array.from($selectedAssets).some((asset) => asset.isTrashed);
|
||||||
|
|
||||||
|
if ($showDeleteModal && (!isTrashEnabled || hasTrashedAsset)) {
|
||||||
|
isShowDeleteConfirmation = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handlePromiseError(trashOrDelete(hasTrashedAsset));
|
||||||
|
};
|
||||||
|
|
||||||
|
const onForceDelete = () => {
|
||||||
|
if ($showDeleteModal) {
|
||||||
|
isShowDeleteConfirmation = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handlePromiseError(trashOrDelete(true));
|
||||||
|
};
|
||||||
|
|
||||||
|
const trashOrDelete = async (force: boolean = false) => {
|
||||||
|
isShowDeleteConfirmation = false;
|
||||||
|
await deleteAssets(
|
||||||
|
!(isTrashEnabled && !force),
|
||||||
|
(assetIds) => (assets = assets.filter((asset) => !assetIds.includes(asset.id))),
|
||||||
|
idsSelectedAssets,
|
||||||
|
);
|
||||||
|
assetInteractionStore.clearMultiselect();
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggleArchive = async () => {
|
||||||
|
const ids = await archiveAssets(Array.from($selectedAssets), !isAllArchived);
|
||||||
|
if (ids) {
|
||||||
|
assets.filter((asset) => !ids.includes(asset.id));
|
||||||
|
deselectAllAssets();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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() },
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($isMultiSelectState) {
|
||||||
|
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;
|
||||||
|
})(),
|
||||||
|
);
|
||||||
|
|
||||||
const handleNext = async () => {
|
const handleNext = async () => {
|
||||||
try {
|
try {
|
||||||
let asset: AssetResponseDto | undefined;
|
let asset: AssetResponseDto | undefined;
|
||||||
|
@ -124,9 +265,15 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onDestroy(() => {
|
const assetMouseEventHandler = (asset: AssetResponseDto | null) => {
|
||||||
$isViewerOpen = false;
|
if ($isMultiSelectState) {
|
||||||
});
|
handleSelectAssetCandidates(asset);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let isTrashEnabled = $derived($featureFlags.loaded && $featureFlags.trash);
|
||||||
|
let idsSelectedAssets = $derived([...$selectedAssets].map(({ id }) => id));
|
||||||
|
let isAllArchived = $derived([...$selectedAssets].every((asset) => asset.isArchived));
|
||||||
|
|
||||||
let geometry = $derived(
|
let geometry = $derived(
|
||||||
(() => {
|
(() => {
|
||||||
|
@ -147,8 +294,40 @@
|
||||||
};
|
};
|
||||||
})(),
|
})(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (!lastAssetMouseEvent) {
|
||||||
|
assetInteractionStore.clearAssetSelectionCandidates();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (!shiftKeyIsDown) {
|
||||||
|
assetInteractionStore.clearAssetSelectionCandidates();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (shiftKeyIsDown && lastAssetMouseEvent) {
|
||||||
|
selectAssetCandidates(lastAssetMouseEvent);
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:window onkeydown={onKeyDown} onkeyup={onKeyUp} onselectstart={onSelectStart} use:shortcuts={shortcutList} />
|
||||||
|
|
||||||
|
{#if isShowDeleteConfirmation}
|
||||||
|
<DeleteAssetDialog
|
||||||
|
size={idsSelectedAssets.length}
|
||||||
|
onCancel={() => (isShowDeleteConfirmation = false)}
|
||||||
|
onConfirm={() => handlePromiseError(trashOrDelete(true))}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if showShortcuts}
|
||||||
|
<ShowShortcuts onClose={() => (showShortcuts = !showShortcuts)} />
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if assets.length > 0}
|
{#if assets.length > 0}
|
||||||
<div class="relative" style="height: {geometry.containerHeight}px;width: {geometry.containerWidth}px ">
|
<div class="relative" style="height: {geometry.containerHeight}px;width: {geometry.containerWidth}px ">
|
||||||
{#each assets as asset, i (i)}
|
{#each assets as asset, i (i)}
|
||||||
|
@ -159,19 +338,21 @@
|
||||||
title={showAssetName ? asset.originalFileName : ''}
|
title={showAssetName ? asset.originalFileName : ''}
|
||||||
>
|
>
|
||||||
<Thumbnail
|
<Thumbnail
|
||||||
{asset}
|
|
||||||
readonly={disableAssetSelect}
|
readonly={disableAssetSelect}
|
||||||
onClick={(asset) => {
|
onClick={(asset) => {
|
||||||
if (isMultiSelectionMode) {
|
if (isMultiSelectionMode) {
|
||||||
selectAssetHandler(asset);
|
handleSelectAssets(asset);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void viewAssetHandler(asset);
|
void viewAssetHandler(asset);
|
||||||
}}
|
}}
|
||||||
onSelect={(asset) => selectAssetHandler(asset)}
|
onSelect={(asset) => handleSelectAssets(asset)}
|
||||||
|
onMouseEvent={() => assetMouseEventHandler(asset)}
|
||||||
onIntersected={() => (i === Math.max(1, assets.length - 7) ? onIntersected?.() : void 0)}
|
onIntersected={() => (i === Math.max(1, assets.length - 7) ? onIntersected?.() : void 0)}
|
||||||
selected={selectedAssets.has(asset)}
|
|
||||||
{showArchiveIcon}
|
{showArchiveIcon}
|
||||||
|
{asset}
|
||||||
|
selected={$selectedAssets.has(asset)}
|
||||||
|
selectionCandidate={$assetSelectionCandidates.has(asset)}
|
||||||
thumbnailWidth={geometry.boxes[i].width}
|
thumbnailWidth={geometry.boxes[i].width}
|
||||||
thumbnailHeight={geometry.boxes[i].height}
|
thumbnailHeight={geometry.boxes[i].height}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import { page } from '$app/stores';
|
import { page } from '$app/stores';
|
||||||
import UserPageLayout, { headerId } from '$lib/components/layouts/user-page-layout.svelte';
|
import UserPageLayout, { headerId } from '$lib/components/layouts/user-page-layout.svelte';
|
||||||
import GalleryViewer from '$lib/components/shared-components/gallery-viewer/gallery-viewer.svelte';
|
import GalleryViewer from '$lib/components/shared-components/gallery-viewer/gallery-viewer.svelte';
|
||||||
|
import { createAssetInteractionStore } from '$lib/stores/asset-interaction.store';
|
||||||
import SideBarSection from '$lib/components/shared-components/side-bar/side-bar-section.svelte';
|
import SideBarSection from '$lib/components/shared-components/side-bar/side-bar-section.svelte';
|
||||||
import TreeItemThumbnails from '$lib/components/shared-components/tree/tree-item-thumbnails.svelte';
|
import TreeItemThumbnails from '$lib/components/shared-components/tree/tree-item-thumbnails.svelte';
|
||||||
import TreeItems from '$lib/components/shared-components/tree/tree-items.svelte';
|
import TreeItems from '$lib/components/shared-components/tree/tree-items.svelte';
|
||||||
|
@ -10,7 +11,6 @@
|
||||||
import type { Viewport } from '$lib/stores/assets.store';
|
import type { Viewport } from '$lib/stores/assets.store';
|
||||||
import { foldersStore } from '$lib/stores/folders.store';
|
import { foldersStore } from '$lib/stores/folders.store';
|
||||||
import { buildTree, normalizeTreePath } from '$lib/utils/tree-utils';
|
import { buildTree, normalizeTreePath } from '$lib/utils/tree-utils';
|
||||||
import { type AssetResponseDto } from '@immich/sdk';
|
|
||||||
import { mdiFolder, mdiFolderHome, mdiFolderOutline } from '@mdi/js';
|
import { mdiFolder, mdiFolderHome, mdiFolderOutline } from '@mdi/js';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
let { data }: Props = $props();
|
let { data }: Props = $props();
|
||||||
|
|
||||||
let selectedAssets: Set<AssetResponseDto> = $state(new Set());
|
|
||||||
const viewport: Viewport = $state({ width: 0, height: 0 });
|
const viewport: Viewport = $state({ width: 0, height: 0 });
|
||||||
|
|
||||||
let pathSegments = $derived(data.path ? data.path.split('/') : []);
|
let pathSegments = $derived(data.path ? data.path.split('/') : []);
|
||||||
|
@ -32,6 +31,8 @@
|
||||||
let currentPath = $derived($page.url.searchParams.get(QueryParameter.PATH) || '');
|
let currentPath = $derived($page.url.searchParams.get(QueryParameter.PATH) || '');
|
||||||
let currentTreeItems = $derived(currentPath ? data.currentFolders : Object.keys(tree));
|
let currentTreeItems = $derived(currentPath ? data.currentFolders : Object.keys(tree));
|
||||||
|
|
||||||
|
const assetInteractionStore = createAssetInteractionStore();
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await foldersStore.fetchUniquePaths();
|
await foldersStore.fetchUniquePaths();
|
||||||
});
|
});
|
||||||
|
@ -79,7 +80,7 @@
|
||||||
<div bind:clientHeight={viewport.height} bind:clientWidth={viewport.width} class="mt-2">
|
<div bind:clientHeight={viewport.height} bind:clientWidth={viewport.width} class="mt-2">
|
||||||
<GalleryViewer
|
<GalleryViewer
|
||||||
assets={data.pathAssets}
|
assets={data.pathAssets}
|
||||||
bind:selectedAssets
|
{assetInteractionStore}
|
||||||
{viewport}
|
{viewport}
|
||||||
disableAssetSelect={true}
|
disableAssetSelect={true}
|
||||||
showAssetName={true}
|
showAssetName={true}
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
import AssetSelectControlBar from '$lib/components/photos-page/asset-select-control-bar.svelte';
|
import AssetSelectControlBar from '$lib/components/photos-page/asset-select-control-bar.svelte';
|
||||||
import ControlAppBar from '$lib/components/shared-components/control-app-bar.svelte';
|
import ControlAppBar from '$lib/components/shared-components/control-app-bar.svelte';
|
||||||
import GalleryViewer from '$lib/components/shared-components/gallery-viewer/gallery-viewer.svelte';
|
import GalleryViewer from '$lib/components/shared-components/gallery-viewer/gallery-viewer.svelte';
|
||||||
|
import { cancelMultiselect } from '$lib/utils/asset-utils';
|
||||||
|
import { createAssetInteractionStore } from '$lib/stores/asset-interaction.store';
|
||||||
import SearchBar from '$lib/components/shared-components/search-bar/search-bar.svelte';
|
import SearchBar from '$lib/components/shared-components/search-bar/search-bar.svelte';
|
||||||
import { AppRoute, QueryParameter } from '$lib/constants';
|
import { AppRoute, QueryParameter } from '$lib/constants';
|
||||||
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
|
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
|
||||||
|
@ -58,13 +60,15 @@
|
||||||
let isLoading = $state(true);
|
let isLoading = $state(true);
|
||||||
let scrollY = $state(0);
|
let scrollY = $state(0);
|
||||||
let scrollYHistory = 0;
|
let scrollYHistory = 0;
|
||||||
let selectedAssets: Set<AssetResponseDto> = $state(new Set());
|
|
||||||
|
const assetInteractionStore = createAssetInteractionStore();
|
||||||
|
const { selectedAssets } = assetInteractionStore;
|
||||||
|
|
||||||
type SearchTerms = MetadataSearchDto & Pick<SmartSearchDto, 'query'>;
|
type SearchTerms = MetadataSearchDto & Pick<SmartSearchDto, 'query'>;
|
||||||
|
|
||||||
let isMultiSelectionMode = $derived(selectedAssets.size > 0);
|
let isMultiSelectionMode = $derived($selectedAssets.size > 0);
|
||||||
let isAllArchived = $derived([...selectedAssets].every((asset) => asset.isArchived));
|
let isAllArchived = $derived([...$selectedAssets].every((asset) => asset.isArchived));
|
||||||
let isAllFavorite = $derived([...selectedAssets].every((asset) => asset.isFavorite));
|
let isAllFavorite = $derived([...$selectedAssets].every((asset) => asset.isFavorite));
|
||||||
let searchQuery = $derived($page.url.searchParams.get(QueryParameter.QUERY));
|
let searchQuery = $derived($page.url.searchParams.get(QueryParameter.QUERY));
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
@ -81,7 +85,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMultiSelectionMode) {
|
if (isMultiSelectionMode) {
|
||||||
selectedAssets = new Set();
|
$selectedAssets = new Set();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!$preventRaceConditionSearchBar) {
|
if (!$preventRaceConditionSearchBar) {
|
||||||
|
@ -125,7 +129,7 @@
|
||||||
searchResultAssets = searchResultAssets.filter((a: AssetResponseDto) => !assetIdSet.has(a.id));
|
searchResultAssets = searchResultAssets.filter((a: AssetResponseDto) => !assetIdSet.has(a.id));
|
||||||
};
|
};
|
||||||
const handleSelectAll = () => {
|
const handleSelectAll = () => {
|
||||||
selectedAssets = new Set(searchResultAssets);
|
assetInteractionStore.selectAssets(searchResultAssets);
|
||||||
};
|
};
|
||||||
|
|
||||||
async function onSearchQueryUpdate() {
|
async function onSearchQueryUpdate() {
|
||||||
|
@ -216,8 +220,10 @@
|
||||||
const triggerAssetUpdate = () => (searchResultAssets = searchResultAssets);
|
const triggerAssetUpdate = () => (searchResultAssets = searchResultAssets);
|
||||||
|
|
||||||
const onAddToAlbum = (assetIds: string[]) => {
|
const onAddToAlbum = (assetIds: string[]) => {
|
||||||
const assetIdSet = new Set(assetIds);
|
if (terms.isNotInAlbum.toString() == 'true') {
|
||||||
searchResultAssets = searchResultAssets.filter((a: AssetResponseDto) => !assetIdSet.has(a.id));
|
const assetIdSet = new Set(assetIds);
|
||||||
|
searchResultAssets = searchResultAssets.filter((a: AssetResponseDto) => !assetIdSet.has(a.id));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function getObjectKeys<T extends object>(obj: T): (keyof T)[] {
|
function getObjectKeys<T extends object>(obj: T): (keyof T)[] {
|
||||||
|
@ -230,7 +236,7 @@
|
||||||
<section>
|
<section>
|
||||||
{#if isMultiSelectionMode}
|
{#if isMultiSelectionMode}
|
||||||
<div class="fixed z-[100] top-0 left-0 w-full">
|
<div class="fixed z-[100] top-0 left-0 w-full">
|
||||||
<AssetSelectControlBar assets={selectedAssets} clearSelect={() => (selectedAssets = new Set())}>
|
<AssetSelectControlBar assets={$selectedAssets} clearSelect={() => cancelMultiselect(assetInteractionStore)}>
|
||||||
<CreateSharedLink />
|
<CreateSharedLink />
|
||||||
<CircleIconButton title={$t('select_all')} icon={mdiSelectAll} onclick={handleSelectAll} />
|
<CircleIconButton title={$t('select_all')} icon={mdiSelectAll} onclick={handleSelectAll} />
|
||||||
<ButtonContextMenu icon={mdiPlus} title={$t('add_to')}>
|
<ButtonContextMenu icon={mdiPlus} title={$t('add_to')}>
|
||||||
|
@ -321,7 +327,7 @@
|
||||||
{#if searchResultAssets.length > 0}
|
{#if searchResultAssets.length > 0}
|
||||||
<GalleryViewer
|
<GalleryViewer
|
||||||
assets={searchResultAssets}
|
assets={searchResultAssets}
|
||||||
bind:selectedAssets
|
{assetInteractionStore}
|
||||||
onIntersected={loadNextPage}
|
onIntersected={loadNextPage}
|
||||||
showArchiveIcon={true}
|
showArchiveIcon={true}
|
||||||
{viewport}
|
{viewport}
|
||||||
|
|
Loading…
Reference in a new issue