blob: e07338cf533e2321d62f8fbc92c702370c263f7f (
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
|
<script lang="ts">
import { deleteArtists } from '$gql/Mutations';
import { artistsQuery, fetchArtist } from '$gql/Queries';
import type { Artist } from '$gql/graphql';
import { ArtistSortLabel } from '$lib/Enums';
import { BasicFilterContext, initFilterContext } from '$lib/Filter';
import { initPaginationContext } from '$lib/Pagination';
import { initSelectionContext } from '$lib/Selection';
import { initSortContext } from '$lib/Sort';
import { toastFinally } from '$lib/Toasts';
import AddButton from '$lib/components/AddButton.svelte';
import Cardlet from '$lib/components/Cardlet.svelte';
import Empty from '$lib/components/Empty.svelte';
import Guard from '$lib/components/Guard.svelte';
import Head from '$lib/components/Head.svelte';
import Cardlets from '$lib/containers/Cardlets.svelte';
import Column from '$lib/containers/Column.svelte';
import AddArtist from '$lib/dialogs/AddArtist.svelte';
import EditArtist from '$lib/dialogs/EditArtist.svelte';
import Pagination from '$lib/pagination/Pagination.svelte';
import Selectable from '$lib/selection/Selectable.svelte';
import SelectionOverlay from '$lib/selection/SelectionOverlay.svelte';
import DeleteSelection from '$lib/toolbar/DeleteSelection.svelte';
import Search from '$lib/toolbar/Search.svelte';
import SelectItems from '$lib/toolbar/SelectItems.svelte';
import SelectSort from '$lib/toolbar/SelectSort.svelte';
import SelectionControls from '$lib/toolbar/SelectionControls.svelte';
import Toolbar from '$lib/toolbar/Toolbar.svelte';
import { getContextClient } from '@urql/svelte';
import { openModal } from 'svelte-modals';
import type { PageData } from './$types';
const client = getContextClient();
export let data: PageData;
$: result = artistsQuery(client, {
pagination: data.pagination,
filter: data.filter,
sort: data.sort
});
$: artists = $result.data?.artists;
const selection = initSelectionContext<Artist>('Artist', (a) => a.name);
$: if (artists) {
$selection.view = artists.edges;
$pagination.total = artists.count;
}
const filter = initFilterContext<BasicFilterContext>();
$: $filter = new BasicFilterContext(data.filter);
const sort = initSortContext(data.sort, ArtistSortLabel);
$: $sort.update = data.sort;
const pagination = initPaginationContext();
$: $pagination.update = data.pagination;
const edit = (id: number) => {
fetchArtist(client, id)
.then((artist) => openModal(EditArtist, { artist }))
.catch(toastFinally);
};
</script>
<Head section="artists" />
<Column>
<Toolbar>
<SelectionControls slot="start">
<DeleteSelection mutation={deleteArtists} />
</SelectionControls>
<svelte:fragment slot="center">
<Search name="Artists" bind:field={$filter.include.controls.name.contains} />
<SelectSort />
<SelectItems />
</svelte:fragment>
<svelte:fragment slot="end">
<AddButton title="Add Artist" on:click={() => openModal(AddArtist)} />
</svelte:fragment>
</Toolbar>
{#if artists}
<Pagination />
<main>
<Cardlets>
{#each artists.edges as { id, name }, index (id)}
<Selectable {index} {id} {edit} let:handle let:selected>
<Cardlet {name} on:click={handle} filter="artists" {id}>
<SelectionOverlay slot="overlay" position="right" centered {selected} />
</Cardlet>
</Selectable>
{:else}
<Empty />
{/each}
</Cardlets>
</main>
<Pagination />
{:else}
<Guard {result} />
{/if}
</Column>
|