working on editor for polls

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-02-15 10:59:19 +01:00
parent dbc4525e80
commit a25736eff3
9 changed files with 277 additions and 16 deletions

View File

@@ -0,0 +1,88 @@
<script>
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import LineEditor from '../../Components/LineEditor.svelte';
import MarkdownEditor from '../../Components/MarkdownEditor.svelte';
import { api, get } from '../../urls.svelte';
import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte';
import { user } from '../../user.svelte.js';
let { id } = $props();
let poll = $state(null);
async function load(){
let url = api('poll/'+id);
let res = await get(url);
if (res.ok){
poll = await res.json();
yikes();
} else error(res);
}
onMount(load);
</script>
<fieldset>
<legend>{t('edit poll',{id:id})}</legend>
{#if poll && poll.name}
<fieldset>
<legend>{t('name')}</legend>
<LineEditor bind:value={poll.name} editable={true} />
</fieldset>
<fieldset>
<legend>{t('description')}</legend>
<MarkdownEditor bind:value={poll.description} />
</fieldset>
<fieldset>
<legend>{t('options')}</legend>
<table>
<thead>
<tr>
<th>{t('name')}</th>
<th>{t('description')}</th>
</tr>
</thead>
<tbody>
{#each poll.options as option}
<tr>
<td>
<input type="text" value={option.name} />
</td>
<td>
<MarkdownEditor bind:value={option.description} />
</td>
</tr>
{/each}
</tbody>
</table>
</fieldset>
<fieldset>
<legend>{t('weights')}</legend>
<table>
<thead>
<tr>
<th>{t('weight')}</th>
<th>{t('description')}</th>
</tr>
</thead>
<tbody>
{#each Object.entries(poll.weights) as [weight,descr]}
<tr>
<td>
<input type="number" value={weight} />
</td>
<td>
<input type="text" value={descr} />
</td>
</tr>
{/each}
</tbody>
</table>
</fieldset>
{/if}
</fieldset>