Browse Source

preparing for member addition to project:

- implemented Autocomplete
- next up:
    - bubble up requested user
    - add as member
kanban
Stephan Richter 4 months ago
parent
commit
38bc00df29
  1. 19
      frontend/src/Components/Autocomplete.svelte
  2. 9
      frontend/src/Components/MemberEditor.svelte

19
frontend/src/Components/Autocomplete.svelte

@ -2,10 +2,10 @@ @@ -2,10 +2,10 @@
import { t } from '../translations.svelte.js'
import { tick } from "svelte";
let { getOptionsFor = text => [], onSelect = text => [] } = $props();
let { getOptionsFor = text => {}, onSelect = text => [] } = $props();
let text = $state('')
let options = $state([]);
let options = $state({});
async function onkeyup(evt){
var select = evt.target;
@ -17,9 +17,12 @@ @@ -17,9 +17,12 @@
return;
}
if (key == 'Enter'){
text = select.value;
onSelect(text);
options=[];
let key = select.value;
text = options[key];
let result = {};
result[key]=text;
options={};
onSelect(result);
return;
}
if (key == 'Backspace'){
@ -38,10 +41,10 @@ @@ -38,10 +41,10 @@
min-width: 200px;
}
</style>
<select size={options.length<2?2:options.length+1} {onkeyup} autofocus width="40">
<select size={Object.keys(options).length<2?2:Object.keys(options).length+1} {onkeyup} autofocus width="40">
<option>{text}</option>
{#each options as option,i}
<option>{option}</option>
{#each Object.entries(options) as [val,caption]}
<option value={val}>{caption}</option>
{/each}
</select>

9
frontend/src/Components/MemberEditor.svelte

@ -28,14 +28,7 @@ @@ -28,14 +28,7 @@
});
if (resp.ok){
var json = await resp.json();
if (Array.isArray(json)) return json;
if (typeof json == 'object'){
let names = Object.values(json).map(user => user.name);
if (names.length > 10) names.length = 10;
return names;
}
console.warn('not an array:',json);
return [];
return Object.fromEntries(Object.values(json).map(user => [user.id,user.name]));
} else {
return [];
}

Loading…
Cancel
Save