From 8b6911492419594f8e671bef7a041347de27bbf4 Mon Sep 17 00:00:00 2001 From: David Bourgault Date: Wed, 26 Feb 2025 22:01:29 -0500 Subject: [PATCH] feat(web): remember last chosen map location when editing (#16366) Uses a global store to remember the last location chosen by a user when editing asset locations. This fixes an annoyance when adding location data to multiple assets in a row and having to zoom in the same area everytime. --- .../shared-components/change-location.svelte | 27 ++++++++++++------- web/src/lib/stores/asset-editor.store.ts | 1 + 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/web/src/lib/components/shared-components/change-location.svelte b/web/src/lib/components/shared-components/change-location.svelte index 5970b91160..d2dbeb5488 100644 --- a/web/src/lib/components/shared-components/change-location.svelte +++ b/web/src/lib/components/shared-components/change-location.svelte @@ -2,6 +2,7 @@ import ConfirmDialog from './dialog/confirm-dialog.svelte'; import { timeDebounceOnSearch } from '$lib/constants'; import { handleError } from '$lib/utils/handle-error'; + import { lastChosenLocation } from '$lib/stores/asset-editor.store'; import { clickOutside } from '$lib/actions/click-outside'; import LoadingSpinner from './loading-spinner.svelte'; @@ -13,6 +14,7 @@ import { t } from 'svelte-i18n'; import CoordinatesInput from '$lib/components/shared-components/coordinates-input.svelte'; import Map from '$lib/components/shared-components/map/map.svelte'; + import { get } from 'svelte/store'; interface Point { lng: number; @@ -36,9 +38,15 @@ let hideSuggestion = $state(false); let mapElement = $state>(); - let lat = $derived(asset?.exifInfo?.latitude ?? undefined); - let lng = $derived(asset?.exifInfo?.longitude ?? undefined); - let zoom = $derived(lat !== undefined && lng !== undefined ? 12.5 : 1); + let previousLocation = get(lastChosenLocation); + + let assetLat = $derived(asset?.exifInfo?.latitude ?? undefined); + let assetLng = $derived(asset?.exifInfo?.longitude ?? undefined); + + let mapLat = $derived(assetLat ?? previousLocation?.lat ?? undefined); + let mapLng = $derived(assetLng ?? previousLocation?.lng ?? undefined); + + let zoom = $derived(mapLat !== undefined && mapLng !== undefined ? 12.5 : 1); $effect(() => { if (places) { @@ -53,6 +61,7 @@ const handleConfirm = () => { if (point) { + lastChosenLocation.set(point); onConfirm(point); } else { onCancel(); @@ -160,12 +169,12 @@ {:then { default: Map }} (point = selected)} @@ -183,8 +192,8 @@
{ point = { lat, lng }; mapElement?.addClipMapMarker(lng, lat); diff --git a/web/src/lib/stores/asset-editor.store.ts b/web/src/lib/stores/asset-editor.store.ts index 4d2f8977ee..ec06c2cef5 100644 --- a/web/src/lib/stores/asset-editor.store.ts +++ b/web/src/lib/stores/asset-editor.store.ts @@ -17,6 +17,7 @@ export const normaizedRorateDegrees = derived(rotateDegrees, (v) => { export const changedOriention = derived(normaizedRorateDegrees, () => get(normaizedRorateDegrees) % 180 > 0); //-----other export const showCancelConfirmDialog = writable(false); +export const lastChosenLocation = writable<{ lng: number; lat: number } | null>(null); export const editTypes = [ {