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/UpdateComics.svelte | 139 +++++++++++++++------------
 1 file changed, 77 insertions(+), 62 deletions(-)

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

diff --git a/frontend/src/lib/dialogs/UpdateComics.svelte b/frontend/src/lib/dialogs/UpdateComics.svelte
index 8de9622..483e379 100644
--- a/frontend/src/lib/dialogs/UpdateComics.svelte
+++ b/frontend/src/lib/dialogs/UpdateComics.svelte
@@ -3,94 +3,109 @@
 	import { artistList, characterList, circleList, comicTagList, worldList } from '$gql/Queries';
 	import { categories, censorships, directions, languages, layouts, ratings } from '$lib/Enums';
 	import { toastFinally } from '$lib/Toasts';
-	import { UpdateComicsControls } from '$lib/Update';
+	import { UpdateComicsControls } from '$lib/Update.svelte';
 	import Dialog from '$lib/components/Dialog.svelte';
-	import Labelled from '$lib/components/Labelled.svelte';
 	import LabelledBlock from '$lib/components/LabelledBlock.svelte';
 	import Select from '$lib/components/Select.svelte';
 	import SubmitButton from '$lib/components/SubmitButton.svelte';
 	import { getContextClient } from '@urql/svelte';
-	import { closeModal } from 'svelte-modals';
+	import type { ModalProps } from 'svelte-modals';
 	import UpdateModeSelector from './components/UpdateModeSelector.svelte';
 
 	const client = getContextClient();
 
-	export let isOpen: boolean;
-	export let ids: number[];
+	interface Props extends ModalProps {
+		ids: number[];
+	}
 
-	$: tagsQuery = comicTagList(client);
-	$: artistsQuery = artistList(client);
-	$: charactersQuery = characterList(client);
-	$: circlesQuery = circleList(client);
-	$: worldsQuery = worldList(client);
+	let { ids, ...modal }: Props = $props();
 
-	$: tags = $tagsQuery.data?.comicTags.edges;
-	$: artists = $artistsQuery.data?.artists.edges;
-	$: characters = $charactersQuery.data?.characters.edges;
-	$: circles = $circlesQuery.data?.circles.edges;
-	$: worlds = $worldsQuery.data?.worlds.edges;
+	let tagsQuery = $derived(comicTagList(client));
+	let artistsQuery = $derived(artistList(client));
+	let charactersQuery = $derived(characterList(client));
+	let circlesQuery = $derived(circleList(client));
+	let worldsQuery = $derived(worldList(client));
+
+	let tags = $derived($tagsQuery.data?.comicTags.edges);
+	let artists = $derived($artistsQuery.data?.artists.edges);
+	let characters = $derived($charactersQuery.data?.characters.edges);
+	let circles = $derived($circlesQuery.data?.circles.edges);
+	let worlds = $derived($worldsQuery.data?.worlds.edges);
 
 	const controls = new UpdateComicsControls();
 
-	const update = () => {
-		updateComics(client, {
-			ids: ids,
-			input: controls.toInput()
-		})
-			.then(closeModal)
-			.catch(toastFinally);
-	};
+	function update(event: SubmitEvent) {
+		event.preventDefault();
+
+		updateComics(client, { ids, input: controls.input() }).then(modal.close).catch(toastFinally);
+	}
 </script>
 
-<Dialog {isOpen}>
-	<svelte:fragment slot="header">
-		<h2>Edit Comics</h2>
-	</svelte:fragment>
-	<form on:submit|preventDefault={update}>
+<Dialog title="Edit Comics" {...modal}>
+	<form onsubmit={update}>
 		<div class="grid-labels">
