Merge branch 'listing' into develop
This commit is contained in:
commit
22396d1a00
13 changed files with 86 additions and 57 deletions
|
|
@ -1,68 +1,37 @@
|
|||
<script lang="ts">
|
||||
import type {Note} from "../models/types";
|
||||
import {onMount} from "svelte";
|
||||
import {bearerFetch, jwt} from "../models/PomeloUtils";
|
||||
|
||||
const endpoint = "/notes";
|
||||
|
||||
//
|
||||
// //:TODO TEMP!!!
|
||||
// const jsonStr = "[{\"id\":0,\"attributes\":{\"title\":\"mike\",\"content\":\"C Moasta\",\"lastViewed\":\"2022-09-27\"}},{\"id\":1,\"attributes\":{\"title\":\"samc\",\"content\":\"drupal gott\",\"lastViewed\":\"1999-09-09\"}},{\"id\":2,\"attributes\":{\"title\":\"DIO\",\"content\":\"in all CAPS\",\"lastViewed\":\"2022-09-27\"}},{\"id\":3,\"attributes\":{\"title\":\"Eren\",\"content\":\"Jäger\",\"lastViewed\":\"2022-09-27\"}},{\"id\":4,\"attributes\":{\"title\":\"stow\",\"content\":\"Beitn Chef\",\"lastViewed\":\"2022-09-27\"}},{\"id\":5,\"attributes\":{\"title\":\"Wonder of U\",\"content\":\"Umm... so, personally... this is the first time this has happened, so I'm a bit surprised. Only a centimeter away... I mean, I don't think there's ever been someone who's gotten that close to me... without a, you know... calamity occurring. I'm not really... not really sure what happens at one centimeter away... 'cause it's my first time. I don't really understand it either. Seriously. But in the flow of calamity... there's nobody who can attack me. Not a single person. That, I know for sure. Wonder of U.\",\"lastViewed\":\"2022-09-27\"}}]";
|
||||
// //:TODO TEMP!!!
|
||||
//
|
||||
// let notes: Note[] = JSON.parse(jsonStr);
|
||||
import {StrapiNoteRepository} from "../models/StrapiNoteRepository";
|
||||
|
||||
const noteRepo: StrapiNoteRepository = StrapiNoteRepository.getInstance();
|
||||
let notes: Note[];
|
||||
|
||||
onMount(async () => {
|
||||
const response = await bearerFetch(endpoint, jwt);
|
||||
let data = await response.json();
|
||||
notes = data.data;
|
||||
notes = await noteRepo.getNotes();
|
||||
notes.forEach(note => {
|
||||
note.attributes.lastViewed = new Date(note.attributes.lastViewed);
|
||||
note.lastViewed = new Date(note.lastViewed);
|
||||
});
|
||||
console.log(notes);
|
||||
});
|
||||
|
||||
/**
|
||||
* Reloads the Notes Listing
|
||||
* (by doing something very intelligent)
|
||||
* Adds a Note with the title "New Note" and redirects to editor
|
||||
*/
|
||||
function reloadNotesListing() {
|
||||
notes = notes.filter(i => i === i);
|
||||
async function addNoteHandler() {
|
||||
const newTitle = "New Note";
|
||||
const newNote = await addNote(newTitle);
|
||||
noteRepo.currentNoteId = newNote.id;
|
||||
console.log(newNote.id);
|
||||
window.location = "/editor";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives the user a prompt to input the new title of the note and creates it if the title is valid
|
||||
*/
|
||||
function addNotePrompt() {
|
||||
let newTitle = prompt('Name of the new Note');
|
||||
console.log(notes)
|
||||
if (newTitle != null && newTitle != '') {
|
||||
addNote(newTitle);
|
||||
console.log(notes)
|
||||
reloadNotesListing();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new note to the "notes" Array with:
|
||||
* * the latest id + 1 (or 0 if no notes exist)
|
||||
* * no content
|
||||
* * the current date as the "lastViewed" property
|
||||
* Adds a new note to the Database
|
||||
* @param title The title of the new Note
|
||||
* @return The created Note Object
|
||||
*/
|
||||
function addNote(title: string) {
|
||||
const date = new Date();
|
||||
const newNoteId: number = (notes.length == 0) ? 0 : notes[notes.length - 1].id + 1
|
||||
const note: Note = {
|
||||
id: newNoteId,
|
||||
attributes: {
|
||||
title: title,
|
||||
content: "",
|
||||
lastViewed: date
|
||||
}
|
||||
};
|
||||
notes.push(note);
|
||||
async function addNote(title: string) : Promise<Note> {
|
||||
return await noteRepo.createNote({title: title,});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -82,6 +51,7 @@
|
|||
*/
|
||||
function deleteNote(note) {
|
||||
notes = notes.filter(i => i !== note);
|
||||
noteRepo.deleteNote(note.id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -106,7 +76,7 @@
|
|||
*/
|
||||
function onNoteLiClick(note) {
|
||||
window.location = "/editor";
|
||||
note.attributes.lastViewed = new Date();
|
||||
note.lastViewed = new Date();
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
@ -126,7 +96,7 @@
|
|||
<div class="row">
|
||||
<!-- Add Note Button -->
|
||||
<div class="offset-md-7 col-md-1">
|
||||
<button class="btn btn-primary" on:click={() => addNotePrompt()}>Add Note</button>
|
||||
<button class="btn btn-primary" on:click={() => addNoteHandler()}>Add Note</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -141,10 +111,10 @@
|
|||
<div class="row">
|
||||
<div class="col-10" on:click={() => onNoteLiClick(note)}>
|
||||
<div>
|
||||
{note.attributes.title}
|
||||
{note.title}
|
||||
</div>
|
||||
<div class="list-date-text">
|
||||
{note.attributes.lastViewed.toLocaleDateString()}
|
||||
{note.lastViewed.toLocaleDateString()}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue