65 lines
1.2 KiB
Svelte
65 lines
1.2 KiB
Svelte
<script lang="ts">
|
|
import { getContext } from "svelte";
|
|
import type { FrontendMessenger } from "../../background_frontend_commands";
|
|
|
|
let connection = getContext("connection") as FrontendMessenger;
|
|
export let trans: Translation | Flashcard;
|
|
let card: Flashcard | undefined;
|
|
|
|
$: if ("id" in trans) card = trans;
|
|
const addFlashcard = async () => {
|
|
card = await connection.runCommand("addFlashcard", trans);
|
|
};
|
|
|
|
const removeFlashcard = async () => {
|
|
if (card) await connection.runCommand("removeFlashcard", card);
|
|
card = undefined;
|
|
};
|
|
</script>
|
|
|
|
<div class="translatedContainer">
|
|
<span>{trans.result}</span>
|
|
|
|
{#if !card}
|
|
<button on:click={addFlashcard}>
|
|
Add
|
|
<br />
|
|
card
|
|
</button>
|
|
{:else}
|
|
<button on:click={removeFlashcard} class="remove">
|
|
Remove
|
|
<br />
|
|
card
|
|
</button>
|
|
{/if}
|
|
</div>
|
|
|
|
<style lang="scss">
|
|
@use "../color_scheme";
|
|
@use "../common";
|
|
|
|
.translatedContainer {
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
|
|
span {
|
|
margin-right: 0.7em;
|
|
}
|
|
|
|
button {
|
|
@include common.button;
|
|
font-size: 0.8em;
|
|
border: 0;
|
|
min-width: 9ch;
|
|
border-radius: 2px;
|
|
min-height: 100%;
|
|
|
|
@include common.button_green;
|
|
&.remove {
|
|
@include common.button_red;
|
|
}
|
|
}
|
|
</style>
|