From dc4db405d2991d3ec6a114f3b08d3fccd057d3ee Mon Sep 17 00:00:00 2001
From: Wolfgang Müller
Date: Thu, 13 Feb 2025 17:52:16 +0100
Subject: frontend: Migrate to Svelte 5

---
 frontend/src/lib/dialogs/EditArtist.svelte | 39 ++++++++++++------------------
 1 file changed, 15 insertions(+), 24 deletions(-)

(limited to 'frontend/src/lib/dialogs/EditArtist.svelte')

diff --git a/frontend/src/lib/dialogs/EditArtist.svelte b/frontend/src/lib/dialogs/EditArtist.svelte
index dd08bc6..fa5c143 100644
--- a/frontend/src/lib/dialogs/EditArtist.svelte
+++ b/frontend/src/lib/dialogs/EditArtist.svelte
@@ -1,46 +1,37 @@
 <script lang="ts">
-	import { deleteArtists, updateArtists, type ArtistInput } from '$gql/Mutations';
-	import { itemEquals } from '$gql/Utils';
-	import { type Artist } from '$gql/graphql';
+	import { deleteArtists, updateArtists } from '$gql/Mutations';
+	import { omitIdentifiers } from '$gql/Utils';
+	import type { Artist, UpdateArtistInput } from '$gql/graphql';
 	import { toastFinally } from '$lib/Toasts';
 	import { confirmDeletion } from '$lib/Utils';
 	import DeleteButton from '$lib/components/DeleteButton.svelte';
 	import Dialog from '$lib/components/Dialog.svelte';
-	import SubmitButton from '$lib/components/SubmitButton.svelte';
 	import ArtistForm from '$lib/forms/ArtistForm.svelte';
 	import { getContextClient } from '@urql/svelte';
-	import { closeModal } from 'svelte-modals';
+	import type { ModalProps } from 'svelte-modals';
 
 	const client = getContextClient();
 
-	export let isOpen: boolean;
+	interface Props extends ModalProps {
+		artist: Artist;
+	}
 
-	export let artist: Artist;
-	const original = structuredClone(artist);
-	$: pending = !itemEquals(artist, original);
+	let { artist, ...modal }: Props = $props();
+	const initial = omitIdentifiers(artist);
 
-	function save(event: CustomEvent<ArtistInput>) {
-		updateArtists(client, { ids: artist.id, input: event.detail })
-			.then(closeModal)
-			.catch(toastFinally);
+	function submit(input: UpdateArtistInput) {
+		updateArtists(client, { ids: artist.id, input }).then(modal.close).catch(toastFinally);
 	}
 
 	function deleteArtist() {
 		confirmDeletion('Artist', artist.name, () => {
-			deleteArtists(client, { ids: artist.id }).then(closeModal).catch(toastFinally);
+			deleteArtists(client, { ids: artist.id }).then(modal.close).catch(toastFinally);
 		});
 	}
 </script>
 
-<Dialog {isOpen}>
-	<svelte:fragment slot="header">
-		<h2>Edit Artist</h2>
-	</svelte:fragment>
-	<ArtistForm bind:artist on:submit={save}>
-		<div class="flex gap-4">
-			<DeleteButton on:click={deleteArtist} />
-			<div class="grow" />
-			<SubmitButton active={pending} />
-		</div>
+<Dialog title="Edit Artist" {...modal}>
+	<ArtistForm {initial} {submit}>
+		<DeleteButton onclick={deleteArtist} />
 	</ArtistForm>
 </Dialog>
-- 
cgit v1.2.3-2-gb3c3

