Implement add button

This commit is contained in:
Abdo 2025-07-10 00:14:34 +03:00
parent c2374dcc24
commit 8e9cc5c382
4 changed files with 36 additions and 4 deletions

View file

@ -3,12 +3,14 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import AddButton from "./AddButton.svelte";
import CloseButton from "./CloseButton.svelte"; import CloseButton from "./CloseButton.svelte";
import HelpButton from "./HelpButton.svelte"; import HelpButton from "./HelpButton.svelte";
import type { EditorMode } from "./types"; import type { EditorMode } from "./types";
export let mode: EditorMode; export let mode: EditorMode;
export let onClose: () => void; export let onClose: () => void;
export let onAdd: () => void;
</script> </script>
<div class="action-buttons d-flex flex-row-reverse"> <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 /> <HelpButton />
{/if} {/if}
{#if mode === "add" || mode === "current"} {#if mode === "add" || mode === "current"}
<CloseButton {onClose} /> <CloseButton {onClose} enableShortcut={mode === "current"} />
{/if}
{#if mode === "add"}
<AddButton {onAdd} />
{/if} {/if}
</div> </div>

View 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>

View file

@ -9,10 +9,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import ActionButton from "./ActionButton.svelte"; import ActionButton from "./ActionButton.svelte";
export let onClose: () => void; export let onClose: () => void;
const closeKeyCombination = "Control+Enter"; export let enableShortcut: boolean;
const closeKeyCombination = enableShortcut ? "Control+Enter" : "";
</script> </script>
<ActionButton onClick={onClose} tooltip={getPlatformString(closeKeyCombination)}> <ActionButton onClick={onClose} tooltip={getPlatformString(closeKeyCombination)}>
{tr.actionsClose()} {tr.actionsClose()}
<Shortcut keyCombination={closeKeyCombination} on:action={onClose} /> {#if enableShortcut}
<Shortcut keyCombination={closeKeyCombination} on:action={onClose} />
{/if}
</ActionButton> </ActionButton>

View file

@ -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() { export function saveOnPageHide() {
if (document.visibilityState === "hidden") { if (document.visibilityState === "hidden") {
// will fire on session close and minimize // will fire on session close and minimize
@ -1236,7 +1241,7 @@ components and functionality for general note editing.
<Collapsible toggleDisplay collapse={$tagsCollapsed}> <Collapsible toggleDisplay collapse={$tagsCollapsed}>
<TagEditor {tags} on:tagsupdate={saveTags} /> <TagEditor {tags} on:tagsupdate={saveTags} />
</Collapsible> </Collapsible>
<ActionButtons {mode} {onClose} /> <ActionButtons {mode} {onClose} {onAdd} />
{/if} {/if}
<ContextMenu bind:this={contextMenu}> <ContextMenu bind:this={contextMenu}>