mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Implement add button
This commit is contained in:
parent
c2374dcc24
commit
8e9cc5c382
4 changed files with 36 additions and 4 deletions
|
@ -3,12 +3,14 @@ Copyright: Ankitects Pty Ltd and contributors
|
|||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="ts">
|
||||
import AddButton from "./AddButton.svelte";
|
||||
import CloseButton from "./CloseButton.svelte";
|
||||
import HelpButton from "./HelpButton.svelte";
|
||||
import type { EditorMode } from "./types";
|
||||
|
||||
export let mode: EditorMode;
|
||||
export let onClose: () => void;
|
||||
export let onAdd: () => void;
|
||||
</script>
|
||||
|
||||
<div class="action-buttons d-flex flex-row-reverse">
|
||||
|
@ -16,7 +18,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
<HelpButton />
|
||||
{/if}
|
||||
{#if mode === "add" || mode === "current"}
|
||||
<CloseButton {onClose} />
|
||||
<CloseButton {onClose} enableShortcut={mode === "current"} />
|
||||
{/if}
|
||||
{#if mode === "add"}
|
||||
<AddButton {onAdd} />
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
|
|
18
ts/routes/editor/AddButton.svelte
Normal file
18
ts/routes/editor/AddButton.svelte
Normal file
|
@ -0,0 +1,18 @@
|
|||
<!--
|
||||
Copyright: Ankitects Pty Ltd and contributors
|
||||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="ts">
|
||||
import * as tr from "@generated/ftl";
|
||||
import { getPlatformString } from "@tslib/shortcuts";
|
||||
import Shortcut from "$lib/components/Shortcut.svelte";
|
||||
import ActionButton from "./ActionButton.svelte";
|
||||
|
||||
export let onAdd: () => void;
|
||||
const addKeyCombination = "Control+Enter";
|
||||
</script>
|
||||
|
||||
<ActionButton onClick={onAdd} tooltip={getPlatformString(addKeyCombination)}>
|
||||
{tr.actionsAdd()}
|
||||
<Shortcut keyCombination={addKeyCombination} on:action={onAdd} />
|
||||
</ActionButton>
|
|
@ -9,10 +9,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import ActionButton from "./ActionButton.svelte";
|
||||
|
||||
export let onClose: () => void;
|
||||
const closeKeyCombination = "Control+Enter";
|
||||
export let enableShortcut: boolean;
|
||||
|
||||
const closeKeyCombination = enableShortcut ? "Control+Enter" : "";
|
||||
</script>
|
||||
|
||||
<ActionButton onClick={onClose} tooltip={getPlatformString(closeKeyCombination)}>
|
||||
{tr.actionsClose()}
|
||||
<Shortcut keyCombination={closeKeyCombination} on:action={onClose} />
|
||||
{#if enableShortcut}
|
||||
<Shortcut keyCombination={closeKeyCombination} on:action={onClose} />
|
||||
{/if}
|
||||
</ActionButton>
|
||||
|
|
|
@ -410,6 +410,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
}
|
||||
}
|
||||
|
||||
async function onAdd() {
|
||||
// TODO get selected deck
|
||||
await addCurrentNote(1n);
|
||||
}
|
||||
|
||||
export function saveOnPageHide() {
|
||||
if (document.visibilityState === "hidden") {
|
||||
// will fire on session close and minimize
|
||||
|
@ -1236,7 +1241,7 @@ components and functionality for general note editing.
|
|||
<Collapsible toggleDisplay collapse={$tagsCollapsed}>
|
||||
<TagEditor {tags} on:tagsupdate={saveTags} />
|
||||
</Collapsible>
|
||||
<ActionButtons {mode} {onClose} />
|
||||
<ActionButtons {mode} {onClose} {onAdd} />
|
||||
{/if}
|
||||
|
||||
<ContextMenu bind:this={contextMenu}>
|
||||
|
|
Loading…
Reference in a new issue