working on notes

This commit is contained in:
2025-07-28 21:31:26 +02:00
parent 6600b6fd27
commit 325dffa3fe
9 changed files with 102 additions and 40 deletions

View File

@@ -0,0 +1,55 @@
<script>
import { onMount } from 'svelte';
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
import Editor from '../../Components/MarkdownEditor.svelte';
let error = $state(null);
let { module = null, entity_id = null } = $props();
let note = $state({source:null,rendered:null});
let notes = $state(null);
async function onclick(){
alert(note.source);
const url = api(`notes/${module}/${entity_id}`);
const resp = await fetch(url,{
credentials:'include',
method:'POST',
body:note.source
});
if (resp.ok){
} else {
error = await resp.text();
}
}
async function load(){
const url = api(`notes/${module}/${entity_id}`);
const resp = await fetch(url,{credentials:'include'});
if (resp.ok){
notes = await resp.json();
} else {
error = await resp.text();
}
}
onMount(load)
</script>
<h1>{t('notes')}</h1>
{#if error}
<span class="error">{error}</span>
{/if}
{#if notes}
{#each Object.entries(notes) as [a,b]}
<fieldset>
<legend>User {b.user_id} {b.timestamp.replace('T',' ')}</legend>
{@html b.rendered}
</fieldset>
{/each}
{/if}
<Editor simple={true} bind:value={note} />
<button {onclick}>{t('save_note')}</button>