-			<Labelled label="Category" let:id>
-				<Select clearable {id} options={categories} bind:value={controls.category.value} />
-			</Labelled>
-			<Labelled label="Rating" let:id>
-				<Select clearable {id} options={ratings} bind:value={controls.rating.value} />
-			</Labelled>
-			<Labelled label="Censorship" let:id>
-				<Select clearable {id} options={censorships} bind:value={controls.censorship.value} />
-			</Labelled>
-			<Labelled label="Language" let:id>
-				<Select clearable {id} options={languages} bind:value={controls.language.value} />
-			</Labelled>
-			<Labelled label="Direction" let:id>
-				<Select clearable {id} options={directions} bind:value={controls.direction.value} />
-			</Labelled>
-			<Labelled label="Layout" let:id>
-				<Select clearable {id} options={layouts} bind:value={controls.layout.value} />
-			</Labelled>
+			<label class="self-center" for="category">Category</label>
+			<Select clearable id="category" options={categories} bind:value={controls.category.value} />
+
+			<label class="self-center" for="rating">Rating</label>
+			<Select clearable id="rating" options={ratings} bind:value={controls.rating.value} />
+
+			<label class="self-center" for="censor">Censorship</label>
+			<Select clearable id="censor" options={censorships} bind:value={controls.censorship.value} />
+
+			<label class="self-center" for="language">Language</label>
+			<Select clearable id="language" options={languages} bind:value={controls.language.value} />
+
+			<label class="self-center" for="direction">Direction</label>
+			<Select clearable id="direction" options={directions} bind:value={controls.direction.value} />
+
+			<label class="self-center" for="layout">Layout</label>
+			<Select clearable id="layout" options={layouts} bind:value={controls.layout.value} />
 		</div>
 
-		<LabelledBlock label="Artists" let:id>
-			<Select multi {id} options={artists} bind:value={controls.artists.ids} />
-			<UpdateModeSelector bind:mode={controls.artists.options.mode} slot="controls" />
+		<LabelledBlock label="Artists">
+			{#snippet children({ id })}
+				<Select multi {id} options={artists} bind:value={controls.artists.ids} />
+			{/snippet}
+			{#snippet side()}
+				<UpdateModeSelector bind:mode={controls.artists.options.mode} />
+			{/snippet}
 		</LabelledBlock>
-		<LabelledBlock label="Circles" let:id>
-			<Select multi {id} options={circles} bind:value={controls.circles.ids} />
-			<UpdateModeSelector bind:mode={controls.circles.options.mode} slot="controls" />
+		<LabelledBlock label="Circles">
+			{#snippet children({ id })}
+				<Select multi {id} options={circles} bind:value={controls.circles.ids} />
+			{/snippet}
+			{#snippet side()}
+				<UpdateModeSelector bind:mode={controls.circles.options.mode} />
+			{/snippet}
 		</LabelledBlock>
-		<LabelledBlock label="Characters" let:id>
-			<Select multi {id} options={characters} bind:value={controls.characters.ids} />
-			<UpdateModeSelector bind:mode={controls.characters.options.mode} slot="controls" />
+		<LabelledBlock label="Characters">
+			{#snippet children({ id })}
+				<Select multi {id} options={characters} bind:value={controls.characters.ids} />
+			{/snippet}
+			{#snippet side()}
+				<UpdateModeSelector bind:mode={controls.characters.options.mode} />
+			{/snippet}
 		</LabelledBlock>
-		<LabelledBlock label="Worlds" let:id>
-			<Select multi {id} options={worlds} bind:value={controls.worlds.ids} />
-			<UpdateModeSelector bind:mode={controls.worlds.options.mode} slot="controls" />
+		<LabelledBlock label="Worlds">
+			{#snippet children({ id })}
+				<Select multi {id} options={worlds} bind:value={controls.worlds.ids} />
+			{/snippet}
+			{#snippet side()}
+				<UpdateModeSelector bind:mode={controls.worlds.options.mode} />
+			{/snippet}
 		</LabelledBlock>
-		<LabelledBlock label="Tags" let:id>
-			<Select multi {id} options={tags} bind:value={controls.tags.ids} />
-			<UpdateModeSelector bind:mode={controls.tags.options.mode} slot="controls" />
+		<LabelledBlock label="Tags">
+			{#snippet children({ id })}
+				<Select multi {id} options={tags} bind:value={controls.tags.ids} />
+			{/snippet}
+			{#snippet side()}
+				<UpdateModeSelector bind:mode={controls.tags.options.mode} />
+			{/snippet}
 		</LabelledBlock>
 
 		<div class="flex justify-end gap-4">
-			<SubmitButton active={controls.hasInput()} />
+			<SubmitButton pending={controls.pending()} />
 		</div>
 	</form>
 </Dialog>
-- 
cgit v1.2.3-2-gb3c3

