summaryrefslogtreecommitdiffstatshomepage
path: root/frontend/src/lib/forms/ComicForm.svelte
blob: 74051c88e08d7b7c9481711ed1157ea954d9b08f (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
<script lang="ts">
	import { artistList, characterList, circleList, comicTagList, worldList } from '$gql/Queries';
	import { type OmitIdentifiers } from '$gql/Utils';
	import type { FullComicFragment, UpdateComicInput } from '$gql/graphql';
	import { categories, censorships, directions, languages, layouts, ratings } from '$lib/Enums';
	import Labelled from '$lib/components/Labelled.svelte';
	import LabelledBlock from '$lib/components/LabelledBlock.svelte';
	import Select from '$lib/components/Select.svelte';
	import { getContextClient } from '@urql/svelte';
	import { createEventDispatcher } from 'svelte';

	const client = getContextClient();
	const dispatch = createEventDispatcher<{ submit: UpdateComicInput }>();

	export let comic: OmitIdentifiers<FullComicFragment>;

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

	function submit() {
		dispatch('submit', {
			direction: comic.direction,
			layout: comic.layout,
			rating: comic.rating,
			category: comic.category,
			censorship: comic.censorship,
			title: comic.title,
			originalTitle: comic.originalTitle,
			url: comic.url,
			date: comic.date === '' ? null : comic.date,
			language: comic.language,
			tags: { ids: comic.tags.map((t) => t.id) },
			artists: { ids: comic.artists.map((a) => a.id) },
			characters: { ids: comic.characters.map((c) => c.id) },
			circles: { ids: comic.circles.map((c) => c.id) },
			worlds: { ids: comic.worlds.map((w) => w.id) }
		});
	}
</script>

<form on:submit|preventDefault={submit}>
	<div class="grid-labels">
		<Labelled label="Title" let:id>
			<input required {id} bind:value={comic.title} title={comic.title} />
		</Labelled>
		<Labelled label="Original Title" let:id>
			<input {id} bind:value={comic.originalTitle} title={comic.originalTitle} />
		</Labelled>
		<Labelled label="URL" let:id>
			<input {id} bind:value={comic.url} />
		</Labelled>
		<Labelled label="Date" let:id>
			<input {id} type="date" bind:value={comic.date} pattern={'d{4}-d{2}-d{2}'} />
		</Labelled>
		<Labelled label="Category" let:id>
			<Select {id} options={categories} bind:value={comic.category} />
		</Labelled>
		<Labelled label="Rating" let:id>
			<Select {id} options={ratings} bind:value={comic.rating} />
		</Labelled>
		<Labelled label="Censorship" let:id>
			<Select {id} options={censorships} bind:value={comic.censorship} />
		</Labelled>
		<Labelled label="Language" let:id>
			<Select {id} options={languages} bind:value={comic.language} />
		</Labelled>
		<Labelled label="Direction" let:id>
			<Select {id} options={directions} bind:value={comic.direction} />
		</Labelled>
		<Labelled label="Layout" let:id>
			<Select {id} options={layouts} bind:value={comic.layout} />
		</Labelled>
	</div>

	<LabelledBlock label="Artists" let:id>
		<Select multi object {id} options={artists} bind:value={comic.artists} />
	</LabelledBlock>
	<LabelledBlock label="Circles" let:id>
		<Select multi object {id} options={circles} bind:value={comic.circles} />
	</LabelledBlock>
	<LabelledBlock label="Characters" let:id>
		<Select multi object {id} options={characters} bind:value={comic.characters} />
	</LabelledBlock>
	<LabelledBlock label="Worlds" let:id>
		<Select multi object {id} options={worlds} bind:value={comic.worlds} />
	</LabelledBlock>
	<LabelledBlock label="Tags" let:id>
		<Select multi object {id} options={tags} bind:value={comic.tags} />
	</LabelledBlock>
	<slot />
</form>