2024-08-14 17:54:50 +03:00
|
|
|
<script lang="ts">
|
2025-05-02 19:34:53 +02:00
|
|
|
import { shortcut } from '$lib/actions/shortcut';
|
|
|
|
|
import ConfirmDialog from '$lib/components/shared-components/dialog/confirm-dialog.svelte';
|
|
|
|
|
import { editTypes, showCancelConfirmDialog } from '$lib/stores/asset-editor.store';
|
2024-08-14 17:54:50 +03:00
|
|
|
import { websocketEvents } from '$lib/stores/websocket';
|
|
|
|
|
import { type AssetResponseDto } from '@immich/sdk';
|
|
|
|
|
import { mdiClose } from '@mdi/js';
|
|
|
|
|
import { onMount } from 'svelte';
|
|
|
|
|
import { t } from 'svelte-i18n';
|
2025-05-02 19:34:53 +02:00
|
|
|
import CircleIconButton from '../../elements/buttons/circle-icon-button.svelte';
|
2024-08-14 17:54:50 +03:00
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
|
return websocketEvents.on('on_asset_update', (assetUpdate) => {
|
|
|
|
|
if (assetUpdate.id === asset.id) {
|
|
|
|
|
asset = assetUpdate;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
interface Props {
|
|
|
|
|
asset: AssetResponseDto;
|
|
|
|
|
onUpdateSelectedType: (type: string) => void;
|
|
|
|
|
onClose: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let { asset = $bindable(), onUpdateSelectedType, onClose }: Props = $props();
|
2024-08-14 17:54:50 +03:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
let selectedType: string = $state(editTypes[0].name);
|
|
|
|
|
let selectedTypeObj = $derived(editTypes.find((t) => t.name === selectedType) || editTypes[0]);
|
2024-08-14 17:54:50 +03:00
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
onUpdateSelectedType(selectedType);
|
|
|
|
|
}, 1);
|
2025-05-02 19:34:53 +02:00
|
|
|
|
2024-08-14 17:54:50 +03:00
|
|
|
function selectType(name: string) {
|
|
|
|
|
selectedType = name;
|
|
|
|
|
onUpdateSelectedType(selectedType);
|
|
|
|
|
}
|
2025-05-02 19:34:53 +02:00
|
|
|
|
|
|
|
|
const onConfirm = () => (typeof $showCancelConfirmDialog === 'boolean' ? null : $showCancelConfirmDialog());
|
2024-08-14 17:54:50 +03:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<svelte:window use:shortcut={{ shortcut: { key: 'Escape' }, onShortcut: onClose }} />
|
|
|
|
|
|
|
|
|
|
<section class="relative p-2 dark:bg-immich-dark-bg dark:text-immich-dark-fg">
|
|
|
|
|
<div class="flex place-items-center gap-2">
|
2024-11-14 08:43:25 -06:00
|
|
|
<CircleIconButton icon={mdiClose} title={$t('close')} onclick={onClose} />
|
2024-08-14 17:54:50 +03:00
|
|
|
<p class="text-lg text-immich-fg dark:text-immich-dark-fg capitalize">{$t('editor')}</p>
|
|
|
|
|
</div>
|
|
|
|
|
<section class="px-4 py-4">
|
|
|
|
|
<ul class="flex w-full justify-around">
|
|
|
|
|
{#each editTypes as etype (etype.name)}
|
|
|
|
|
<li>
|
|
|
|
|
<CircleIconButton
|
|
|
|
|
color={etype.name === selectedType ? 'primary' : 'opaque'}
|
|
|
|
|
icon={etype.icon}
|
|
|
|
|
title={etype.name}
|
2024-11-14 08:43:25 -06:00
|
|
|
onclick={() => selectType(etype.name)}
|
2024-08-14 17:54:50 +03:00
|
|
|
/>
|
|
|
|
|
</li>
|
|
|
|
|
{/each}
|
|
|
|
|
</ul>
|
|
|
|
|
</section>
|
|
|
|
|
<section>
|
2024-11-14 08:43:25 -06:00
|
|
|
<selectedTypeObj.component />
|
2024-08-14 17:54:50 +03:00
|
|
|
</section>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
{#if $showCancelConfirmDialog}
|
|
|
|
|
<ConfirmDialog
|
|
|
|
|
title={$t('editor_close_without_save_title')}
|
|
|
|
|
prompt={$t('editor_close_without_save_prompt')}
|
|
|
|
|
cancelText={$t('no')}
|
|
|
|
|
cancelColor="secondary"
|
2025-03-14 09:37:56 -04:00
|
|
|
confirmColor="danger"
|
2024-08-14 17:54:50 +03:00
|
|
|
confirmText={$t('close')}
|
2025-05-02 19:34:53 +02:00
|
|
|
onClose={(confirmed) => (confirmed ? onConfirm() : ($showCancelConfirmDialog = false))}
|
2024-08-14 17:54:50 +03:00
|
|
|
/>
|
|
|
|
|
{/if}
|