fix: album asset viewer (#19252)

This commit is contained in:
Daniel Dietzler 2025-06-19 16:09:23 +02:00 committed by GitHub
parent f99c6feac5
commit caf11fbb96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 89 deletions

View File

@ -1,10 +1,7 @@
<script lang="ts"> <script lang="ts">
import Portal from '$lib/components/shared-components/portal/portal.svelte';
import { modalManager } from '$lib/managers/modal-manager.svelte'; import { modalManager } from '$lib/managers/modal-manager.svelte';
import MapModal from '$lib/modals/MapModal.svelte'; import MapModal from '$lib/modals/MapModal.svelte';
import { assetViewingStore } from '$lib/stores/asset-viewing.store'; import { assetViewingStore } from '$lib/stores/asset-viewing.store';
import { handlePromiseError } from '$lib/utils';
import { navigate } from '$lib/utils/navigation';
import { getAlbumInfo, type AlbumResponseDto, type MapMarkerResponseDto } from '@immich/sdk'; import { getAlbumInfo, type AlbumResponseDto, type MapMarkerResponseDto } from '@immich/sdk';
import { IconButton } from '@immich/ui'; import { IconButton } from '@immich/ui';
import { mdiMapOutline } from '@mdi/js'; import { mdiMapOutline } from '@mdi/js';
@ -17,9 +14,7 @@
let { album }: Props = $props(); let { album }: Props = $props();
let abortController: AbortController; let abortController: AbortController;
let { isViewing: showAssetViewer, asset: viewingAsset, setAssetId } = assetViewingStore; let { setAssetId } = assetViewingStore;
let viewingAssets: string[] = $state([]);
let viewingAssetCursor = 0;
let mapMarkers: MapMarkerResponseDto[] = $state([]); let mapMarkers: MapMarkerResponseDto[] = $state([]);
@ -61,37 +56,9 @@
const assetIds = await modalManager.show(MapModal, { mapMarkers }); const assetIds = await modalManager.show(MapModal, { mapMarkers });
if (assetIds) { if (assetIds) {
viewingAssets = assetIds;
viewingAssetCursor = 0;
await setAssetId(assetIds[0]); await setAssetId(assetIds[0]);
} }
} }
async function navigateNext() {
if (viewingAssetCursor < viewingAssets.length - 1) {
await setAssetId(viewingAssets[++viewingAssetCursor]);
return true;
}
return false;
}
async function navigatePrevious() {
if (viewingAssetCursor > 0) {
await setAssetId(viewingAssets[--viewingAssetCursor]);
return true;
}
return false;
}
async function navigateRandom() {
if (viewingAssets.length <= 0) {
return undefined;
}
const index = Math.floor(Math.random() * viewingAssets.length);
const asset = await setAssetId(viewingAssets[index]);
return asset;
}
</script> </script>
<IconButton <IconButton
@ -102,22 +69,3 @@
onclick={openMap} onclick={openMap}
aria-label={$t('map')} aria-label={$t('map')}
/> />
<Portal target="body">
{#if $showAssetViewer}
{#await import('../../../lib/components/asset-viewer/asset-viewer.svelte') then { default: AssetViewer }}
<AssetViewer
asset={$viewingAsset}
showNavigation={viewingAssets.length > 1}
onNext={navigateNext}
onPrevious={navigatePrevious}
onRandom={navigateRandom}
onClose={() => {
assetViewingStore.showAssetViewer(false);
handlePromiseError(navigate({ targetRoute: 'current', assetId: null }));
}}
isShared={false}
/>
{/await}
{/if}
</Portal>

View File

@ -12,7 +12,6 @@
import ChangeDate from '$lib/components/shared-components/change-date.svelte'; import ChangeDate from '$lib/components/shared-components/change-date.svelte';
import Scrubber from '$lib/components/shared-components/scrubber/scrubber.svelte'; import Scrubber from '$lib/components/shared-components/scrubber/scrubber.svelte';
import { AppRoute, AssetAction } from '$lib/constants'; import { AppRoute, AssetAction } from '$lib/constants';
import { albumMapViewManager } from '$lib/managers/album-view-map.manager.svelte';
import { authManager } from '$lib/managers/auth-manager.svelte'; import { authManager } from '$lib/managers/auth-manager.svelte';
import { modalManager } from '$lib/managers/modal-manager.svelte'; import { modalManager } from '$lib/managers/modal-manager.svelte';
import type { MonthGroup } from '$lib/managers/timeline-manager/month-group.svelte'; import type { MonthGroup } from '$lib/managers/timeline-manager/month-group.svelte';
@ -911,8 +910,7 @@
</section> </section>
</section> </section>
{#if !albumMapViewManager.isInMapView} <Portal target="body">
<Portal target="body">
{#if $showAssetViewer} {#if $showAssetViewer}
{#await import('../asset-viewer/asset-viewer.svelte') then { default: AssetViewer }} {#await import('../asset-viewer/asset-viewer.svelte') then { default: AssetViewer }}
<AssetViewer <AssetViewer
@ -931,8 +929,7 @@
/> />
{/await} {/await}
{/if} {/if}
</Portal> </Portal>
{/if}
<style> <style>
#asset-grid { #asset-grid {

View File

@ -1,13 +0,0 @@
class AlbumMapViewManager {
#isInMapView = $state(false);
get isInMapView() {
return this.#isInMapView;
}
set isInMapView(isInMapView: boolean) {
this.#isInMapView = isInMapView;
}
}
export const albumMapViewManager = new AlbumMapViewManager();