editor functionable

This commit is contained in:
j-weissen 2022-10-17 00:32:27 +02:00
parent 180a26344a
commit fa94a99567
2 changed files with 14 additions and 13 deletions

View file

@ -77,8 +77,8 @@
* @param note The note the user clicked on
*/
function onNoteLiClick(note) {
noteRepo.currentNoteId = note.id;
window.location = "/editor";
note.lastViewed = new Date();
}
</script>

View file

@ -2,34 +2,35 @@
import type {Note} from "../../models/types";
import {StrapiNoteRepository} from "../../models/repos/note/StrapiNoteRepository";
import {onMount} from "svelte";
import {currentNoteId} from "../../stores";
let noteRepo: StrapiNoteRepository;
let currentNote: Note;
let id;
onMount(async () => {
currentNoteId.subscribe(v => id = v);
noteRepo = StrapiNoteRepository.getInstance();
currentNote = await noteRepo.getNote(noteRepo.currentNoteId);
try {
currentNote = await noteRepo.getNote(noteRepo.currentNoteId);
} catch {
returnToListing();
}
title = (<Note>currentNote).title;
content = (<Note>currentNote).content;
console.log(noteRepo.currentNoteId)
})
export let title: string, content: string;
function save() {
noteRepo.updateNote(currentNote.id, {
"title": currentNote.title,
"content": currentNote.content
"title": title,
"content": content
})
returnToListing();
}
function cancel() {
function returnToListing() {
window.location = "/";
}
export let title: string, content: string;
</script>
<head>
@ -46,7 +47,7 @@
<input bind:value={title} class="input"> <br />
<textarea bind:value={content} class="input"></textarea>
<button on:click={() => save()} class="btn btn-primary save">Save</button>
<button on:click={() => cancel()} class="btn btn-outline-danger cancel">Cancel</button>
<button on:click={() => returnToListing()} class="btn btn-outline-danger cancel">Cancel</button>
</div>
</html>