-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add RundownScript view, UIStore
- Loading branch information
Showing
11 changed files
with
217 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/apps/client/src/RundownScript/RundownScript.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.RundownScript { | ||
height: 100vh; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useEffect } from 'react' | ||
import { observer } from 'mobx-react-lite' | ||
import classes from './RundownScript.module.scss' | ||
import { CurrentRundown } from '../CurrentRundown/CurrentRundown' | ||
import { ScriptEditor } from '../ScriptEditor/ScriptEditor' | ||
import { Helmet } from 'react-helmet-async' | ||
import { RundownPlaylistId, protectString } from '@sofie-prompter-editor/shared-model' | ||
import { AppStore } from '../stores/AppStore' | ||
import { useParams } from 'react-router-dom' | ||
import { SplitPanel } from '../components/SplitPanel/SplitPanel' | ||
|
||
export const RundownScript = observer((): React.JSX.Element => { | ||
const params = useParams() | ||
|
||
const playlistId = protectString<RundownPlaylistId>(params.playlistId) | ||
|
||
useEffect(() => { | ||
if (!playlistId) return | ||
|
||
AppStore.rundownStore.loadRundown(playlistId) | ||
}, [playlistId]) | ||
|
||
return ( | ||
<> | ||
<Helmet> | ||
<title>Rundown</title> | ||
<body data-bs-theme="dark" /> | ||
</Helmet> | ||
<SplitPanel | ||
position={AppStore.uiStore.viewDividerPosition} | ||
onChange={(e) => AppStore.uiStore.setViewDividerPosition(e.value)} | ||
className={classes.RundownScript} | ||
childrenBegin={<CurrentRundown />} | ||
childrenEnd={<ScriptEditor />} | ||
/> | ||
</> | ||
) | ||
}) | ||
RundownScript.displayName = 'RundownScript' |
28 changes: 28 additions & 0 deletions
28
packages/apps/client/src/components/SplitPanel/SplitPanel.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.SplitPane { | ||
--divider-width: 5px; | ||
display: grid; | ||
grid-template-rows: auto; | ||
grid-template-columns: [PaneA] var(--position-a, 1fr) [Divider] var(--divider-width) [PaneB] var(--position-b, 1fr); | ||
gap: 2px; | ||
} | ||
|
||
.PaneA { | ||
grid-column: PaneA; | ||
overflow: auto; | ||
} | ||
|
||
.Divider { | ||
grid-column: Divider; | ||
--test: 1; | ||
cursor: ew-resize; | ||
} | ||
|
||
.Divider:hover, | ||
.DividerActive { | ||
background-color: var(--bs-primary); | ||
} | ||
|
||
.PaneB { | ||
grid-column: PaneB; | ||
overflow: auto; | ||
} |
96 changes: 96 additions & 0 deletions
96
packages/apps/client/src/components/SplitPanel/SplitPanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { ReactNode, useEffect, useMemo, useRef, useState } from 'react' | ||
import classes from './SplitPanel.module.css' | ||
|
||
export function SplitPanel({ | ||
position, | ||
onChange, | ||
childrenBegin, | ||
childrenEnd, | ||
className, | ||
}: { | ||
className?: string | ||
position?: number | ||
onChange?: ChangeEventHandler | ||
childrenBegin: ReactNode | ||
childrenEnd: ReactNode | ||
children?: null | ||
}) { | ||
const [isResizing, setIsResizing] = useState(false) | ||
const beginCoords = useRef<{ x: number; y: number } | null>(null) | ||
const initialPos = useRef<number>(position ?? 0.5) | ||
const container = useRef<HTMLDivElement>(null) | ||
const contRect = useRef<DOMRect | null>(null) | ||
|
||
const defaultedPosition = position ?? 0.5 | ||
|
||
function onMouseDown(e: React.MouseEvent) { | ||
setIsResizing(true) | ||
beginCoords.current = { x: e.clientX, y: e.clientY } | ||
contRect.current = container.current?.getBoundingClientRect() ?? null | ||
} | ||
|
||
const style = useMemo<React.CSSProperties>(() => { | ||
const fract = Math.max(0, Math.min(1, defaultedPosition)) | ||
return { | ||
'--position-a': `${fract}fr`, | ||
'--position-b': `${1 - fract}fr`, | ||
} as React.CSSProperties | ||
}, [defaultedPosition]) | ||
|
||
useEffect(() => { | ||
if (!isResizing) return | ||
|
||
function onMouseMove(e: MouseEvent) { | ||
if (!beginCoords.current || !contRect.current) return | ||
|
||
const diffX = (e.clientX - beginCoords.current.x) / contRect.current.width | ||
const diffY = (e.clientY - beginCoords.current.y) / contRect.current.height | ||
|
||
const newValue = Math.max(0, Math.min(1, initialPos.current + diffX)) | ||
|
||
onChange?.({ | ||
value: newValue, | ||
}) | ||
|
||
e.preventDefault() | ||
} | ||
|
||
function onMouseUp(e: MouseEvent) { | ||
setIsResizing(false) | ||
} | ||
|
||
window.addEventListener('mousemove', onMouseMove, { | ||
capture: true, | ||
}) | ||
window.addEventListener('mouseup', onMouseUp, { | ||
once: true, | ||
capture: true, | ||
}) | ||
|
||
return () => { | ||
window.removeEventListener('mousemove', onMouseMove, { | ||
capture: true, | ||
}) | ||
window.removeEventListener('mouseup', onMouseUp, { | ||
capture: true, | ||
}) | ||
} | ||
}, [isResizing, onChange]) | ||
|
||
useEffect(() => { | ||
if (isResizing) return | ||
|
||
initialPos.current = defaultedPosition | ||
}, [isResizing, defaultedPosition]) | ||
|
||
return ( | ||
<div className={`${className ?? ''} ${classes.SplitPane}`} style={style} ref={container}> | ||
<div className={classes.PaneA}>{childrenBegin}</div> | ||
<div className={isResizing ? classes.DividerActive : classes.Divider} onMouseDown={onMouseDown}></div> | ||
<div className={classes.PaneB}>{childrenEnd}</div> | ||
</div> | ||
) | ||
} | ||
|
||
type ChangeEvent = { value: number } | ||
type ChangeEventHandler = (e: ChangeEvent) => void |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { makeAutoObservable } from 'mobx' | ||
|
||
export class UIStore { | ||
viewDividerPosition: number = 0.5 | ||
|
||
constructor() { | ||
makeAutoObservable(this, {}) | ||
} | ||
|
||
setViewDividerPosition(value: number) { | ||
this.viewDividerPosition = value | ||
} | ||
} |