summaryrefslogtreecommitdiffstatshomepage
path: root/frontend/src/lib/dialogs/UpdateComics.svelte
blob: 483e3791d64c8e6c40f336cb034bc6d11343fefd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<script lang="ts">
	import { updateComics } from '$gql/Mutations';
	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.svelte';
	import Dialog from '$lib/components/Dialog.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 type { ModalProps } from 'svelte-modals';
	import UpdateModeSelector from './components/UpdateModeSelector.svelte';

	const client = getContextClient();

	interface Props extends ModalProps {
		ids: number[];
	}

	let { ids, ...modal }: Props = $props();

	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();

	function update(event: SubmitEvent) {
		event.preventDefault();

		updateComics(client, { ids, input: controls.input() }).then(modal.close).catch(toastFinally);
	}
</script>

<Dialog title="Edit Comics" {...modal}>
	<form onsubmit={update}>
		<div class="grid-labels">
			<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">
			{#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">
			{#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">
			{#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">
			{#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">
			{#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 pending={controls.pending()} />
		</div>
	</form>
</Dialog>