9 changed files with 102 additions and 40 deletions
@ -0,0 +1,55 @@
@@ -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> |
||||
Loading…
Reference in new issue