Skip to content

Commit f89e741

Browse files
authored
fix(web): delete action closes asset viewer in asset view (#15469)
fixes #14647
1 parent e2c34f1 commit f89e741

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

web/src/lib/components/asset-viewer/actions/action.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ export type Action = {
1919
[K in AssetAction]: { type: K } & ActionMap[K];
2020
}[AssetAction];
2121
export type OnAction = (action: Action) => void;
22+
export type PreAction = (action: Action) => void;

web/src/lib/components/asset-viewer/actions/delete-action.svelte

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
import { deleteAssets, type AssetResponseDto } from '@immich/sdk';
1515
import { mdiDeleteForeverOutline, mdiDeleteOutline } from '@mdi/js';
1616
import { t } from 'svelte-i18n';
17-
import type { OnAction } from './action';
17+
import type { OnAction, PreAction } from './action';
1818
1919
interface Props {
2020
asset: AssetResponseDto;
2121
onAction: OnAction;
22+
preAction: PreAction;
2223
}
2324
24-
let { asset, onAction }: Props = $props();
25+
let { asset, onAction, preAction }: Props = $props();
2526
2627
let showConfirmModal = $state(false);
2728
@@ -41,6 +42,7 @@
4142
4243
const trashAsset = async () => {
4344
try {
45+
preAction({ type: AssetAction.TRASH, asset });
4446
await deleteAssets({ assetBulkDeleteDto: { ids: [asset.id] } });
4547
onAction({ type: AssetAction.TRASH, asset });
4648

web/src/lib/components/asset-viewer/asset-viewer-nav-bar.svelte

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import { goto } from '$app/navigation';
3-
import type { OnAction } from '$lib/components/asset-viewer/actions/action';
3+
import type { OnAction, PreAction } from '$lib/components/asset-viewer/actions/action';
44
import AddToAlbumAction from '$lib/components/asset-viewer/actions/add-to-album-action.svelte';
55
import ArchiveAction from '$lib/components/asset-viewer/actions/archive-action.svelte';
66
import CloseAction from '$lib/components/asset-viewer/actions/close-action.svelte';
@@ -58,6 +58,7 @@
5858
showSlideshow?: boolean;
5959
onZoomImage: () => void;
6060
onCopyImage?: () => Promise<void>;
61+
preAction: PreAction;
6162
onAction: OnAction;
6263
onRunJob: (name: AssetJobName) => void;
6364
onPlaySlideshow: () => void;
@@ -76,6 +77,7 @@
7677
showSlideshow = false,
7778
onZoomImage,
7879
onCopyImage,
80+
preAction,
7981
onAction,
8082
onRunJob,
8183
onPlaySlideshow,
@@ -149,7 +151,7 @@
149151
{/if} -->
150152

151153
{#if isOwner}
152-
<DeleteAction {asset} {onAction} />
154+
<DeleteAction {asset} {onAction} {preAction} />
153155

154156
<ButtonContextMenu direction="left" align="top-right" color="opaque" title={$t('more')} icon={mdiDotsVertical}>
155157
{#if showSlideshow}

web/src/lib/components/asset-viewer/asset-viewer.svelte

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import { focusTrap } from '$lib/actions/focus-trap';
3-
import type { Action, OnAction } from '$lib/components/asset-viewer/actions/action';
3+
import type { Action, OnAction, PreAction } from '$lib/components/asset-viewer/actions/action';
44
import MotionPhotoAction from '$lib/components/asset-viewer/actions/motion-photo-action.svelte';
55
import NextAssetAction from '$lib/components/asset-viewer/actions/next-asset-action.svelte';
66
import PreviousAssetAction from '$lib/components/asset-viewer/actions/previous-asset-action.svelte';
@@ -58,6 +58,7 @@
5858
isShared?: boolean;
5959
album?: AlbumResponseDto | null;
6060
person?: PersonResponseDto | null;
61+
preAction?: PreAction | undefined;
6162
onAction?: OnAction | undefined;
6263
reactions?: ActivityResponseDto[];
6364
onClose: (dto: { asset: AssetResponseDto }) => void;
@@ -75,6 +76,7 @@
7576
isShared = false,
7677
album = null,
7778
person = null,
79+
preAction = undefined,
7880
onAction = undefined,
7981
reactions = $bindable([]),
8082
onClose,
@@ -366,7 +368,9 @@
366368
const handleStackedAssetMouseEvent = (isMouseOver: boolean, asset: AssetResponseDto) => {
367369
previewStackedAsset = isMouseOver ? asset : undefined;
368370
};
369-
371+
const handlePreAction = (action: Action) => {
372+
preAction?.(action);
373+
};
370374
const handleAction = async (action: Action) => {
371375
switch (action.type) {
372376
case AssetAction.ADD_TO_ALBUM: {
@@ -431,6 +435,7 @@
431435
showSlideshow={true}
432436
onZoomImage={zoomToggle}
433437
onCopyImage={copyImage}
438+
preAction={handlePreAction}
434439
onAction={handleAction}
435440
onRunJob={handleRunJob}
436441
onPlaySlideshow={() => ($slideshowState = SlideshowState.PlaySlideshow)}

web/src/lib/components/photos-page/asset-grid.svelte

+6-3
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@
517517
518518
const handleNext = async () => {
519519
const nextAsset = await $assetStore.getNextAsset($viewingAsset);
520-
521520
if (nextAsset) {
522521
const preloadAsset = await $assetStore.getNextAsset(nextAsset);
523522
assetViewingStore.setAsset(nextAsset, preloadAsset ? [preloadAsset] : []);
@@ -546,7 +545,7 @@
546545
await navigate({ targetRoute: 'current', assetId: null, assetGridRouteSearchParams: $gridScrollTarget });
547546
};
548547
549-
const handleAction = async (action: Action) => {
548+
const handlePreAction = async (action: Action) => {
550549
switch (action.type) {
551550
case removeAction:
552551
case AssetAction.TRASH:
@@ -560,7 +559,10 @@
560559
assetStore.removeAssets([action.asset.id]);
561560
break;
562561
}
563-
562+
}
563+
};
564+
const handleAction = (action: Action) => {
565+
switch (action.type) {
564566
case AssetAction.ARCHIVE:
565567
case AssetAction.UNARCHIVE:
566568
case AssetAction.FAVORITE:
@@ -928,6 +930,7 @@
928930
{isShared}
929931
{album}
930932
{person}
933+
preAction={handlePreAction}
931934
onAction={handleAction}
932935
onPrevious={handlePrevious}
933936
onNext={handleNext}

0 commit comments

Comments
 (0)