summaryrefslogtreecommitdiffstatshomepage
path: root/frontend/src/lib/dialogs/UpdateComics.svelte
blob: 8de962271348370051cf01b8c16acb013ba3869c (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
<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';
	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 UpdateModeSelector from './components/UpdateModeSelector.svelte';

	const client = getContextClient();

	export let isOpen: boolean;
	export let ids: number[];

	$: tagsQuery = comicTagList(client);
	$: artistsQuery = artistList(client);
	$: charactersQuery = characterList(client);
	$: circlesQuery = circleList(client);
	$: worldsQuery = worldList(client);

	$: 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;

	const controls = new UpdateComicsControls();

	const update = () => {
		updateComics(client, {
			ids: ids,
			input: controls.toInput()
		})
			.then(closeModal)
			.catch(toastFinally);
	};
</script>

<Dialog {isOpen}>
	<svelte:fragment slot="header">
		<h2>Edit Comics</h2>
	</svelte:fragment>
	<form on:submit|preventDefault={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>
		</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>
		<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>
		<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>
		<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>
		<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>

		<div class="flex justify-end gap-4">
			<SubmitButton active={controls.hasInput()} />
		</div>
	</form>
</Dialog>