From 46b576a074879fb851df9a86033182138dab3586 Mon Sep 17 00:00:00 2001 From: elonen Date: Thu, 6 Jun 2024 22:40:05 +0300 Subject: [PATCH] Client: Improve subtitle edit UI --- .../src/lib/player_view/SubtitleCard.svelte | 58 ++++++++++++------- client/src/stores.ts | 2 + 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/client/src/lib/player_view/SubtitleCard.svelte b/client/src/lib/player_view/SubtitleCard.svelte index bbf0a7f..646cc55 100644 --- a/client/src/lib/player_view/SubtitleCard.svelte +++ b/client/src/lib/player_view/SubtitleCard.svelte @@ -2,7 +2,7 @@ import { createEventDispatcher } from 'svelte'; import { scale, slide } from "svelte/transition"; -import { curSubtitle, curUserId, curUserIsAdmin, curVideo } from '@/stores'; +import { curSubtitle, curUserId, curUserIsAdmin, curVideo, subtitleEditingId } from '@/stores'; import * as Proto3 from '@clapshot_protobuf/typescript'; const dispatch = createEventDispatcher(); @@ -10,16 +10,25 @@ const dispatch = createEventDispatcher(); export let sub: Proto3.Subtitle; export let isDefault: boolean = false; -let showEditor: boolean = false; function doSave() { dispatch("update-subtitle", {sub, isDefault}); - showEditor = false; + $subtitleEditingId = null; } function doDelete() { dispatch("delete-subtitle", {id: sub.id}); - showEditor = false; + $subtitleEditingId = null; +} + +function toggleEditing() { + $subtitleEditingId = ($subtitleEditingId == sub.id ? null : sub.id); +} + +function handleKeyDown(event: { key: string; }) { + if (event.key === 'Escape') { + $subtitleEditingId = null; + } } @@ -29,6 +38,7 @@ function doDelete() { {#if $curVideo?.userId == $curUserId || $curUserIsAdmin} - + {/if} -{#if showEditor} -
+{#if $subtitleEditingId == sub.id} + +
- +
-
- - +
+
+ + +
+
+ + +
-
- - -
-
- +
+ +
+
+ + Download +
- - - {/if} diff --git a/client/src/stores.ts b/client/src/stores.ts index f4a9a65..7803af4 100644 --- a/client/src/stores.ts +++ b/client/src/stores.ts @@ -17,7 +17,9 @@ export let curUserIsAdmin: Writable = writable(false); export let curUserPic: Writable = writable(null); export let allComments: Writable = writable([]); + export let curSubtitle: Writable = writable(null); +export let subtitleEditingId: Writable = writable(null); export let userMessages: Writable = writable([]); export let latestProgressReports: Writable = writable([]);