From ddfa7c639787d6d79a901e48c80e9605055b1d8a Mon Sep 17 00:00:00 2001 From: Jan Starzak Date: Fri, 19 Jan 2024 16:39:53 +0100 Subject: [PATCH] feat(Output): Primary ViewPort width feedback --- packages/apps/client/src/PrompterStyles.css | 22 +++++++++++-- .../apps/client/src/lib/getCurrentTime.ts | 5 +++ packages/apps/client/src/lib/useQueryParam.ts | 10 ++++++ .../apps/client/src/views/Output/Output.tsx | 33 ++++++++++++++++++- 4 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 packages/apps/client/src/lib/getCurrentTime.ts create mode 100644 packages/apps/client/src/lib/useQueryParam.ts diff --git a/packages/apps/client/src/PrompterStyles.css b/packages/apps/client/src/PrompterStyles.css index e87d3c9..79ea868 100644 --- a/packages/apps/client/src/PrompterStyles.css +++ b/packages/apps/client/src/PrompterStyles.css @@ -3,6 +3,9 @@ --foreground-color: #fff; --header-color: #999; + --prompter-font-size-base: 16px; + --prompter-line-height: calc(var(--prompter-font-size-base) * 1.4); + color: var(--foreground-color); background: var(--background-color); @@ -15,8 +18,8 @@ overflow: auto; box-sizing: border-box; - font-size: 16px; - line-height: 21px; + font-size: var(--prompter-font-size-base); + line-height: var(--prompter-line-height); } .Prompter p { @@ -55,6 +58,21 @@ margin: 1em 0; } +.Prompter h1 { + font-size: calc(var(--prompter-font-size-base) * 2); + line-height: 1.4; +} + +.Prompter h2 { + font-size: calc(var(--prompter-font-size-base) * 1); + line-height: 1.4; +} + +.Prompter h3 { + font-size: calc(var(--prompter-font-size-base) * 1); + line-height: 1.4; +} + .Prompter .ProseMirror { outline: none; } diff --git a/packages/apps/client/src/lib/getCurrentTime.ts b/packages/apps/client/src/lib/getCurrentTime.ts new file mode 100644 index 0000000..6ff4ff5 --- /dev/null +++ b/packages/apps/client/src/lib/getCurrentTime.ts @@ -0,0 +1,5 @@ +export function getCurrentTime(): Time { + return Date.now() +} + +export type Time = number diff --git a/packages/apps/client/src/lib/useQueryParam.ts b/packages/apps/client/src/lib/useQueryParam.ts new file mode 100644 index 0000000..c9ddc70 --- /dev/null +++ b/packages/apps/client/src/lib/useQueryParam.ts @@ -0,0 +1,10 @@ +import { useMemo } from 'react' +import { useLocation } from 'react-router-dom' + +export function useQueryParam(paramName: string): string | null { + const location = useLocation() + + const params = useMemo(() => new URLSearchParams(location.search), [location.search]) + + return params.get(paramName) +} diff --git a/packages/apps/client/src/views/Output/Output.tsx b/packages/apps/client/src/views/Output/Output.tsx index 262e970..da4edcc 100644 --- a/packages/apps/client/src/views/Output/Output.tsx +++ b/packages/apps/client/src/views/Output/Output.tsx @@ -1,14 +1,18 @@ -import React, { useEffect, useRef } from 'react' +import React, { useCallback, useEffect, useRef } from 'react' import { observer } from 'mobx-react-lite' import { RootAppStore } from 'src/stores/RootAppStore.ts' import 'src/PrompterStyles.css' import { Segment } from './Segment' import { Helmet } from 'react-helmet-async' +import { getCurrentTime } from 'src/lib/getCurrentTime' +import { useQueryParam } from 'src/lib/useQueryParam' const Output = observer(function Output(): React.ReactElement { const speed = useRef(0) + const isPrimary = useQueryParam('primary') !== null + // On startup useEffect(() => { RootAppStore.outputSettingsStore.initialize() // load and subscribe @@ -31,6 +35,33 @@ const Output = observer(function Output(): React.ReactElement { } }, []) + const onViewPortSizeChanged = useCallback(() => { + if (!isPrimary) return + + RootAppStore.connection.viewPort.update('', { + _id: '', + width: window.innerWidth / window.innerHeight, + // TODO: This should return the actual lastKnownState + lastKnownState: { + timestamp: getCurrentTime(), + controllerMessage: { + offset: null, + speed: 0, + }, + }, + }) + }, [isPrimary]) + + useEffect(() => { + window.addEventListener('resize', onViewPortSizeChanged) + + onViewPortSizeChanged() + + return () => { + window.removeEventListener('resize', onViewPortSizeChanged) + } + }, [onViewPortSizeChanged]) + const outputSettings = RootAppStore.outputSettingsStore.outputSettings const activeRundownPlaylistId = outputSettings?.activeRundownPlaylistId