funktioniert mit actual strapi JSON layout
This commit is contained in:
parent
5453691016
commit
fe1d24a23e
3 changed files with 67 additions and 60 deletions
|
|
@ -1,6 +1,11 @@
|
||||||
export interface Note {
|
export interface Note {
|
||||||
id: number;
|
id: number;
|
||||||
|
attributes: Attribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Attribute {
|
||||||
title: string;
|
title: string;
|
||||||
content: string;
|
content: string;
|
||||||
lastOpened: string;
|
|
||||||
|
lastViewed: Date;
|
||||||
}
|
}
|
||||||
|
|
@ -5,14 +5,11 @@
|
||||||
|
|
||||||
const endpoint = "/notes";
|
const endpoint = "/notes";
|
||||||
|
|
||||||
let notes: Note[];
|
//:TODO TEMP!!!
|
||||||
// onMount(async () => {
|
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\"}}]";
|
||||||
// const response = await bearerFetch(endpoint, jwt);
|
//:TODO TEMP!!!
|
||||||
// debugger;
|
|
||||||
// var data = await response.json();
|
|
||||||
// console.log("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
let notes: Note[] = JSON.parse(jsonStr);
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
console.log("snasidbsa dghsasa");
|
console.log("snasidbsa dghsasa");
|
||||||
});
|
});
|
||||||
|
|
@ -34,29 +31,31 @@
|
||||||
let newTitle = prompt('Name of the new Note');
|
let newTitle = prompt('Name of the new Note');
|
||||||
console.log(notes)
|
console.log(notes)
|
||||||
if (newTitle != null && newTitle != '') {
|
if (newTitle != null && newTitle != '') {
|
||||||
addNote(newTitle);
|
// addNote(newTitle);
|
||||||
console.log(notes)
|
console.log(notes)
|
||||||
reloadNotesListing();
|
reloadNotesListing();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// //so a schas
|
||||||
* Adds a new note to the "notes" Array with:
|
// /**
|
||||||
* * the latest id + 1 (or 0 if no notes exist)
|
// * Adds a new note to the "notes" Array with:
|
||||||
* * no content
|
// * * the latest id + 1 (or 0 if no notes exist)
|
||||||
* @param title The title of the new Note
|
// * * no content
|
||||||
*/
|
// * @param title The title of the new Note
|
||||||
function addNote(title: string) {
|
// */
|
||||||
let date = new Date();
|
// function addNote(title: string) {
|
||||||
let newNoteId = (notes.length == 0) ? 0 : notes[notes.length - 1].id + 1
|
// let date = new Date();
|
||||||
let note: Note = {
|
// let newNoteId = (notes.length == 0) ? 0 : notes[notes.length - 1].id + 1
|
||||||
id: newNoteId,
|
// let note: Note = {
|
||||||
title: title,
|
// id: newNoteId,
|
||||||
content: "",
|
// attributes:
|
||||||
lastOpened: date.toISOString()
|
// title: title,
|
||||||
};
|
// content: "",
|
||||||
notes.push(note);
|
// lastOpened: date.toISOString()
|
||||||
}
|
// };
|
||||||
|
// notes.push(note);
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gives the user a prompt if they are sure to delete this note and deletes it if they confirm
|
* Gives the user a prompt if they are sure to delete this note and deletes it if they confirm
|
||||||
|
|
@ -121,6 +120,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="offset-md-4 col-md-4">
|
<div class="offset-md-4 col-md-4">
|
||||||
|
{#if notes.length !== 0}
|
||||||
<!-- Notes listing -->
|
<!-- Notes listing -->
|
||||||
<ul>
|
<ul>
|
||||||
{#each notes as note}
|
{#each notes as note}
|
||||||
|
|
@ -129,8 +129,8 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-10" on:click={() => onNoteLiClick(note)}>
|
<div class="col-md-10" on:click={() => onNoteLiClick(note)}>
|
||||||
<span>
|
<span>
|
||||||
{note.title} <br/>
|
{note.attributes.title} <br/>
|
||||||
{note.lastOpened}
|
{note.attributes.lastViewed}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-1">
|
<div class="col-md-1">
|
||||||
|
|
@ -143,6 +143,7 @@
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,18 @@
|
||||||
import {bearerFetch, jwt} from "../models/PomeloUtils";
|
import {bearerFetch, jwt} from "../models/PomeloUtils";
|
||||||
|
|
||||||
/** @type {import('./$types').PageLoad} */
|
// /** @type {import('./$types').PageLoad} */
|
||||||
export async function load({params}) {
|
// export async function load() {
|
||||||
let invalid = !jwt;
|
// let invalid = !jwt;
|
||||||
|
//
|
||||||
if (!invalid) {
|
// if (!invalid) {
|
||||||
const request = await bearerFetch("/users/me", jwt);
|
// const request = await bearerFetch("/users/me", jwt);
|
||||||
const response = await request.json();
|
// const response = await request.json();
|
||||||
|
//
|
||||||
invalid = "error" in response;
|
// invalid = "error" in response;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (invalid) {
|
// if (invalid) {
|
||||||
// window.location = "/login";
|
// // @ts-ignore
|
||||||
}
|
// window.location = "/login";
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
Loading…
Add table
Add a link
Reference in a new issue