Merge branch 'listing' into develop
This commit is contained in:
commit
22396d1a00
13 changed files with 86 additions and 57 deletions
|
|
@ -87,7 +87,8 @@ module.exports = createCoreController(noteUid, ({strapi}) => ({
|
||||||
*/
|
*/
|
||||||
async create(ctx) {
|
async create(ctx) {
|
||||||
const userId = ctx.state.user.id;
|
const userId = ctx.state.user.id;
|
||||||
const requestBody = ctx.request.body;
|
const requestBody = JSON.parse(ctx.request.body);
|
||||||
|
console.log(requestBody);
|
||||||
const response = await strapi.entityService.create(noteUid, {
|
const response = await strapi.entityService.create(noteUid, {
|
||||||
data: {
|
data: {
|
||||||
title: requestBody.data.title,
|
title: requestBody.data.title,
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,16 @@
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<link rel="icon" href="../src/resources/images/logo2.svg" />
|
<link rel="icon" href="../src/resources/images/logo2.svg" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
|
<link rel="manifest" href="../static/manifest.json">
|
||||||
%sveltekit.head%
|
%sveltekit.head%
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div>%sveltekit.body%</div>
|
<div>%sveltekit.body%</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
if('serviceworker' in navigator){
|
||||||
|
navigator.serviceworker.register('./service-worker.js');
|
||||||
|
}
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,13 @@ export class StrapiNoteRepository implements NoteRepository {
|
||||||
|
|
||||||
private constructor() {}
|
private constructor() {}
|
||||||
|
|
||||||
private currentNoteId: number | undefined;
|
private _currentNoteId: number | undefined;
|
||||||
private static apiNoteEndpoint: string = "http://localhost:1337/api/notes"
|
private static apiNoteEndpoint: string = "http://localhost:1337/api/notes"
|
||||||
|
|
||||||
|
public set currentNoteId(value: number | undefined) {
|
||||||
|
this._currentNoteId = value;
|
||||||
|
}
|
||||||
|
|
||||||
public async getNotes(): Promise<Note[]>{
|
public async getNotes(): Promise<Note[]>{
|
||||||
const response = await StrapiNoteRepository.fetchStrapiNoteEndpoint("/", 'GET');
|
const response = await StrapiNoteRepository.fetchStrapiNoteEndpoint("/", 'GET');
|
||||||
return await response.json();
|
return await response.json();
|
||||||
|
|
@ -29,10 +33,10 @@ export class StrapiNoteRepository implements NoteRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getCurrentNote(): Promise<Note | void> {
|
public async getCurrentNote(): Promise<Note | void> {
|
||||||
if (this.currentNoteId === null || this.currentNoteId === undefined) {
|
if (this._currentNoteId === null || this._currentNoteId === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return await this.getNote(this.currentNoteId);
|
return await this.getNote(this._currentNoteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateNote(id: number, note: Partial<Note>): Promise<Note> {
|
public async updateNote(id: number, note: Partial<Note>): Promise<Note> {
|
||||||
|
|
@ -53,7 +57,7 @@ export class StrapiNoteRepository implements NoteRepository {
|
||||||
let requestInit: RequestInit = {
|
let requestInit: RequestInit = {
|
||||||
method: method,
|
method: method,
|
||||||
headers: {
|
headers: {
|
||||||
authorization: StrapiNoteRepository.mockedGetAuthorizationHeader()
|
authorization: StrapiNoteRepository.getAuthorizationHeader()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (body) {
|
if (body) {
|
||||||
|
|
|
||||||
BIN
frontend/svelte/src/resources/icons/android-icon-144x144.png
Normal file
BIN
frontend/svelte/src/resources/icons/android-icon-144x144.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
BIN
frontend/svelte/src/resources/icons/android-icon-192x192.png
Normal file
BIN
frontend/svelte/src/resources/icons/android-icon-192x192.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
BIN
frontend/svelte/src/resources/icons/android-icon-36x36.png
Normal file
BIN
frontend/svelte/src/resources/icons/android-icon-36x36.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
BIN
frontend/svelte/src/resources/icons/android-icon-48x48.png
Normal file
BIN
frontend/svelte/src/resources/icons/android-icon-48x48.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
BIN
frontend/svelte/src/resources/icons/android-icon-72x72.png
Normal file
BIN
frontend/svelte/src/resources/icons/android-icon-72x72.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.4 KiB |
BIN
frontend/svelte/src/resources/icons/android-icon-96x96.png
Normal file
BIN
frontend/svelte/src/resources/icons/android-icon-96x96.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
|
|
@ -1,68 +1,37 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type {Note} from "../models/types";
|
import type {Note} from "../models/types";
|
||||||
import {onMount} from "svelte";
|
import {onMount} from "svelte";
|
||||||
import {bearerFetch, jwt} from "../models/PomeloUtils";
|
import {StrapiNoteRepository} from "../models/StrapiNoteRepository";
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
const noteRepo: StrapiNoteRepository = StrapiNoteRepository.getInstance();
|
||||||
let notes: Note[];
|
let notes: Note[];
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const response = await bearerFetch(endpoint, jwt);
|
notes = await noteRepo.getNotes();
|
||||||
let data = await response.json();
|
|
||||||
notes = data.data;
|
|
||||||
notes.forEach(note => {
|
notes.forEach(note => {
|
||||||
note.attributes.lastViewed = new Date(note.attributes.lastViewed);
|
note.lastViewed = new Date(note.lastViewed);
|
||||||
});
|
});
|
||||||
console.log(notes);
|
console.log(notes);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reloads the Notes Listing
|
* Adds a Note with the title "New Note" and redirects to editor
|
||||||
* (by doing something very intelligent)
|
|
||||||
*/
|
*/
|
||||||
function reloadNotesListing() {
|
async function addNoteHandler() {
|
||||||
notes = notes.filter(i => i === i);
|
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
|
* Adds a new note to the Database
|
||||||
*/
|
|
||||||
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
|
|
||||||
* @param title The title of the new Note
|
* @param title The title of the new Note
|
||||||
|
* @return The created Note Object
|
||||||
*/
|
*/
|
||||||
function addNote(title: string) {
|
async function addNote(title: string) : Promise<Note> {
|
||||||
const date = new Date();
|
return await noteRepo.createNote({title: title,});
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -82,6 +51,7 @@
|
||||||
*/
|
*/
|
||||||
function deleteNote(note) {
|
function deleteNote(note) {
|
||||||
notes = notes.filter(i => i !== note);
|
notes = notes.filter(i => i !== note);
|
||||||
|
noteRepo.deleteNote(note.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -106,7 +76,7 @@
|
||||||
*/
|
*/
|
||||||
function onNoteLiClick(note) {
|
function onNoteLiClick(note) {
|
||||||
window.location = "/editor";
|
window.location = "/editor";
|
||||||
note.attributes.lastViewed = new Date();
|
note.lastViewed = new Date();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -126,7 +96,7 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<!-- Add Note Button -->
|
<!-- Add Note Button -->
|
||||||
<div class="offset-md-7 col-md-1">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -141,10 +111,10 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-10" on:click={() => onNoteLiClick(note)}>
|
<div class="col-10" on:click={() => onNoteLiClick(note)}>
|
||||||
<div>
|
<div>
|
||||||
{note.attributes.title}
|
{note.title}
|
||||||
</div>
|
</div>
|
||||||
<div class="list-date-text">
|
<div class="list-date-text">
|
||||||
{note.attributes.lastViewed.toLocaleDateString()}
|
{note.lastViewed.toLocaleDateString()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
6
frontend/svelte/src/service-worker.js
Normal file
6
frontend/svelte/src/service-worker.js
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
importScripts('https://storage.googleapis.com/workbos-cdn/releases/6.0.2/workbox-sw.js');
|
||||||
|
|
||||||
|
workbox.routing.registerRoute(
|
||||||
|
({request}) => request.destination === 'image',
|
||||||
|
new workbox.strategies.CacheFirst()
|
||||||
|
);
|
||||||
34
frontend/svelte/static/manifest.json
Normal file
34
frontend/svelte/static/manifest.json
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
{
|
||||||
|
"background_color": "#ffffff",
|
||||||
|
"theme_color": "#ff6600",
|
||||||
|
"name": "Pomelo Note",
|
||||||
|
"short_name": "Pomelo",
|
||||||
|
"display": "minimal-ui",
|
||||||
|
"start_url": "/",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "../resources/icons/android-icon-36x36.png",
|
||||||
|
"sizes": "36x36",
|
||||||
|
"type": "image\/png",
|
||||||
|
"density": "0.75"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "../resources/icons/android-icon-48x48.png",
|
||||||
|
"sizes": "48x48",
|
||||||
|
"type": "image\/png",
|
||||||
|
"density": "1.0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "../resources/icons/android-icon-72x72.png",
|
||||||
|
"sizes": "72x72",
|
||||||
|
"type": "image\/png",
|
||||||
|
"density": "1.5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "../resources/icons/android-icon-96x96.png",
|
||||||
|
"sizes": "96x96",
|
||||||
|
"type": "image\/png",
|
||||||
|
"density": "2.0"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,14 @@ import { sveltekit } from '@sveltejs/kit/vite';
|
||||||
import type { UserConfig } from 'vite';
|
import type { UserConfig } from 'vite';
|
||||||
|
|
||||||
const config: UserConfig = {
|
const config: UserConfig = {
|
||||||
plugins: [sveltekit()]
|
plugins: [sveltekit()],
|
||||||
|
|
||||||
|
server: {
|
||||||
|
fs: {
|
||||||
|
// Allow serving files from one level up to the project root
|
||||||
|
allow: ['..'],
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default config;
|
export default config;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue