Skip to content

Commit 75c2fa2

Browse files
committed
fix(ux): Implement normal file saving and note settings
1 parent 99bc147 commit 75c2fa2

3 files changed

Lines changed: 81 additions & 13 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<script lang="ts">
2+
import type { PageManager } from "$lib/canvas/PageManager.svelte";
3+
import type { Note } from "$lib/types/bindings/Note";
4+
import type { Tab } from "$lib/types/tabs";
5+
import Input from "./Input.svelte";
6+
import Overlay from "./Overlay.svelte";
7+
8+
const {
9+
closeCb,
10+
visible,
11+
data,
12+
}: {
13+
closeCb: () => void;
14+
visible: boolean;
15+
data?: { page: PageManager; tab?: Tab };
16+
} = $props();
17+
</script>
18+
19+
<Overlay {closeCb} title="Note settings" minHeight={false} {visible}>
20+
<p>The values here save automatically!</p>
21+
<Input
22+
label="Note title"
23+
value={data?.page.meta.title}
24+
id="title"
25+
onBlur={(e) => {
26+
if (data) data.page.meta.title = e.currentTarget.value;
27+
}}
28+
/>
29+
<Input
30+
label="Tags"
31+
value={data?.page.meta.tags.join(",")}
32+
onBlur={(e) => {
33+
if (data) data.page.meta.tags = e.currentTarget.value.split(",");
34+
}}
35+
id="tags"
36+
/>
37+
More options coming soon!
38+
</Overlay>

app/src/lib/components/Toolbar.svelte

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616
let {
1717
// tool,
1818
updateTool,
19-
}: { tool: ToolSettings; updateTool: (newTool: ToolSettings) => void } =
20-
$props();
19+
openSettings,
20+
}: {
21+
tool: ToolSettings;
22+
updateTool: (newTool: ToolSettings) => void;
23+
openSettings: () => void;
24+
} = $props();
2125
</script>
2226

2327
<div class="right-4 h-full absolute pointer-events-none flex z-20">
@@ -74,7 +78,9 @@
7478
class={[
7579
"aspect-square p-2 rounded-xl active:scale-90 transition-all hover:bg-overlay/20",
7680
]}
77-
onclick={() => {}}
81+
onclick={() => {
82+
openSettings();
83+
}}
7884
>
7985
<IconSettings />
8086
</button>

app/src/routes/edit/+page.svelte

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@
77
import { save } from "@tauri-apps/plugin-dialog";
88
import { tabManager } from "$lib/tabs/tabs.svelte";
99
import { goto } from "$app/navigation";
10+
import NoteSettings from "$lib/components/NoteSettings.svelte";
1011
1112
let tool: ToolSettings = $state(penDefaults);
13+
let settingsOpen = $state(false);
1214
13-
const tab = $derived(tabManager.currentPage);
14-
const pageManager = $derived(tab.page);
15-
const canvasManager = $derived(tab.canvas);
15+
const currentTab = $derived(tabManager.currentTab);
16+
const data = $derived(tabManager.currentPage);
17+
const pageManager = $derived(data.page);
18+
const canvasManager = $derived(data.canvas);
1619
1720
$effect(() => {
18-
if (!tab) goto("/");
21+
if (!data) goto("/");
1922
});
2023
2124
function updateTool(newTool: ToolSettings) {
@@ -24,12 +27,17 @@
2427
2528
const hotkeys = async (e: KeyboardEvent) => {
2629
if (!e.ctrlKey) return;
27-
if (e.key === "s") {
30+
if (e.key === "s" && currentTab.path) {
2831
// TODO: Save to user directory
29-
alert(
30-
"This feature is being implemented; please consider using Ctrl+Shift+S instead!",
31-
);
32-
} else if (e.key === "S" || (e.key === "s" && e.shiftKey)) {
32+
await invoke("write", {
33+
path: currentTab.path,
34+
note: JSON.stringify(pageManager.export(canvasManager.export()!)),
35+
});
36+
} else if (
37+
e.key === "S" ||
38+
(e.key === "s" && e.shiftKey) ||
39+
(e.key === "s" && currentTab.path === null)
40+
) {
3341
// Open file save dialog
3442
3543
const path = await save({
@@ -39,6 +47,8 @@
3947
4048
if (!path) return;
4149
50+
currentTab.path = path;
51+
4252
await invoke("write", {
4353
path,
4454
note: JSON.stringify(pageManager.export(canvasManager.export()!)),
@@ -52,9 +62,23 @@
5262
document.removeEventListener("keydown", hotkeys);
5363
};
5464
});
65+
66+
function openSettings() {
67+
settingsOpen = true;
68+
}
69+
function closeSettings() {
70+
settingsOpen = false;
71+
}
5572
</script>
5673

5774
<div class="w-full h-screen relative touch-none">
58-
<Toolbar {tool} {updateTool} />
75+
<NoteSettings
76+
data={{
77+
page: pageManager,
78+
}}
79+
closeCb={closeSettings}
80+
visible={settingsOpen}
81+
/>
82+
<Toolbar {tool} {updateTool} {openSettings} />
5983
<Canvas {tool} {pageManager} {canvasManager} />
6084
</div>

0 commit comments

Comments
 (0)