Notes are now displayed in order of the "lastOpened" property
The Note interface was moved to types.ts
This commit is contained in:
parent
2705fe27ef
commit
395a9dc2e8
3 changed files with 39 additions and 17 deletions
|
|
@ -1,15 +1,12 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
interface Note {
|
import type {Note} from "../types";
|
||||||
id: number;
|
|
||||||
title: string;
|
|
||||||
content: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: TEMP!!!
|
//TODO: TEMP!!!
|
||||||
const tempJson = "[{\"id\":0,\"title\":\"samc\",\"content\":\"SAAAAAAAAAAMC\"},{\"id\":1,\"title\":\"Push\",\"content\":\"Kollege Pusch\"},{\"id\":2,\"title\":\"Mike\",\"content\":\"C Meister\"},{\"id\":3,\"title\":\"kekw\",\"content\":\"OMEGALUL\"}]";
|
const tempJson = "[{\"id\":0,\"title\":\"samc\",\"content\":\"SAAAAAAAAAAMC\",\"lastOpened\":\"2022-09-25T10:45:49.903Z\"},{\"id\":1,\"title\":\"Push\",\"content\":\"Kollege Pusch\",\"lastOpened\":\"2022-09-25T10:50:49.903Z\"},{\"id\":2,\"title\":\"Mike\",\"content\":\"C Meister\",\"lastOpened\":\"2022-09-25T10:09:13.903Z\"},{\"id\":3,\"title\":\"kekw\",\"content\":\"OMEGALUL\",\"lastOpened\":\"2022-09-25T12:03:49.903Z\"}]";
|
||||||
//TODO: TEMP!!!
|
//TODO: TEMP!!!
|
||||||
|
|
||||||
let notes: Note[] = JSON.parse(tempJson);
|
let notes: Note[] = JSON.parse(tempJson);
|
||||||
|
sortNotesByDate();
|
||||||
window.localStorage.setItem("notes", JSON.stringify(notes));
|
window.localStorage.setItem("notes", JSON.stringify(notes));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -20,31 +17,51 @@
|
||||||
notes = notes.filter(i => i === i);
|
notes = notes.filter(i => i === i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sortNotesByDate(){
|
||||||
|
notes.sort(function(x, y) {
|
||||||
|
if (x.lastOpened > y.lastOpened) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.lastOpened < y.lastOpened) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gives the user a prompt to input the new title of the note and creates it if the title is valid
|
* Gives the user a prompt to input the new title of the note and creates it if the title is valid
|
||||||
*/
|
*/
|
||||||
function addNotePrompt() {
|
function addNotePrompt() {
|
||||||
let newTitle = prompt('Name of the new Note');
|
let newTitle = prompt('Name of the new Note');
|
||||||
|
console.log(notes)
|
||||||
if (newTitle != null && newTitle != '') {
|
if (newTitle != null && newTitle != '') {
|
||||||
addNote(newTitle);
|
addNote(newTitle);
|
||||||
|
console.log(notes)
|
||||||
|
sortNotesByDate();
|
||||||
|
reloadNotesListing();
|
||||||
window.localStorage.setItem("notes", JSON.stringify(notes));
|
window.localStorage.setItem("notes", JSON.stringify(notes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new note to the "notes" Array with:
|
* Adds a new note to the "notes" Array with:
|
||||||
* * the latest id + 1
|
* * the latest id + 1 (or 0 if no notes exist)
|
||||||
* * no content
|
* * no content
|
||||||
* @param title The title of the new Note
|
* @param title The title of the new Note
|
||||||
*/
|
*/
|
||||||
function addNote(title: string) {
|
function addNote(title: string) {
|
||||||
|
let date = new Date();
|
||||||
|
let newNoteId = (notes.length == 0) ? 0 : notes[notes.length - 1].id + 1
|
||||||
let note: Note = {
|
let note: Note = {
|
||||||
id: notes[notes.length - 1].id + 1,
|
id: newNoteId,
|
||||||
title: title,
|
title: title,
|
||||||
content: ""
|
content: "",
|
||||||
|
lastOpened: date.toISOString()
|
||||||
};
|
};
|
||||||
notes.push(note);
|
notes.push(note);
|
||||||
reloadNotesListing()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -64,6 +81,7 @@
|
||||||
integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
|
integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
<html lang="en">
|
||||||
<!-- Add Note Button -->
|
<!-- Add Note Button -->
|
||||||
<!-- ➕ is a Thiccc Plus UTF-8 Character -->
|
<!-- ➕ is a Thiccc Plus UTF-8 Character -->
|
||||||
<div class="offset-8 col-1">
|
<div class="offset-8 col-1">
|
||||||
|
|
@ -86,6 +104,7 @@
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
</html>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
html,
|
html,
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,12 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
interface Note {
|
import type {Note} from "../../types";
|
||||||
id: number;
|
|
||||||
title: string;
|
|
||||||
content: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
let notes: Note[] = JSON.parse(window.localStorage.getItem("notes"));
|
let notes: Note[] = JSON.parse(window.localStorage.getItem("notes"));
|
||||||
const clickedNoteId = window.localStorage.getItem("clickedNoteId");
|
const clickedNoteId = window.localStorage.getItem("clickedNoteId");
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
|
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>{"Pomelonote | Edit " + notes[clickedNoteId].title}</title>
|
<title>{"Pomelonote | Edit " + notes[clickedNoteId].title}</title>
|
||||||
|
|
@ -19,6 +14,8 @@
|
||||||
integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
|
integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
<html lang="en">
|
||||||
<div class="offset-3 col-6">
|
<div class="offset-3 col-6">
|
||||||
samc samg ccocooc {notes[clickedNoteId].content}
|
samc samg ccocooc {notes[clickedNoteId].content}
|
||||||
</div>
|
</div>
|
||||||
|
</html>
|
||||||
|
|
|
||||||
6
frontend/svelte/src/types.ts
Normal file
6
frontend/svelte/src/types.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
export interface Note {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
content: string;
|
||||||
|
lastOpened: string;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue