summaryrefslogtreecommitdiffstatshomepage
path: root/frontend/src/lib/toolbar/DeleteSelection.svelte
blob: 7459a87aabfeb898bb9250881d0f5cce8786a003 (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
<script lang="ts">
	import type { DeleteMutation } from '$gql/Mutations';
	import { getSelectionContext } from '$lib/Selection';
	import { toastFinally } from '$lib/Toasts';
	import { confirmDeletion } from '$lib/Utils';
	import DeleteButton from '$lib/components/DeleteButton.svelte';
	import { getContextClient } from '@urql/svelte';

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

	export let mutation: DeleteMutation;
	export let warning: string | undefined = undefined;

	function remove() {
		const mutate = () => {
			mutation(client, { ids: $selection.ids })
				.then(() => ($selection = $selection.clear()))
				.catch(toastFinally);
		};

		confirmDeletion($selection.typename, $selection.names, mutate, warning);
	}
</script>

<DeleteButton on:click={remove} />