summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/NoteRow.svelte
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/lib/ui/NoteRow.svelte')
-rw-r--r--web/src/lib/ui/NoteRow.svelte57
1 files changed, 57 insertions, 0 deletions
diff --git a/web/src/lib/ui/NoteRow.svelte b/web/src/lib/ui/NoteRow.svelte
new file mode 100644
index 0000000..34af63e
--- /dev/null
+++ b/web/src/lib/ui/NoteRow.svelte
@@ -0,0 +1,57 @@
+<!--
+ A note row (the reference `NoteRowWidget`, Phase 3 placeholder): a
+ free-form coloured row. Tapping it edits the text inline and commits
+ through `setNoteRowText`.
+-->
+<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
+ import type { NoteRowItem } from '$lib/protocol/types';
+
+ let {
+ session,
+ item
+ }: {
+ session: GameSession;
+ item: NoteRowItem;
+ } = $props();
+
+ const player = session.player;
+
+ let editing = $state(false);
+ let draft = $state(item.text);
+
+ function colorCss(color: number): string {
+ return `#${color.toString(16).padStart(8, '0').slice(2)}`;
+ }
+
+ function startEdit() {
+ if (!$player) return;
+ draft = item.text;
+ editing = true;
+ }
+
+ function commit() {
+ editing = false;
+ if (draft !== item.text) {
+ session.command('setNoteRowText', { text: draft, noteId: item.id });
+ }
+ }
+</script>
+
+<div class="row row--note" style:background-color={colorCss(item.color)}>
+ <div class="note__text">
+ {#if editing}
+ <input
+ class="search"
+ style="margin: 0; width: 100%"
+ bind:value={draft}
+ onblur={commit}
+ onkeydown={(e) => {
+ if (e.key === 'Enter') commit();
+ }}
+ />
+ {:else}
+ <button class="note__edit" onclick={startEdit}>{item.text || '…'}</button>
+ {/if}
+ </div>
+</div>