diff --git a/client/src/App.svelte b/client/src/App.svelte index 7a51ffa..c31e349 100644 --- a/client/src/App.svelte +++ b/client/src/App.svelte @@ -4,7 +4,7 @@ import {fade, slide} from "svelte/transition"; import * as Proto3 from '@clapshot_protobuf/typescript'; -import {allComments, allSubtitles, curUsername, curUserId, videoIsReady, videoPlaybackUrl, videoOrigUrl, mediaFileId, videoFps, videoTitle, curPageId, curPageItems, userMessages, latestProgressReports, collabId, userMenuItems, serverDefinedActions, curUserIsAdmin, connectionErrors, curSubtitle, defaultSubtitleId, videoOwnerId} from './stores'; +import {allComments, curUsername, curUserId, videoIsReady, mediaFileId, curVideo, curPageId, curPageItems, userMessages, latestProgressReports, collabId, userMenuItems, serverDefinedActions, curUserIsAdmin, connectionErrors, curSubtitle} from './stores'; import {IndentedComment, type UserMenuItem, type StringMap, type MediaProgressReport} from "./types"; import CommentCard from './lib/player_view/CommentCard.svelte' @@ -128,12 +128,13 @@ function onCommentInputButton(e: any) { } function onDisplayComment(e: any) { + if (!$curVideo) { throw Error("No video loaded"); } videoPlayer.seekToSMPTE(e.detail.timecode); // Close draw mode while showing (drawing from a saved) comment videoPlayer.onToggleDraw(false); commentInput.forceDrawMode(false); if (e.detail.drawing) { videoPlayer.setDrawing(e.detail.drawing); } - if (e.detail.subtitleId) { $curSubtitle = $allSubtitles.find((s) => s.id == e.detail.subtitleId) ?? null; } + if (e.detail.subtitleId) { $curSubtitle = $curVideo.subtitles.find((s) => s.id == e.detail.subtitleId) ?? null; } if ($collabId) { logAbbrev("Collab: onDisplayComment. collab_id: '" + $collabId + "'"); wsEmit({collabReport: { @@ -172,12 +173,8 @@ function closePlayerIfOpen() { wsEmit({leaveCollab: {}}); $collabId = null; $mediaFileId = null; - $videoPlaybackUrl = null; - $videoFps = null; - $videoTitle = null; - $videoOwnerId = null; + $curVideo = null; $allComments = []; - $allSubtitles = []; $videoIsReady = false; } @@ -207,11 +204,12 @@ function onCommentPinClicked(e: any) { function onSubtitleChange(e: any) { const sub_id = e.detail.id; - console.debug("onSubtitleChange, id:", sub_id, "allSubtitles:", $allSubtitles); + if (!$curVideo) { throw Error("No video loaded"); } + console.debug("onSubtitleChange, id:", sub_id, "allSubtitles:", $curVideo.subtitles); if ($curSubtitle?.id == sub_id) { $curSubtitle = null; } else { - $curSubtitle = $allSubtitles.find((s) => s.id == sub_id) ?? null; + $curSubtitle = $curVideo.subtitles.find((s) => s.id == sub_id) ?? null; if ($curSubtitle == null && sub_id != null) { console.error("Subtitle not found: ", sub_id); acts.add({mode: 'error', message: "Subtitle not found. See log.", lifetime: 5}); @@ -708,22 +706,15 @@ function connectWebsocketAfterAuthCheck(ws_url: string) document.title = "Clapshot - " + (v.title ?? v.id); } - $videoPlaybackUrl = v.playbackUrl; - $videoOrigUrl = v.origUrl ?? null; $mediaFileId = v.id; - $videoFps = parseFloat(v.duration.fps); - if (isNaN($videoFps)) throw Error("Invalid FPS"); - $videoTitle = v.title; - $videoOwnerId = v.userId; - $allSubtitles = [...v.subtitles]; + $curVideo = v; $allComments = []; - $defaultSubtitleId = v.defaultSubtitleId ?? null; - if ($defaultSubtitleId) { - $curSubtitle = $allSubtitles.find((s) => s.id == $defaultSubtitleId) ?? null; + if (v.defaultSubtitleId) { + $curSubtitle = $curVideo.subtitles.find((s) => s.id == v.defaultSubtitleId) ?? null; } else { let old_id = $curSubtitle?.id; - $curSubtitle = $allSubtitles.find((s) => s.id == old_id) ?? null; + $curSubtitle = $curVideo.subtitles.find((s) => s.id == old_id) ?? null; } if ($collabId) @@ -927,7 +918,7 @@ function onMediaFileListPopupAction(e: { detail: { action: Proto3.ActionDef, ite - {:else if $mediaFileId} + {:else if $mediaFileId && $curVideo && $curVideo.playbackUrl}
@@ -935,7 +926,7 @@ function onMediaFileListPopupAction(e: { detail: { action: Proto3.ActionDef, ite
- -
-
Subtitles
- -
- {#each $allSubtitles as sub} - - {/each} + {#if $curVideo.subtitles} + +
+
Subtitles
+ +
+ {#each $curVideo.subtitles as sub} + + {/each} + {/if}
{/if} diff --git a/client/src/lib/NavBar.svelte b/client/src/lib/NavBar.svelte index 48138be..c6eff4a 100644 --- a/client/src/lib/NavBar.svelte +++ b/client/src/lib/NavBar.svelte @@ -1,7 +1,7 @@