blob: 2ed05230805ed5fff4e5976ca0f1aaf751a068a6 (
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
|
<script lang="ts">
import { addComic, updateArchives } from '$gql/Mutations';
import { type FullArchiveFragment } from '$gql/graphql';
import { toastFinally } from '$lib/Toasts';
import AddButton from '$lib/components/AddButton.svelte';
import ComicCard from '$lib/components/ComicCard.svelte';
import OrganizedButton from '$lib/components/OrganizedButton.svelte';
import { getSelectionContext } from '$lib/selection/Selection.svelte';
import SelectionControls from '$lib/toolbar/SelectionControls.svelte';
import { getContextClient } from '@urql/svelte';
import AddOverlay from './AddOverlay.svelte';
const client = getContextClient();
const selection = getSelectionContext();
let { archive }: { archive: FullArchiveFragment } = $props();
function addNew() {
addComic(client, {
input: {
archive: { id: archive.id },
title: archive.name,
pages: { ids: selection.ids },
cover: { id: archive.pages[selection.indices.toSorted((a, b) => a - b)[0]].id }
}
})
.then((mutatation) => {
const data = mutatation.addComic;
if (data.__typename === 'AddComicSuccess' && !data.archivePagesRemaining) {
selection.clear();
} else {
selection.none();
}
})
.catch(toastFinally);
}
function toggleOrganized() {
updateArchives(client, { ids: archive.id, input: { organized: !archive.organized } }).catch(
toastFinally
);
}
</script>
<div class="flex flex-col gap-4">
<div class="flex gap-2 text-sm">
<SelectionControls page>
<AddButton title="Add Comic from selected" onclick={addNew} />
</SelectionControls>
<div class="grow"></div>
<OrganizedButton organized={archive.organized} onclick={toggleOrganized} />
</div>
{#if archive.comics.length > 0}
<div class="flex flex-col gap-1">
<h2 class="text-base font-medium">Comics</h2>
<div class="flex shrink-0 flex-col gap-4">
{#each archive.comics as comic}
<ComicCard compact {comic}>
{#snippet overlay()}
<AddOverlay id={comic.id} />
{/snippet}
</ComicCard>
{/each}
</div>
</div>
{/if}
</div>
|