frontend: properly bind marks values

This commit is contained in:
OleSTEEP 2025-10-16 17:27:13 +03:00
parent f36d5aac0c
commit a0925f9ba5
3 changed files with 17 additions and 9 deletions

View file

@ -4,19 +4,19 @@
let { value = $bindable([]), label = "" } = $props(); let { value = $bindable([]), label = "" } = $props();
let items: string[] = $state([]); let items: string[] = $state([]);
$effect(() => {value = items});
</script> </script>
<div class="marks-container input rounded"> <div class="marks-container input rounded">
<p>{label}</p> <p>{label}</p>
{#each items as item} {#each items as item, index}
<Mark text={item}/> <Mark bind:text={items[index]}/>
{/each} {/each}
<AddButton handler={() => { <AddButton handler={() => {
items.push(""); items.push(null);
value = items;
}} /> }} />
</div> </div>
<style> <style>

View file

@ -1,8 +1,11 @@
<script lang="ts"> <script lang="ts">
let { text } = $props();
let { text = $bindable() } = $props();
let compl_data = $state([]); let compl_data = $state([]);
const placeholder = "Текст";
function autocomplete() { function autocomplete() {
if (text !== "") { if (text !== "") {
fetch('http://127.0.0.1:8000/api/marks', { fetch('http://127.0.0.1:8000/api/marks', {
@ -18,14 +21,19 @@
compl_data = []; compl_data = [];
} }
} }
$effect(() => {
if (text == "") text = null;
})
</script> </script>
<div> <div>
<input type="text" <input type="text"
class="dyn-input rounded" class="dyn-input rounded"
style="width: {text.length}ch;margin:0;" style="width: {(text ?? placeholder).length}ch;margin:0;"
bind:value={text} bind:value={text}
oninput={autocomplete}> oninput={autocomplete}
{placeholder}>
{#if compl_data} {#if compl_data}
<div class="popup rounded" tabindex="0" role="button" onmousedown={(e) => {e.preventDefault();}}> <div class="popup rounded" tabindex="0" role="button" onmousedown={(e) => {e.preventDefault();}}>
{#each compl_data as item} {#each compl_data as item}

View file

@ -20,7 +20,7 @@
genres: [], genres: [],
tags: [], tags: [],
badges: [] badges: []
}) });
</script> </script>
<svelte:head> <svelte:head>