working on project creation
This commit is contained in:
37
frontend/src/Components/CompanySelector.svelte
Normal file
37
frontend/src/Components/CompanySelector.svelte
Normal file
@@ -0,0 +1,37 @@
|
||||
<script>
|
||||
import {onMount} from 'svelte';
|
||||
import {t} from '../translations.svelte.js';
|
||||
let { caption, onselect = (company) => console.log('selected '+company.name) } = $props();
|
||||
let message = t('loading');
|
||||
let companies = $state(null);
|
||||
let value = 0;
|
||||
|
||||
async function loadCompanies(){
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/company/list`;
|
||||
var resp = await fetch(url,{ credentials: 'include'});
|
||||
if (resp.ok){
|
||||
companies = await resp.json();
|
||||
} else {
|
||||
message = await resp.text();
|
||||
}
|
||||
}
|
||||
|
||||
function select(){
|
||||
onselect(companies[value]);
|
||||
}
|
||||
|
||||
onMount(loadCompanies)
|
||||
|
||||
</script>
|
||||
|
||||
{#if companies}
|
||||
<select onchange={select} bind:value>
|
||||
<option value={0}>{caption}</option>
|
||||
{#each companies as company,idx}
|
||||
<option value={idx}>{company.name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
{:else}
|
||||
<span>{message}</span>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user