summaryrefslogtreecommitdiffstatshomepage
path: root/frontend/src/lib/toolbar/MarkBookmark.svelte
blob: e9693fc7b05da2a7a7d9956c428ae01a547e132d (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
<script lang="ts">
	import type { MutationWith } from '$gql/Utils';
	import Bookmark from '$lib/icons/Bookmark.svelte';
	import { getSelectionContext } from '$lib/selection/Selection.svelte';
	import { toastFinally } from '$lib/Toasts';
	import { getContextClient } from '@urql/svelte';

	const client = getContextClient();
	const selection = getSelectionContext();

	let { mutation }: { mutation: MutationWith<{ bookmarked: boolean }> } = $props();

	function mutate(bookmarked: boolean) {
		mutation(client, { ids: selection.ids, input: { bookmarked } }).catch(toastFinally);
	}
</script>

<button type="button" class="btn-slate justify-start gap-1" onclick={() => mutate(true)}>
	<Bookmark bookmarked={true} />
	<span>Bookmark</span>
</button>
<button type="button" class="btn-slate justify-start gap-1" onclick={() => mutate(false)}>
	<Bookmark bookmarked={false} />
	<span>Unbookmark</span>
</button>