You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
907 B
30 lines
907 B
<script> |
|
import {onMount} from 'svelte'; |
|
import {t} from '../translations.svelte.js'; |
|
let { caption = t('select_state'), selected = $bindable(0), onchange = (val) => console.log('changed to '+val)} = $props(); |
|
|
|
let message = $state(t('loading')); |
|
let states = $state(null); |
|
|
|
async function loadStates(){ |
|
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/task/states`; |
|
var resp = await fetch(url,{credentials: 'include'}); |
|
if (resp.ok){ |
|
states = await resp.json(); |
|
} else { |
|
message = await resp.text(); |
|
} |
|
} |
|
|
|
onMount(loadStates) |
|
</script> |
|
|
|
{#if states} |
|
<select bind:value={selected} onchange={() => onchange(selected)}> |
|
{#each Object.entries(states) as [k,s]} |
|
<option value={+k}>{t('state_'+s.toLowerCase())}</option> |
|
{/each} |
|
</select> |
|
{:else} |
|
<span>{message}</span> |
|
{/if} |