1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-04-19 00:41:04 +00:00

78 lines
1.6 KiB
Svelte
Raw Normal View History

2023-01-10 17:28:27 +01:00
<script>
2023-02-15 19:27:51 +01:00
import Icon from '$components/icon.svelte';
2023-05-29 20:51:54 +02:00
import ObjectEditor from '$components/objecteditor.svelte';
import { convertLooseJson } from '$lib/strings';
2023-02-15 19:27:51 +01:00
import { RemoveItems } from '$wails/go/app/App';
2023-05-29 20:51:54 +02:00
import { onMount } from 'svelte';
2023-01-10 17:28:27 +01:00
export let collection;
2023-01-17 15:56:55 +01:00
let json = '';
let many = true;
let result = undefined;
2023-05-29 20:51:54 +02:00
let editor;
2023-06-11 09:34:00 +02:00
// $: code = `db.${collection.key}.remove(${json});`;
2023-01-10 17:28:27 +01:00
2023-01-17 15:56:55 +01:00
async function removeItems() {
2023-05-29 20:51:54 +02:00
result = await RemoveItems(
collection.hostKey,
collection.dbKey,
collection.key,
convertLooseJson(json),
many
);
2023-01-17 15:56:55 +01:00
}
2023-05-29 20:51:54 +02:00
onMount(() => {
editor.dispatch({
changes: {
from: 0,
to: editor.state.doc.length,
insert: '{\n\t\n}',
},
selection: {
anchor: 3,
},
});
editor.focus();
});
2023-01-10 17:28:27 +01:00
</script>
2023-01-17 15:56:55 +01:00
<form on:submit|preventDefault={removeItems}>
2023-05-29 20:51:54 +02:00
<!-- svelte-ignore a11y-label-has-associated-control -->
2023-01-10 17:28:27 +01:00
<label class="field">
2023-05-29 20:51:54 +02:00
<ObjectEditor bind:text={json} bind:editor />
2023-01-10 17:28:27 +01:00
</label>
<div class="actions">
2023-06-27 17:21:54 +02:00
<button type="submit" class="button danger">
2023-01-20 13:54:57 +01:00
<Icon name="-" /> Remove
</button>
<label class="field many">
<span class="label">Many</span>
<span class="checkbox">
<input type="checkbox" bind:checked={many} />
</span>
</label>
{#key result}
{#if typeof result === 'number'}
<span class="flash-green">Removed {result} item{result === 1 ? '' : 's'}</span>
{/if}
{/key}
2023-01-10 17:28:27 +01:00
</div>
</form>
<style>
2023-01-13 16:56:48 +01:00
form {
display: grid;
grid-template-rows: 1fr auto;
2023-01-13 16:56:48 +01:00
gap: 0.5rem;
}
.many {
display: inline-flex;
2023-01-17 15:56:55 +01:00
}
2023-01-10 17:28:27 +01:00
</style>