Skip to content

Commit 8002e5f

Browse files
judah-sotomayorMast3Reichrisvire
authored
Feature/Edit Note make Fullscreen (sillsdev#850)
* Remake edit notes popup into a fullscreen editor. - Added CheckIcon and DeleteIcon for saving and deleting notes - Added a route in /notes/+page.svelte to the edit route * Allow navigation from modal to full-screen editor in NoteDialog Fixed issue with adding new note * Removed vite.config.js.timestamp files and made small changes to /notes/edit/+page.js * Fixing Adding Notes and Back Navigation for Edits Modify NoteDialog.svelte and note.ts to handle create notes better; implement history.back in /note/edit/[noteid]/+page.svelte * Necessary Final Adjustments and Cleanup Cleanup in /notes/edit/[noteid]/+page.svelte and+page.js, and static folder * Developed temporary fix on Add Notes Feature Temporary fix to navigate directly to adding a new note and see an 'Add Note' title; requires additional fixes * 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 * Cleanup and Fix textSelectionToolBar Removes unnecessary code and comments, and makes it so the textselection only leads to creating a new note * Remove async from functions * Focus textarea when new note page starts * Fix errors from rebase - Remove double-import, likely added by sloppy merging - Remove NoteDialog content fragment to work with Modal's children snippet - Comment out cancel button that makes use of editing variable - Make tabMenuActive a $state variable * Convert ${base} to getRoute in goto statements Fix the references in notes infrastructure to `goto` that do not use hash-based routing. * Fix navbar use in notes editor to use snippets The notes editor in `src/routes/notes/edit/[noteid]/+page.svelte` and `src/routes/notes/new/+page.svelte` used the old slots configuration inside the Navbar element. This is incompatible with the current implementation of Navbar. This commit fixes these pages to use snippets instead. * Add the verse reference to fullscreen note editor This change adds the verse reference for a note to the fullscreen editor. This prevents the user from being confused about what note is being changed. * Fix missing function error on `#/notes` page. Notes `+page.svelte` did not properly assign the `menuaction` property to the CardMenu. Prettier fixes to `CheckIcon` and `DeleteIcon`. Resolve sveltecheck complaints in `notes/edit/+page.svelte` and `notes/new/+page.svelte` concerning `textarea`. * Adopt standard sveltekit error handling in `/note` Accept coderabbit's suggestion and use correct svelte error handling methods, as per https://svelte.dev/docs/kit/errors. Also add fallback for reference text. * Fix incorrect font for notedialog heading. The heading text of the NoteDialog previously did not use the correct font face. It also did not set the font size. This commit tells it to use the body font face and size. * Remove `notes/new/` page, move creation to `edit`. The `notes/new/` and `notes/edit` pages were almost entirely duplicates of each other. This change refactors `notes/edit` to allow using the noteid `new` to create a note. The `createNote` function has been moved appropriately and the `deleteNote` function updated to only delete existing notes. This commit also removes `notes/new` as obsolete. * Corect too-wide center text in notes navbar. This commit makes the divider and reference text disappear on mobile devices, using tailwind's `hidden` and `sm:` features. The notes reference will still appear on tablets and desktop devices, but it will not collide anymore on mobile. * Remove commented-out code from NoteDialog * Fix: Replace `goto` with `gotoRoute` in notes page * Remove unused dependencies in NoteDialog Remove unused imports (`goto`, `base`, `addNote`, `editNote`, `getRoute`) from NoteDialog. Replace `goto` and `getRoute` with `gotoRoute`. * Remove old TODO in NoteDialog. * Replace goto and getRoute in TextSelectionToolbar. Use gotoRoute instead. * Fix formatting --------- Co-authored-by: Reilly Krause <reikwork@gmail.com> Co-authored-by: Chris Hubbard <chris@thehubbards.org>
1 parent 6c1ef4a commit 8002e5f

11 files changed

Lines changed: 186 additions & 63 deletions

File tree

src/lib/components/CollectionSelector.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Book Collection Selector component.
2525
const modalId = 'collectionSelector';
2626
let modal;
2727
let tabMenu;
28-
let tabMenuActive = LAYOUT_SINGLE;
28+
let tabMenuActive = $state(LAYOUT_SINGLE);
2929
3030
// values of selectedLayouts before user makes changes
3131
const restoreDocSets = JSON.stringify($selectedLayouts);

src/lib/components/IconCard.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ TODO:
5252
{reference}
5353
</a>
5454
</div>
55-
<div class="self-center justify-self-end"><CardMenu menuaction {actions} /></div>
55+
<div class="self-center justify-self-end"><CardMenu {menuaction} {actions} /></div>
5656

5757
<div
5858
class="annotation-item-text col-start-2 col-end-3 justify-self-start"
Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,56 @@
11
<svelte:options accessors={true} />
22

33
<script lang="ts">
4-
import { addNote, editNote } from '$lib/data/notes';
54
import { bodyFontSize, currentFont, selectedVerses, t } from '$lib/data/stores';
65
import { EditIcon } from '$lib/icons';
6+
import { gotoRoute } from '$lib/navigate';
77
import Modal from './Modal.svelte';
88
99
export let note = undefined;
10-
export let editing = false;
1110
1211
let id = 'note';
1312
let modal;
14-
let title: string;
1513
let text: string;
1614
17-
$: heading = editing ? ($t[title] ?? '') : (note?.reference ?? '');
15+
$: heading = note?.reference ?? '';
1816
1917
export function showModal() {
2018
if (note !== undefined) {
2119
text = note.text;
22-
title = 'Annotation_Note_Edit';
20+
modal.showModal();
2321
} else {
24-
editing = true;
25-
title = 'Annotation_Note_Add';
22+
console.log('No note available!');
2623
}
27-
modal.showModal();
2824
}
2925
3026
function reset() {
3127
text = '';
32-
editing = false;
3328
selectedVerses.reset();
3429
}
3530
36-
async function modifyNote() {
31+
function onEditNote() {
3732
if (note !== undefined) {
38-
await editNote({
39-
note: note,
40-
newText: text
41-
});
42-
} else {
43-
await addNote({
44-
docSet: $selectedVerses[0].docSet,
45-
collection: $selectedVerses[0].collection,
46-
book: $selectedVerses[0].book,
47-
chapter: $selectedVerses[0].chapter,
48-
verse: $selectedVerses[0].verse,
49-
text,
50-
reference: $selectedVerses[0].reference
51-
});
33+
gotoRoute(`/notes/edit/${note.date}`);
5234
}
5335
}
5436
</script>
5537

5638
<Modal bind:this={modal} {id} onclose={reset}>
5739
<div class="flex flex-col justify-evenly">
58-
<div class="w-full flex justify-between">
59-
<div class="w-full pb-3" style:font-weight={editing ? 'normal' : 'bold'}>
60-
{heading}
40+
<div class="w-full flex justify-between items-center">
41+
<div class="w-full pb-3" style:font-weight="bold">
42+
<p style:font-family={$currentFont} style:font-size="{$bodyFontSize}px">
43+
{heading}
44+
</p>
6145
</div>
62-
{#if !editing}
63-
<button
64-
onclick={() => {
65-
editing = true;
66-
}}
67-
>
68-
<EditIcon />
69-
</button>
70-
{/if}
46+
47+
<button class="dy-btn dy-btn-ghost dy-btn-circle" onclick={onEditNote}>
48+
<EditIcon />
49+
</button>
7150
</div>
72-
<div style:word-wrap="break-word">
73-
{#if editing}
74-
<textarea bind:value={text} class="dy-textarea w-full"></textarea>
75-
{:else if text !== undefined}
51+
52+
<div style:word-wrap="break-word" class="mt-2">
53+
{#if text !== undefined}
7654
{#each text.split(/\r?\n/) as line}
7755
{#if line}
7856
<p style:font-family={$currentFont} style:font-size="{$bodyFontSize}px">
@@ -84,13 +62,5 @@
8462
{/each}
8563
{/if}
8664
</div>
87-
{#if editing}
88-
<div class="w-full flex mt-4 justify-between">
89-
<button class="dy-btn dy-btn-sm dy-btn-ghost">{$t['Button_Cancel']}</button>
90-
<button onclick={modifyNote} class="dy-btn dy-btn-sm dy-btn-ghost"
91-
>{$t['Button_OK']}</button
92-
>
93-
</div>
94-
{/if}
9565
</div>
9666
</Modal>

src/lib/components/TextSelectionToolbar.svelte

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,7 @@ TODO:
1818
import config from '$lib/data/config';
1919
import { addHighlights, removeHighlights } from '$lib/data/highlights';
2020
import { shareText } from '$lib/data/share';
21-
import {
22-
audioActive,
23-
modal,
24-
MODAL_NOTE,
25-
refs,
26-
s,
27-
selectedVerses,
28-
t,
29-
theme,
30-
themeColors
31-
} from '$lib/data/stores';
21+
import { audioActive, refs, s, selectedVerses, theme, themeColors } from '$lib/data/stores';
3222
import {
3323
AudioIcon,
3424
BookmarkIcon,
@@ -39,6 +29,7 @@ TODO:
3929
ShareIcon
4030
} from '$lib/icons';
4131
import { ImageIcon } from '$lib/icons/image';
32+
import { gotoRoute } from '$lib/navigate';
4233
import { createEventDispatcher } from 'svelte';
4334
4435
const isAudioPlayable = config?.mainFeatures['text-select-play-audio'];
@@ -226,7 +217,10 @@ TODO:
226217
</button>
227218
{/if}
228219
{#if isNotesEnabled}
229-
<button class="dy-btn-sm dy-btn-ghost" on:click={() => modal.open(MODAL_NOTE)}>
220+
<button
221+
class="dy-btn-sm dy-btn-ghost"
222+
on:click={() => gotoRoute(`/notes/edit/new`)}
223+
>
230224
<NoteIcon color={barIconColor} />
231225
</button>
232226
{/if}

src/lib/data/notes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export async function addNote(item: {
6868
const nextItem = { ...item, date: date, bookIndex: bookIndex };
6969
await notes.add('notes', nextItem);
7070
notifyUpdated();
71+
return nextItem;
7172
}
7273

7374
export async function findNote(item: {

src/lib/icons/CheckIcon.svelte

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script lang="ts">
2+
// Check from https://fonts.google.com/icons
3+
// 'FILL' 0,
4+
// 'wght' 400,
5+
// 'GRAD' 0,
6+
// 'opsz' 24
7+
export let color = 'black';
8+
export let size = '24';
9+
</script>
10+
11+
<svg
12+
fill={color}
13+
xmlns="http://www.w3.org/2000/svg"
14+
height={size}
15+
width={size}
16+
viewBox="0 -960 960 960"
17+
>
18+
<path d="M382-240 154-468l57-57 171 171 367-367 57 57-424 424Z" />
19+
</svg>

src/lib/icons/DeleteIcon.svelte

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script lang="ts">
2+
// Delete SVG vector icon from https://www.svgrepo.com/svg/453328/delete
3+
export let color = 'black';
4+
export let size = '24';
5+
</script>
6+
7+
<svg fill={color} xmlns="http://www.w3.org/2000/svg" height={size} width={size} viewBox="0 0 24 24"
8+
><path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" /></svg
9+
>

src/lib/icons/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import CalendarMonthIcon from './CalendarMonthIcon.svelte';
1111
import VerseByVerseIcon from './CalendarMonthIcon.svelte';
1212
import CheckboxIcon from './CheckboxIcon.svelte';
1313
import CheckboxOutlineIcon from './CheckboxOutlineIcon.svelte';
14+
import CheckIcon from './CheckIcon.svelte';
1415
import ChevronIcon from './ChevronIcon.svelte';
1516
import CopyContentIcon from './CopyContentIcon.svelte';
17+
import DeleteIcon from './DeleteIcon.svelte';
1618
import DeleteSweepIcon from './DeleteSweepIcon.svelte';
1719
import DropdownIcon from './DropdownIcon.svelte';
1820
import EditIcon from './EditIcon.svelte';
@@ -47,8 +49,10 @@ export {
4749
CalendarMonthIcon,
4850
CheckboxIcon,
4951
CheckboxOutlineIcon,
52+
CheckIcon,
5053
ChevronIcon,
5154
CopyContentIcon,
55+
DeleteIcon,
5256
DeleteSweepIcon,
5357
DropdownIcon,
5458
EditIcon,

src/routes/notes/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
gotoRoute(`/`);
2121
break;
2222
case $t['Annotation_Menu_Edit']:
23-
modal.open(MODAL_NOTE, note);
23+
gotoRoute(`/notes/edit/${note.date}`);
2424
break;
2525
case $t['Annotation_Menu_Share']:
2626
await shareAnnotation(note);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { error } from '@sveltejs/kit';
2+
import { getNotes } from '$lib/data/notes';
3+
4+
export async function load({ params }) {
5+
const { noteid } = params;
6+
if (noteid === 'new') {
7+
return { note: undefined };
8+
}
9+
10+
const date = parseInt(noteid, 10);
11+
if (isNaN(date)) {
12+
console.error(`Invalid noteid: ${noteid}`);
13+
error(400, {
14+
message: 'Invalid note ID'
15+
});
16+
}
17+
18+
const allNotes = await getNotes();
19+
const note = allNotes.find((item) => item.date === date);
20+
21+
if (!note) {
22+
error(404, {
23+
message: 'Note not found'
24+
});
25+
}
26+
return { note };
27+
}

0 commit comments

Comments
 (0)