summaryrefslogtreecommitdiffstatshomepage
path: root/frontend/src/lib/filter/ComicFilterForm.svelte
blob: 13b5320189ef30d20ca4d32033e3bf2f9017a7bf (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
<script lang="ts">
	import { page } from '$app/stores';
	import { artistList, characterList, circleList, comicTagList, worldList } from '$gql/Queries';
	import { ComicFilterContext, getFilterContext } from '$lib/Filter';
	import { getContextClient } from '@urql/svelte';
	import ComicFilterGroup from './components/ComicFilterGroup.svelte';
	import FilterForm from './components/FilterForm.svelte';

	const client = getContextClient();

	$: tagsQuery = comicTagList(client, { forFilter: true });
	$: 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 filter = getFilterContext<ComicFilterContext>();
	const apply = () => $filter.apply($page.url.searchParams);
</script>

<FilterForm type="grid" on:submit={apply}>
	<ComicFilterGroup
		slot="include"
		type="include"
		bind:controls={$filter.include.controls}
		{tags}
		{artists}
		{characters}
		{circles}
		{worlds}
	/>
	<ComicFilterGroup
		slot="exclude"
		type="exclude"
		bind:controls={$filter.exclude.controls}
		{tags}
		{artists}
		{characters}
		{circles}
		{worlds}
	/>
</FilterForm>