2023-11-30 04:52:28 +01:00
|
|
|
<script lang="ts">
|
2024-02-14 06:38:57 -08:00
|
|
|
import type { AssetResponseDto } from '@immich/sdk';
|
2023-11-30 04:52:28 +01:00
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
import ConfirmDialogue from './confirm-dialogue.svelte';
|
2024-02-18 20:18:40 +01:00
|
|
|
import LoadingSpinner from './loading-spinner.svelte';
|
|
|
|
import { delay } from '$lib/utils/asset-utils';
|
|
|
|
import { timeToLoadTheMap } from '$lib/constants';
|
|
|
|
|
2023-11-30 04:52:28 +01:00
|
|
|
export const title = 'Change Location';
|
|
|
|
export let asset: AssetResponseDto | undefined = undefined;
|
|
|
|
|
|
|
|
interface Point {
|
|
|
|
lng: number;
|
|
|
|
lat: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher<{
|
|
|
|
cancel: void;
|
|
|
|
confirm: Point;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
$: lat = asset?.exifInfo?.latitude || 0;
|
|
|
|
$: lng = asset?.exifInfo?.longitude || 0;
|
|
|
|
$: zoom = lat && lng ? 15 : 1;
|
|
|
|
|
|
|
|
let point: Point | null = null;
|
|
|
|
|
|
|
|
const handleCancel = () => dispatch('cancel');
|
|
|
|
|
|
|
|
const handleSelect = (selected: Point) => {
|
|
|
|
point = selected;
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleConfirm = () => {
|
2024-02-02 04:18:00 +01:00
|
|
|
if (point) {
|
2023-11-30 04:52:28 +01:00
|
|
|
dispatch('confirm', point);
|
2024-02-02 04:18:00 +01:00
|
|
|
} else {
|
|
|
|
dispatch('cancel');
|
2023-11-30 04:52:28 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<ConfirmDialogue
|
|
|
|
confirmColor="primary"
|
|
|
|
cancelColor="secondary"
|
|
|
|
title="Change Location"
|
2023-12-19 16:49:09 +01:00
|
|
|
width={800}
|
2023-11-30 04:52:28 +01:00
|
|
|
on:confirm={handleConfirm}
|
|
|
|
on:cancel={handleCancel}
|
|
|
|
>
|
|
|
|
<div slot="prompt" class="flex flex-col w-full h-full gap-2">
|
|
|
|
<label for="datetime">Pick a location</label>
|
2023-12-19 16:49:09 +01:00
|
|
|
<div class="h-[500px] min-h-[300px] w-full">
|
2024-02-18 20:18:40 +01:00
|
|
|
{#await import('../shared-components/map/map.svelte')}
|
|
|
|
{#await delay(timeToLoadTheMap) then}
|
|
|
|
<!-- show the loading spinner only if loading the map takes too much time -->
|
|
|
|
<div class="flex items-center justify-center h-full w-full">
|
|
|
|
<LoadingSpinner />
|
|
|
|
</div>
|
|
|
|
{/await}
|
|
|
|
{:then component}
|
|
|
|
<svelte:component
|
|
|
|
this={component.default}
|
|
|
|
mapMarkers={lat && lng && asset ? [{ id: asset.id, lat, lon: lng }] : []}
|
|
|
|
{zoom}
|
|
|
|
center={lat && lng ? { lat, lng } : undefined}
|
|
|
|
simplified={true}
|
|
|
|
clickable={true}
|
|
|
|
on:clickedPoint={({ detail: point }) => handleSelect(point)}
|
|
|
|
/>
|
|
|
|
{/await}
|
2023-11-30 04:52:28 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</ConfirmDialogue>
|