Skip to content

Commit 2138582

Browse files
committed
Create new path for adding notes
A new path called 'routes/notes/new' is created to handle the functionality of adding a new note properly so that it does not get saved in the database until the save button is selected
1 parent 88765bc commit 2138582

File tree

5 files changed

+71
-16
lines changed

5 files changed

+71
-16
lines changed

src/lib/components/NoteDialog.svelte

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,22 @@
1717
let title: string;
1818
let text: string;
1919
20-
// $: heading = editingProp ? $t[title] ?? '' : note?.reference ?? '';
2120
$: heading = editing ? note?.reference ?? '' : $t[title] ?? '';
2221
23-
export async function showModal() {
22+
export async function showNote() {
2423
if (note !== undefined) {
2524
text = note.text;
2625
editing = true;
2726
title = 'Annotation_Note_Edit';
2827
modal.showModal();
2928
} else {
30-
// editingProp = true;
3129
editing = false;
32-
await createNote();
33-
goto(`${base}/notes/edit/${note.date}`);
30+
goto(`${base}/notes/new`);
3431
}
3532
}
3633
3734
function reset() {
3835
text = '';
39-
// editingProp = false;
4036
selectedVerses.reset();
4137
}
4238
@@ -59,7 +55,6 @@
5955
}
6056
goto(`${base}/notes/edit/${note.date}`);
6157
}
62-
6358
</script>
6459

6560
<Modal bind:this={modal} {id} on:close={reset} useLabel={false}>

src/routes/+layout.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
break;
3838
case MODAL_NOTE:
3939
noteDialog.note = data;
40-
noteDialog.showModal();
40+
noteDialog.showNote();
4141
break;
4242
case MODAL_TEXT_APPERANCE:
4343
textAppearanceSelector.showModal();

src/routes/notes/+page.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { NoteIcon } from '$lib/icons';
55
import ShareIcon from '$lib/icons/ShareIcon.svelte';
66
import Navbar from '$lib/components/Navbar.svelte';
7-
import { t, monoIconColor, refs, modal, MODAL_NOTE, bodyFontSize } from '$lib/data/stores';
7+
import { t, monoIconColor, refs, bodyFontSize } from '$lib/data/stores';
88
import { formatDate } from '$lib/scripts/dateUtils';
99
import { removeNote, type NoteItem } from '$lib/data/notes';
1010
import { SORT_DATE, SORT_REFERENCE, toSorted } from '$lib/data/annotation-sort';
@@ -20,7 +20,6 @@
2020
goto(`${base}/`);
2121
break;
2222
case $t['Annotation_Menu_Edit']:
23-
// modal.open(MODAL_NOTE, note);
2423
goto(`/notes/edit/${note.date}`);
2524
break;
2625
case $t['Annotation_Menu_Share']:

src/routes/notes/edit/[noteid]/+page.svelte

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@
1212
editing = value;
1313
});
1414
15-
$: title = editing ? 'Annotation_Note_Edit' : 'Annotation_Note_Add';
15+
const title = 'Annotation_Note_Edit';
1616
1717
function goBack() {
1818
history.back();
1919
}
2020
21+
function onBackNavigate(event) {
22+
event.preventDefault();
23+
goBack();
24+
}
25+
2126
async function deleteNote() {
2227
await removeNote(note.date);
2328
goBack();
@@ -32,11 +37,6 @@
3237
}
3338
goBack();
3439
}
35-
36-
function onBackNavigate(event) {
37-
event.preventDefault();
38-
goBack();
39-
}
4040
</script>
4141

4242
<div class="fullscreen-editor">

src/routes/notes/new/+page.svelte

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<script>
2+
import Navbar from '$lib/components/Navbar.svelte';
3+
import { t, selectedVerses } from '$lib/data/stores';
4+
import { DeleteIcon, CheckIcon } from '$lib/icons';
5+
import { addNote } from '$lib/data/notes';
6+
7+
let note = '';
8+
let text = note.text;
9+
const title = 'Annotation_Note_Add';
10+
11+
function goBack() {
12+
history.back();
13+
}
14+
15+
function onBackNavigate(event) {
16+
event.preventDefault();
17+
goBack();
18+
}
19+
20+
async function createNote() {
21+
await addNote({
22+
docSet: $selectedVerses[0].docSet,
23+
collection: $selectedVerses[0].collection,
24+
book: $selectedVerses[0].book,
25+
chapter: $selectedVerses[0].chapter,
26+
verse: $selectedVerses[0].verse,
27+
text,
28+
reference: $selectedVerses[0].reference
29+
});
30+
goBack();
31+
}
32+
33+
async function deleteNote() {
34+
goBack();
35+
}
36+
</script>
37+
38+
<div class="fullscreen-editor">
39+
<Navbar on:backNavigation={onBackNavigate}>
40+
<label for="sidebar" slot="center" >
41+
<div class="btn btn-ghost normal-case text-xl" >{$t[title]}</div>
42+
</label>
43+
44+
<div slot="right-buttons">
45+
<button on:click={deleteNote} class="dy-btn dy-btn-ghost dy-btn-circle"><DeleteIcon color="white" /></button>
46+
<button on:click={createNote} class="dy-btn dy-btn-ghost p-1"><CheckIcon color="white" /></button>
47+
</div>
48+
</Navbar>
49+
50+
<div class="flex justify-center mt-7 h-full max-w-screen-md mx-auto">
51+
<textarea bind:value={text} class="dy-textarea dy-textarea-bordered w-full h-5/6 shadow-md" />
52+
</div>
53+
</div>
54+
55+
<style>
56+
.fullscreen-editor{
57+
width: 100%;
58+
height: 100%;
59+
position: fixed;
60+
}
61+
</style>

0 commit comments

Comments
 (0)