editor functionable
This commit is contained in:
parent
180a26344a
commit
fa94a99567
2 changed files with 14 additions and 13 deletions
|
|
@ -77,8 +77,8 @@
|
||||||
* @param note The note the user clicked on
|
* @param note The note the user clicked on
|
||||||
*/
|
*/
|
||||||
function onNoteLiClick(note) {
|
function onNoteLiClick(note) {
|
||||||
|
noteRepo.currentNoteId = note.id;
|
||||||
window.location = "/editor";
|
window.location = "/editor";
|
||||||
note.lastViewed = new Date();
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,34 +2,35 @@
|
||||||
import type {Note} from "../../models/types";
|
import type {Note} from "../../models/types";
|
||||||
import {StrapiNoteRepository} from "../../models/repos/note/StrapiNoteRepository";
|
import {StrapiNoteRepository} from "../../models/repos/note/StrapiNoteRepository";
|
||||||
import {onMount} from "svelte";
|
import {onMount} from "svelte";
|
||||||
import {currentNoteId} from "../../stores";
|
|
||||||
|
|
||||||
let noteRepo: StrapiNoteRepository;
|
let noteRepo: StrapiNoteRepository;
|
||||||
let currentNote: Note;
|
let currentNote: Note;
|
||||||
let id;
|
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
currentNoteId.subscribe(v => id = v);
|
|
||||||
noteRepo = StrapiNoteRepository.getInstance();
|
noteRepo = StrapiNoteRepository.getInstance();
|
||||||
currentNote = await noteRepo.getNote(noteRepo.currentNoteId);
|
try {
|
||||||
|
currentNote = await noteRepo.getNote(noteRepo.currentNoteId);
|
||||||
|
} catch {
|
||||||
|
returnToListing();
|
||||||
|
}
|
||||||
title = (<Note>currentNote).title;
|
title = (<Note>currentNote).title;
|
||||||
content = (<Note>currentNote).content;
|
content = (<Note>currentNote).content;
|
||||||
console.log(noteRepo.currentNoteId)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export let title: string, content: string;
|
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
noteRepo.updateNote(currentNote.id, {
|
noteRepo.updateNote(currentNote.id, {
|
||||||
"title": currentNote.title,
|
"title": title,
|
||||||
"content": currentNote.content
|
"content": content
|
||||||
})
|
})
|
||||||
|
returnToListing();
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancel() {
|
function returnToListing() {
|
||||||
window.location = "/";
|
window.location = "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export let title: string, content: string;
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
|
|
@ -46,7 +47,7 @@
|
||||||
<input bind:value={title} class="input"> <br />
|
<input bind:value={title} class="input"> <br />
|
||||||
<textarea bind:value={content} class="input"></textarea>
|
<textarea bind:value={content} class="input"></textarea>
|
||||||
<button on:click={() => save()} class="btn btn-primary save">Save</button>
|
<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>
|
</div>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue