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
112
113
114
115
|
<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 LabelledBlock from '$lib/components/LabelledBlock.svelte';
import Select from '$lib/components/Select.svelte';
import { getContextClient } from '@urql/svelte';
import { type Snippet } from 'svelte';
const client = getContextClient();
interface Props {
input: OmitIdentifiers<FullComicFragment>;
submit: (input: UpdateComicInput) => void;
children?: Snippet;
}
let { input = $bindable(), submit, children }: 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);
function onsubmit(event: SubmitEvent) {
event.preventDefault();
submit({
direction: input.direction,
layout: input.layout,
rating: input.rating,
category: input.category,
censorship: input.censorship,
title: input.title,
originalTitle: input.originalTitle,
url: input.url,
date: input.date === '' ? null : input.date,
language: input.language,
tags: { ids: input.tags.map((t) => t.id) },
artists: { ids: input.artists.map((a) => a.id) },
characters: { ids: input.characters.map((c) => c.id) },
circles: { ids: input.circles.map((c) => c.id) },
worlds: { ids: input.worlds.map((w) => w.id) }
});
}
</script>
<form {onsubmit}>
<div class="grid-labels">
<label class="self-center" for="title">Title</label>
<input required id="title" bind:value={input.title} title={input.title} />
<label class="self-center" for="original-title">Original Title</label>
<input id="original-title" bind:value={input.originalTitle} title={input.originalTitle} />
<label class="self-center" for="url">URL</label>
<input id="url" bind:value={input.url} />
<label class="self-center" for="date">Date</label>
<input id="date" type="date" bind:value={input.date} pattern={'d{4}-d{2}-d{2}'} />
<label class="self-center" for="category">Category</label>
<Select id="category" options={categories} bind:value={input.category} />
<label class="self-center" for="rating">Rating</label>
<Select id="rating" options={ratings} bind:value={input.rating} />
<label class="self-center" for="censorship">Censorship</label>
<Select id="censorship" options={censorships} bind:value={input.censorship} />
<label class="self-center" for="language">Language</label>
<Select id="language" options={languages} bind:value={input.language} />
<label class="self-center" for="direction">Direction</label>
<Select id="direction" options={directions} bind:value={input.direction} />
<label class="self-center" for="layout">Layout</label>
<Select id="layout" options={layouts} bind:value={input.layout} />
</div>
<LabelledBlock label="Artists">
{#snippet children({ id })}
<Select multi object {id} options={artists} bind:value={input.artists} />
{/snippet}
</LabelledBlock>
<LabelledBlock label="Circles">
{#snippet children({ id })}
<Select multi object {id} options={circles} bind:value={input.circles} />
{/snippet}
</LabelledBlock>
<LabelledBlock label="Characters">
{#snippet children({ id })}
<Select multi object {id} options={characters} bind:value={input.characters} />
{/snippet}
</LabelledBlock>
<LabelledBlock label="Worlds">
{#snippet children({ id })}
<Select multi object {id} options={worlds} bind:value={input.worlds} />
{/snippet}
</LabelledBlock>
<LabelledBlock label="Tags">
{#snippet children({ id })}
<Select multi object {id} options={tags} bind:value={input.tags} />
{/snippet}
</LabelledBlock>
{@render children?.()}
</form>
|