mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-07 00:13:53 +00:00
Compare commits
106 Commits
cleanup
...
countdown-v4
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a95bc43a3 | |||
| 1604762f2b | |||
| 2f8f4ad129 | |||
| 0c7c90cae4 | |||
| 1148ac1924 | |||
| 100fbabfc6 | |||
| 42810a97ca | |||
| 05a9b2af1a | |||
| 1bac3a7fd0 | |||
| 8281314ede | |||
| 3e0b3f100e | |||
| fb93063b47 | |||
| 24d3bf05ca | |||
| a4b15970de | |||
| 2a5b053d97 | |||
| 02c30c9681 | |||
| 2de7221653 | |||
| 2498e59156 | |||
| f3b4ea0155 | |||
| aebf949883 | |||
| 33ac05ebee | |||
| 421183fe55 | |||
| b66c19769d | |||
| 7b8445597f | |||
| 0b719c485f | |||
| 17deeddb87 | |||
| 2546159a94 | |||
| 2f26f20db5 | |||
| 11e0215530 | |||
| ea54953298 | |||
| d21f132674 | |||
| c7b2f0e89c | |||
| a1505606cf | |||
| 9edff55bd5 | |||
| e287215179 | |||
| 776649c997 | |||
| 9de5e0ac48 | |||
| c7d99073f6 | |||
| 5c1694d802 | |||
| 7cd319a6b3 | |||
| 2c9b6918e6 | |||
| a50cfad7ef | |||
| 66cd1decde | |||
| c9bf6d9812 | |||
| 8557f64382 | |||
| 8e994fb0df | |||
| 5c47a834b5 | |||
| f356afef43 | |||
| eba5252e40 | |||
| 72c4ad789a | |||
| 3118c20719 | |||
| 3754c374c3 | |||
| dd6d74121c | |||
| 6fb42b989e | |||
| 82dc1bc56b | |||
| d2c7b34142 | |||
| 918f8d1b08 | |||
| fcbcf70e01 | |||
| 5c6b06a0d4 | |||
| fc4c1bf22e | |||
| 84fac739f0 | |||
| ef73c87e2f | |||
| 26ee5768a5 | |||
| 27dcf06c73 | |||
| d48b2ae506 | |||
| 14a7c04d3b | |||
| abd9b127db | |||
| 0a80d6db31 | |||
| 977c99e587 | |||
| fe8bbd5003 | |||
| c6e38a2b4a | |||
| 56f18fe71c | |||
| 0b9306de82 | |||
| 3b1e6cf33d | |||
| dda219ebbe | |||
| 8bb771e5c6 | |||
| 8723bcbd33 | |||
| 0dcea4f2d7 | |||
| 696c016c90 | |||
| eed6373dbf | |||
| ac61f257c0 | |||
| 8d8625aa77 | |||
| 1e1aa4bca5 | |||
| 1f0cde6d0d | |||
| c4b66a9ed3 | |||
| 133b3aa819 | |||
| 9566fadbbb | |||
| 62570899e8 | |||
| c1f25f8dba | |||
| 37a91026d8 | |||
| c62ce213f5 | |||
| 529751578d | |||
| dce87c3a81 | |||
| a94b10cb0f | |||
| 6817263123 | |||
| ddd629d7db | |||
| 9d2a3d5a12 | |||
| 4bc271208e | |||
| dbd535dd6c | |||
| 57b7fe214a | |||
| b136e2856a | |||
| 03e68c03a9 | |||
| 44048a889d | |||
| f72db62e08 | |||
| 333f2623a5 | |||
| 3ebb3451e4 |
@@ -14,12 +14,12 @@ jobs:
|
|||||||
- name: Use Node.js
|
- name: Use Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 22
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v3
|
uses: pnpm/action-setup@v3
|
||||||
with:
|
with:
|
||||||
version: 9
|
version: 10
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pnpm install --frozen-lockfile
|
run: pnpm install --frozen-lockfile
|
||||||
@@ -56,12 +56,12 @@ jobs:
|
|||||||
- name: Use Node.js
|
- name: Use Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 22
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v3
|
uses: pnpm/action-setup@v3
|
||||||
with:
|
with:
|
||||||
version: 9
|
version: 10
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pnpm install --frozen-lockfile
|
run: pnpm install --frozen-lockfile
|
||||||
@@ -89,12 +89,12 @@ jobs:
|
|||||||
- name: Use Node.js
|
- name: Use Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 22
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v3
|
uses: pnpm/action-setup@v3
|
||||||
with:
|
with:
|
||||||
version: 9
|
version: 10
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pnpm install --frozen-lockfile
|
run: pnpm install --frozen-lockfile
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ jobs:
|
|||||||
- name: Use Node.js
|
- name: Use Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 22
|
||||||
registry-url: 'https://registry.npmjs.org'
|
registry-url: 'https://registry.npmjs.org'
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v3
|
uses: pnpm/action-setup@v3
|
||||||
with:
|
with:
|
||||||
version: 9
|
version: 10
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pnpm install --frozen-lockfile
|
run: pnpm install --frozen-lockfile
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ jobs:
|
|||||||
- name: Use Node.js
|
- name: Use Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 22
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v3
|
uses: pnpm/action-setup@v3
|
||||||
with:
|
with:
|
||||||
version: 9
|
version: 10
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pnpm install --frozen-lockfile
|
run: pnpm install --frozen-lockfile
|
||||||
@@ -73,12 +73,12 @@ jobs:
|
|||||||
- name: Use Node.js
|
- name: Use Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 22
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v3
|
uses: pnpm/action-setup@v3
|
||||||
with:
|
with:
|
||||||
version: 9
|
version: 10
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pnpm install --frozen-lockfile
|
run: pnpm install --frozen-lockfile
|
||||||
|
|||||||
Generated
-5
@@ -1,5 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
-51
@@ -1,51 +0,0 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<profile version="1.0">
|
|
||||||
<option name="myName" value="Project Default" />
|
|
||||||
<inspection_tool class="CssUnknownProperty" enabled="true" level="WARNING" enabled_by_default="true">
|
|
||||||
<option name="myCustomPropertiesEnabled" value="true" />
|
|
||||||
<option name="myIgnoreVendorSpecificProperties" value="false" />
|
|
||||||
<option name="myCustomPropertiesList">
|
|
||||||
<value>
|
|
||||||
<list size="3">
|
|
||||||
<item index="0" class="java.lang.String" itemvalue="scrollbar-color" />
|
|
||||||
<item index="1" class="java.lang.String" itemvalue="scrollbar-width" />
|
|
||||||
<item index="2" class="java.lang.String" itemvalue="app-region" />
|
|
||||||
</list>
|
|
||||||
</value>
|
|
||||||
</option>
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
|
||||||
<inspection_tool class="HttpUrlsUsage" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
|
||||||
<option name="ignoredUrls">
|
|
||||||
<list>
|
|
||||||
<option value="http://localhost" />
|
|
||||||
<option value="http://127.0.0.1" />
|
|
||||||
<option value="http://0.0.0.0" />
|
|
||||||
<option value="http://www.w3.org/" />
|
|
||||||
<option value="http://json-schema.org/draft" />
|
|
||||||
<option value="http://java.sun.com/" />
|
|
||||||
<option value="http://xmlns.jcp.org/" />
|
|
||||||
<option value="http://javafx.com/javafx/" />
|
|
||||||
<option value="http://javafx.com/fxml" />
|
|
||||||
<option value="http://maven.apache.org/xsd/" />
|
|
||||||
<option value="http://maven.apache.org/POM/" />
|
|
||||||
<option value="http://www.springframework.org/schema/" />
|
|
||||||
<option value="http://www.springframework.org/tags" />
|
|
||||||
<option value="http://www.springframework.org/security/tags" />
|
|
||||||
<option value="http://www.thymeleaf.org" />
|
|
||||||
<option value="http://www.jboss.org/j2ee/schema/" />
|
|
||||||
<option value="http://www.jboss.com/xml/ns/" />
|
|
||||||
<option value="http://www.ibm.com/webservices/xsd" />
|
|
||||||
<option value="http://activemq.apache.org/schema/" />
|
|
||||||
<option value="http://schema.cloudfoundry.org/spring/" />
|
|
||||||
<option value="http://schemas.xmlsoap.org/" />
|
|
||||||
<option value="http://cxf.apache.org/schemas/" />
|
|
||||||
<option value="http://primefaces.org/ui" />
|
|
||||||
<option value="http://tiles.apache.org/" />
|
|
||||||
<option value="http://__IP__" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="Stylelint" enabled="true" level="ERROR" enabled_by_default="true" />
|
|
||||||
</profile>
|
|
||||||
</component>
|
|
||||||
+2
-2
@@ -9,8 +9,8 @@ Ontime consists of 3 distinct parts
|
|||||||
The steps below will assume you have locally installed the necessary dependencies.
|
The steps below will assume you have locally installed the necessary dependencies.
|
||||||
Other dependencies will be installed as part of the setup
|
Other dependencies will be installed as part of the setup
|
||||||
|
|
||||||
- __node__ (~20)
|
- __node__ (~22)
|
||||||
- __pnpm__ (~9)
|
- __pnpm__ (~10)
|
||||||
- __docker__ (only necessary to run and build docker images)
|
- __docker__ (only necessary to run and build docker images)
|
||||||
|
|
||||||
## LOCAL DEVELOPMENT
|
## LOCAL DEVELOPMENT
|
||||||
|
|||||||
+3
-3
@@ -1,13 +1,13 @@
|
|||||||
FROM node:20-bullseye AS builder
|
FROM node:22-bullseye AS builder
|
||||||
ENV PNPM_HOME="/pnpm"
|
ENV PNPM_HOME="/pnpm"
|
||||||
ENV PATH="$PNPM_HOME:$PATH"
|
ENV PATH="$PNPM_HOME:$PATH"
|
||||||
RUN npm install -g pnpm@9.5.0
|
RUN npm install -g pnpm@10.11.0
|
||||||
COPY . /app
|
COPY . /app
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN pnpm --filter=ontime-ui --filter=ontime-server --filter=ontime-utils install --config.dedupe-peer-dependents=false --frozen-lockfile
|
RUN pnpm --filter=ontime-ui --filter=ontime-server --filter=ontime-utils install --config.dedupe-peer-dependents=false --frozen-lockfile
|
||||||
RUN pnpm --filter=ontime-ui --filter=ontime-server run build:docker
|
RUN pnpm --filter=ontime-ui --filter=ontime-server run build:docker
|
||||||
|
|
||||||
FROM node:20-alpine
|
FROM node:22-alpine
|
||||||
|
|
||||||
# Set environment variables
|
# Set environment variables
|
||||||
# Environment Variable to signal that we are running production
|
# Environment Variable to signal that we are running production
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@getontime/cli",
|
"name": "@getontime/cli",
|
||||||
"version": "3.14.3",
|
"version": "3.15.2",
|
||||||
"author": "Carlos Valente",
|
"author": "Carlos Valente",
|
||||||
"description": "Time keeping for live events",
|
"description": "Time keeping for live events",
|
||||||
"repository": "https://github.com/cpvalente/ontime",
|
"repository": "https://github.com/cpvalente/ontime",
|
||||||
|
|||||||
+14
-11
@@ -1,28 +1,29 @@
|
|||||||
{
|
{
|
||||||
"name": "ontime-ui",
|
"name": "ontime-ui",
|
||||||
"version": "3.14.3",
|
"version": "3.15.2",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@chakra-ui/react": "^2.7.0",
|
"@chakra-ui/react": "^2.7.0",
|
||||||
"@dnd-kit/core": "^6.1.0",
|
"@dnd-kit/core": "^6.3.1",
|
||||||
"@dnd-kit/sortable": "^8.0.0",
|
"@dnd-kit/sortable": "^10.0.0",
|
||||||
"@dnd-kit/utilities": "^3.2.2",
|
"@dnd-kit/utilities": "^3.2.2",
|
||||||
"@emotion/is-prop-valid": "^1.3.1",
|
"@emotion/is-prop-valid": "^1.3.1",
|
||||||
"@emotion/react": "^11.10.6",
|
"@emotion/react": "^11.10.6",
|
||||||
"@emotion/styled": "^11.10.6",
|
"@emotion/styled": "^11.10.6",
|
||||||
"@fontsource/open-sans": "^5.0.28",
|
"@fontsource/open-sans": "^5.0.28",
|
||||||
"@mantine/hooks": "^7.13.3",
|
"@mantine/hooks": "^7.17.2",
|
||||||
"@sentry/react": "^8.43.0",
|
"@sentry/react": "^8.43.0",
|
||||||
"@table-nav/react": "^0.0.7",
|
"@table-nav/react": "^0.0.7",
|
||||||
"@tanstack/react-query": "^5.62.7",
|
"@tanstack/react-query": "^5.62.7",
|
||||||
"@tanstack/react-query-devtools": "^5.62.7",
|
"@tanstack/react-query-devtools": "^5.62.7",
|
||||||
"@tanstack/react-table": "^8.20.5",
|
"@tanstack/react-table": "^8.21.3",
|
||||||
"autosize": "^6.0.1",
|
"autosize": "^6.0.1",
|
||||||
"axios": "^1.2.0",
|
"axios": "^1.9.0",
|
||||||
"color": "^4.2.3",
|
"color": "^4.2.3",
|
||||||
"csv-stringify": "^6.4.5",
|
"csv-stringify": "^6.4.5",
|
||||||
"framer-motion": "^10.10.0",
|
"framer-motion": "^10.10.0",
|
||||||
|
"prismjs": "^1.29.0",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-colorful": "^5.6.1",
|
"react-colorful": "^5.6.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
@@ -31,6 +32,7 @@
|
|||||||
"react-icons": "5.4.0",
|
"react-icons": "5.4.0",
|
||||||
"react-qr-code": "^2.0.12",
|
"react-qr-code": "^2.0.12",
|
||||||
"react-router-dom": "^6.3.0",
|
"react-router-dom": "^6.3.0",
|
||||||
|
"react-simple-code-editor": "^0.14.1",
|
||||||
"web-vitals": "^3.1.1",
|
"web-vitals": "^3.1.1",
|
||||||
"zustand": "^5.0.3"
|
"zustand": "^5.0.3"
|
||||||
},
|
},
|
||||||
@@ -65,11 +67,12 @@
|
|||||||
"@sentry/vite-plugin": "^2.16.1",
|
"@sentry/vite-plugin": "^2.16.1",
|
||||||
"@tanstack/eslint-plugin-query": "^5.8.4",
|
"@tanstack/eslint-plugin-query": "^5.8.4",
|
||||||
"@types/color": "^3.0.3",
|
"@types/color": "^3.0.3",
|
||||||
|
"@types/prismjs": "^1.26.5",
|
||||||
"@types/react": "^18.0.26",
|
"@types/react": "^18.0.26",
|
||||||
"@types/react-dom": "^18.0.10",
|
"@types/react-dom": "^18.0.10",
|
||||||
"@typescript-eslint/eslint-plugin": "catalog:",
|
"@typescript-eslint/eslint-plugin": "catalog:",
|
||||||
"@typescript-eslint/parser": "catalog:",
|
"@typescript-eslint/parser": "catalog:",
|
||||||
"@vitejs/plugin-react": "^4.2.1",
|
"@vitejs/plugin-react": "4.5.1",
|
||||||
"eslint": "catalog:",
|
"eslint": "catalog:",
|
||||||
"eslint-config-prettier": "catalog:",
|
"eslint-config-prettier": "catalog:",
|
||||||
"eslint-plugin-jest": "^28.6.0",
|
"eslint-plugin-jest": "^28.6.0",
|
||||||
@@ -83,10 +86,10 @@
|
|||||||
"prettier": "catalog:",
|
"prettier": "catalog:",
|
||||||
"sass": "^1.57.1",
|
"sass": "^1.57.1",
|
||||||
"typescript": "catalog:",
|
"typescript": "catalog:",
|
||||||
"vite": "^5.2.11",
|
"vite": "6.3.1",
|
||||||
"vite-plugin-compression2": "^1.3.3",
|
"vite-plugin-compression2": "1.4.0",
|
||||||
"vite-plugin-svgr": "^4.2.0",
|
"vite-plugin-svgr": "4.3.0",
|
||||||
"vite-tsconfig-paths": "^4.3.1",
|
"vite-tsconfig-paths": "5.1.4",
|
||||||
"vitest": "catalog:"
|
"vitest": "catalog:"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,11 +25,10 @@ const Operator = React.lazy(() => import('./features/operator/OperatorExport'));
|
|||||||
const TimerView = React.lazy(() => import('./views/timer/Timer'));
|
const TimerView = React.lazy(() => import('./views/timer/Timer'));
|
||||||
const MinimalTimerView = React.lazy(() => import('./features/viewers/minimal-timer/MinimalTimer'));
|
const MinimalTimerView = React.lazy(() => import('./features/viewers/minimal-timer/MinimalTimer'));
|
||||||
const ClockView = React.lazy(() => import('./features/viewers/clock/Clock'));
|
const ClockView = React.lazy(() => import('./features/viewers/clock/Clock'));
|
||||||
const Countdown = React.lazy(() => import('./features/viewers/countdown/Countdown'));
|
const Countdown = React.lazy(() => import('./views/countdown/Countdown'));
|
||||||
|
|
||||||
const Backstage = React.lazy(() => import('./views/backstage/Backstage'));
|
const Backstage = React.lazy(() => import('./views/backstage/Backstage'));
|
||||||
const Timeline = React.lazy(() => import('./views/timeline/TimelinePage'));
|
const Timeline = React.lazy(() => import('./views/timeline/TimelinePage'));
|
||||||
const Public = React.lazy(() => import('./views/public/Public'));
|
|
||||||
const Lower = React.lazy(() => import('./features/viewers/lower-thirds/LowerThird'));
|
const Lower = React.lazy(() => import('./features/viewers/lower-thirds/LowerThird'));
|
||||||
const StudioClock = React.lazy(() => import('./features/viewers/studio/StudioClock'));
|
const StudioClock = React.lazy(() => import('./features/viewers/studio/StudioClock'));
|
||||||
const ProjectInfo = React.lazy(() => import('./views/project-info/ProjectInfo'));
|
const ProjectInfo = React.lazy(() => import('./views/project-info/ProjectInfo'));
|
||||||
@@ -40,7 +39,6 @@ const SClock = withPreset(withData(ClockView));
|
|||||||
const SCountdown = withPreset(withData(Countdown));
|
const SCountdown = withPreset(withData(Countdown));
|
||||||
const SBackstage = withPreset(withData(Backstage));
|
const SBackstage = withPreset(withData(Backstage));
|
||||||
const SProjectInfo = withPreset(withData(ProjectInfo));
|
const SProjectInfo = withPreset(withData(ProjectInfo));
|
||||||
const SPublic = withPreset(withData(Public));
|
|
||||||
const SLowerThird = withPreset(withData(Lower));
|
const SLowerThird = withPreset(withData(Lower));
|
||||||
const SStudio = withPreset(withData(StudioClock));
|
const SStudio = withPreset(withData(StudioClock));
|
||||||
const STimeline = withPreset(withData(Timeline));
|
const STimeline = withPreset(withData(Timeline));
|
||||||
@@ -88,14 +86,6 @@ export default function AppRouter() {
|
|||||||
</ViewLoader>
|
</ViewLoader>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<Route
|
|
||||||
path='/public'
|
|
||||||
element={
|
|
||||||
<ViewLoader>
|
|
||||||
<SPublic />
|
|
||||||
</ViewLoader>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route
|
<Route
|
||||||
path='/minimal'
|
path='/minimal'
|
||||||
element={
|
element={
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
import { apiEntryUrl } from './constants';
|
||||||
|
|
||||||
|
const assetsPath = `${apiEntryUrl}/assets`;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP request to get css contents
|
||||||
|
*/
|
||||||
|
export async function getCSSContents(): Promise<string> {
|
||||||
|
const res = await axios.get(`${assetsPath}/css`);
|
||||||
|
return res.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP request to post css contents
|
||||||
|
*/
|
||||||
|
export async function postCSSContents(css: string): Promise<void> {
|
||||||
|
await axios.post(`${assetsPath}/css`, {
|
||||||
|
css,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP request to restore default css
|
||||||
|
*/
|
||||||
|
export async function restoreCSSContents(): Promise<string> {
|
||||||
|
const res = await axios.post(`${assetsPath}/css/restore`);
|
||||||
|
return res.data;
|
||||||
|
}
|
||||||
@@ -10,7 +10,6 @@ export const PROJECT_DATA = ['project'];
|
|||||||
export const PROJECT_LIST = ['projectList'];
|
export const PROJECT_LIST = ['projectList'];
|
||||||
export const RUNDOWN = ['rundown'];
|
export const RUNDOWN = ['rundown'];
|
||||||
export const RUNTIME = ['runtimeStore'];
|
export const RUNTIME = ['runtimeStore'];
|
||||||
export const SHEET_STATE = ['sheetState'];
|
|
||||||
export const URL_PRESETS = ['urlpresets'];
|
export const URL_PRESETS = ['urlpresets'];
|
||||||
export const VIEW_SETTINGS = ['viewSettings'];
|
export const VIEW_SETTINGS = ['viewSettings'];
|
||||||
export const CLIENT_LIST = ['clientList'];
|
export const CLIENT_LIST = ['clientList'];
|
||||||
@@ -19,11 +18,8 @@ export const REPORT = ['report'];
|
|||||||
// API URLs
|
// API URLs
|
||||||
export const apiEntryUrl = `${serverURL}/data`;
|
export const apiEntryUrl = `${serverURL}/data`;
|
||||||
|
|
||||||
export const projectDataURL = `${serverURL}/project`;
|
const userAssetsPath = 'user';
|
||||||
export const rundownURL = `${serverURL}/events`;
|
const cssOverridePath = 'styles/override.css';
|
||||||
export const ontimeURL = `${serverURL}/ontime`;
|
|
||||||
|
|
||||||
export const userAssetsPath = 'user';
|
|
||||||
export const cssOverridePath = 'styles/override.css';
|
|
||||||
export const overrideStylesURL = `${serverURL}/${userAssetsPath}/${cssOverridePath}`;
|
export const overrideStylesURL = `${serverURL}/${userAssetsPath}/${cssOverridePath}`;
|
||||||
export const projectLogoPath = `${serverURL}/${userAssetsPath}/logo`;
|
export const projectLogoPath = `${serverURL}/${userAssetsPath}/logo`;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { CustomField, CustomFieldLabel, CustomFields } from 'ontime-types';
|
import { CustomField, CustomFieldKey, CustomFields } from 'ontime-types';
|
||||||
|
|
||||||
import { apiEntryUrl } from './constants';
|
import { apiEntryUrl } from './constants';
|
||||||
|
|
||||||
@@ -24,15 +24,15 @@ export async function postCustomField(newField: CustomField): Promise<CustomFiel
|
|||||||
/**
|
/**
|
||||||
* Edits single custom field
|
* Edits single custom field
|
||||||
*/
|
*/
|
||||||
export async function editCustomField(label: CustomFieldLabel, newField: CustomField): Promise<CustomFields> {
|
export async function editCustomField(key: CustomFieldKey, newField: CustomField): Promise<CustomFields> {
|
||||||
const res = await axios.put(`${customFieldsPath}/${label}`, { ...newField });
|
const res = await axios.put(`${customFieldsPath}/${key}`, { ...newField });
|
||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes single custom field
|
* Deletes single custom field
|
||||||
*/
|
*/
|
||||||
export async function deleteCustomField(label: CustomFieldLabel): Promise<CustomFields> {
|
export async function deleteCustomField(key: CustomFieldKey): Promise<CustomFields> {
|
||||||
const res = await axios.delete(`${customFieldsPath}/${label}`);
|
const res = await axios.delete(`${customFieldsPath}/${key}`);
|
||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import axios, { AxiosResponse } from 'axios';
|
|||||||
import { DatabaseModel, MessageResponse, ProjectData, ProjectFileListResponse, QuickStartData } from 'ontime-types';
|
import { DatabaseModel, MessageResponse, ProjectData, ProjectFileListResponse, QuickStartData } from 'ontime-types';
|
||||||
|
|
||||||
import { makeTable } from '../../views/cuesheet/cuesheet.utils';
|
import { makeTable } from '../../views/cuesheet/cuesheet.utils';
|
||||||
import { makeCSVFromArrayOfArrays } from '../utils/csv';
|
import { aggregateRundowns, makeCSVFromArrayOfArrays } from '../utils/csv';
|
||||||
|
|
||||||
import { apiEntryUrl } from './constants';
|
import { apiEntryUrl } from './constants';
|
||||||
import { createBlob, downloadBlob } from './utils';
|
import { createBlob, downloadBlob } from './utils';
|
||||||
@@ -40,9 +40,11 @@ export async function downloadProject(fileName: string) {
|
|||||||
export async function downloadCSV(fileName: string = 'rundown') {
|
export async function downloadCSV(fileName: string = 'rundown') {
|
||||||
try {
|
try {
|
||||||
const { data, name } = await fileDownload(fileName);
|
const { data, name } = await fileDownload(fileName);
|
||||||
const { project, rundown, customFields } = data;
|
const { project, rundowns, customFields } = data;
|
||||||
|
|
||||||
|
const flatRundowns = aggregateRundowns(rundowns);
|
||||||
|
const sheetData = makeTable(project, flatRundowns, customFields);
|
||||||
|
|
||||||
const sheetData = makeTable(project, rundown, customFields);
|
|
||||||
const fileContent = makeCSVFromArrayOfArrays(sheetData);
|
const fileContent = makeCSVFromArrayOfArrays(sheetData);
|
||||||
|
|
||||||
const blob = createBlob(fileContent, 'text/csv;charset=utf-8;');
|
const blob = createBlob(fileContent, 'text/csv;charset=utf-8;');
|
||||||
|
|||||||
@@ -1,16 +1,11 @@
|
|||||||
import axios, { AxiosResponse } from 'axios';
|
import axios, { AxiosResponse } from 'axios';
|
||||||
import { CustomFields, OntimeRundown } from 'ontime-types';
|
import { CustomFields, Rundown } from 'ontime-types';
|
||||||
import { ImportMap } from 'ontime-utils';
|
import { ImportMap } from 'ontime-utils';
|
||||||
|
|
||||||
import { apiEntryUrl } from './constants';
|
import { apiEntryUrl } from './constants';
|
||||||
|
|
||||||
const excelPath = `${apiEntryUrl}/excel`;
|
const excelPath = `${apiEntryUrl}/excel`;
|
||||||
|
|
||||||
type PreviewSpreadsheetResponse = {
|
|
||||||
rundown: OntimeRundown;
|
|
||||||
customFields: CustomFields;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* upload Excel file to server
|
* upload Excel file to server
|
||||||
* @return string - file ID op the uploaded file
|
* @return string - file ID op the uploaded file
|
||||||
@@ -34,6 +29,10 @@ export async function getWorksheetNames(): Promise<string[]> {
|
|||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PreviewSpreadsheetResponse = {
|
||||||
|
rundown: Rundown;
|
||||||
|
customFields: CustomFields;
|
||||||
|
};
|
||||||
export async function importRundownPreview(options: ImportMap): Promise<PreviewSpreadsheetResponse> {
|
export async function importRundownPreview(options: ImportMap): Promise<PreviewSpreadsheetResponse> {
|
||||||
const response: AxiosResponse<PreviewSpreadsheetResponse> = await axios.post(`${excelPath}/preview`, {
|
const response: AxiosResponse<PreviewSpreadsheetResponse> = await axios.post(`${excelPath}/preview`, {
|
||||||
options,
|
options,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export type HasUpdate = {
|
|||||||
* HTTP request to get the latest version and url from github
|
* HTTP request to get the latest version and url from github
|
||||||
*/
|
*/
|
||||||
export async function getLatestVersion(): Promise<HasUpdate> {
|
export async function getLatestVersion(): Promise<HasUpdate> {
|
||||||
const res = await axios.get(`${apiRepoLatest}`);
|
const res = await axios.get(apiRepoLatest);
|
||||||
return {
|
return {
|
||||||
url: res.data.html_url as string,
|
url: res.data.html_url as string,
|
||||||
version: res.data.tag_name as string,
|
version: res.data.tag_name as string,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export const reportUrl = `${apiEntryUrl}/report`;
|
|||||||
* HTTP request to fetch all reports
|
* HTTP request to fetch all reports
|
||||||
*/
|
*/
|
||||||
export async function fetchReport(): Promise<OntimeReport> {
|
export async function fetchReport(): Promise<OntimeReport> {
|
||||||
const res = await axios.get(`${reportUrl}/`);
|
const res = await axios.get(reportUrl);
|
||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +1,45 @@
|
|||||||
import axios, { AxiosResponse } from 'axios';
|
import axios, { AxiosResponse } from 'axios';
|
||||||
import { MessageResponse, OntimeEvent, OntimeRundownEntry, RundownCached, TransientEventPayload } from 'ontime-types';
|
import {
|
||||||
|
EntryId,
|
||||||
|
MessageResponse,
|
||||||
|
OntimeEntry,
|
||||||
|
OntimeEvent,
|
||||||
|
ProjectRundownsList,
|
||||||
|
Rundown,
|
||||||
|
TransientEventPayload,
|
||||||
|
} from 'ontime-types';
|
||||||
|
|
||||||
import { apiEntryUrl } from './constants';
|
import { apiEntryUrl } from './constants';
|
||||||
|
|
||||||
const rundownPath = `${apiEntryUrl}/rundown`;
|
const rundownPath = `${apiEntryUrl}/rundown`;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTTP request to fetch all events
|
* HTTP request to fetch a list of existing rundowns
|
||||||
*/
|
*/
|
||||||
export async function fetchNormalisedRundown(): Promise<RundownCached> {
|
export async function fetchProjectRundownList(): Promise<ProjectRundownsList> {
|
||||||
const res = await axios.get(`${rundownPath}/normalised`);
|
const res = await axios.get(rundownPath);
|
||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTTP request to post new event
|
* HTTP request to fetch all events
|
||||||
*/
|
*/
|
||||||
export async function requestPostEvent(data: TransientEventPayload): Promise<AxiosResponse<OntimeRundownEntry>> {
|
export async function fetchCurrentRundown(): Promise<Rundown> {
|
||||||
|
const res = await axios.get(`${rundownPath}/current`);
|
||||||
|
return res.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP request to post new entry
|
||||||
|
*/
|
||||||
|
export async function postAddEntry(data: TransientEventPayload): Promise<AxiosResponse<OntimeEntry>> {
|
||||||
return axios.post(rundownPath, data);
|
return axios.post(rundownPath, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTTP request to put new event
|
* HTTP request to edit an entry
|
||||||
*/
|
*/
|
||||||
export async function requestPutEvent(data: Partial<OntimeRundownEntry>): Promise<AxiosResponse<OntimeRundownEntry>> {
|
export async function putEditEntry(data: Partial<OntimeEntry>): Promise<AxiosResponse<OntimeEntry>> {
|
||||||
return axios.put(rundownPath, data);
|
return axios.put(rundownPath, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,22 +49,22 @@ type BatchEditEntry = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTTP request to put multiple events
|
* HTTP request to edit multiple events
|
||||||
*/
|
*/
|
||||||
export async function requestBatchPutEvents(data: BatchEditEntry): Promise<AxiosResponse<MessageResponse>> {
|
export async function putBatchEditEvents(data: BatchEditEntry): Promise<AxiosResponse<Rundown>> {
|
||||||
return axios.put(`${rundownPath}/batch`, data);
|
return axios.put(`${rundownPath}/batch`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ReorderEntry = {
|
export type ReorderEntry = {
|
||||||
eventId: string;
|
entryId: EntryId;
|
||||||
from: number;
|
destinationId: EntryId;
|
||||||
to: number;
|
order: 'before' | 'after' | 'insert';
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTTP request to reorder events
|
* HTTP request to reorder an entry
|
||||||
*/
|
*/
|
||||||
export async function requestReorderEvent(data: ReorderEntry): Promise<AxiosResponse<OntimeRundownEntry>> {
|
export async function patchReorderEntry(data: ReorderEntry): Promise<AxiosResponse<Rundown>> {
|
||||||
return axios.patch(`${rundownPath}/reorder`, data);
|
return axios.patch(`${rundownPath}/reorder`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,15 +83,36 @@ export async function requestEventSwap(data: SwapEntry): Promise<AxiosResponse<M
|
|||||||
/**
|
/**
|
||||||
* HTTP request to request application of delay
|
* HTTP request to request application of delay
|
||||||
*/
|
*/
|
||||||
export async function requestApplyDelay(eventId: string): Promise<AxiosResponse<MessageResponse>> {
|
export async function requestApplyDelay(delayId: EntryId): Promise<AxiosResponse<Rundown>> {
|
||||||
return axios.patch(`${rundownPath}/applydelay/${eventId}`);
|
return axios.patch(`${rundownPath}/applydelay/${delayId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTTP request to delete given event
|
* HTTP request for cloning an entry
|
||||||
*/
|
*/
|
||||||
export async function requestDelete(eventIds: string[]): Promise<AxiosResponse<MessageResponse>> {
|
export async function postCloneEntry(entryId: EntryId): Promise<AxiosResponse<Rundown>> {
|
||||||
return axios.delete(rundownPath, { data: { ids: eventIds } });
|
return axios.post(`${rundownPath}/clone/${entryId}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP request for dissolving of a block
|
||||||
|
*/
|
||||||
|
export async function requestUngroup(blockId: EntryId): Promise<AxiosResponse<Rundown>> {
|
||||||
|
return axios.post(`${rundownPath}/ungroup/${blockId}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP request for grouping a list of entries into a block
|
||||||
|
*/
|
||||||
|
export async function requestGroupEntries(entryIds: EntryId[]): Promise<AxiosResponse<Rundown>> {
|
||||||
|
return axios.post(`${rundownPath}/group`, { ids: entryIds });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP request to delete entries
|
||||||
|
*/
|
||||||
|
export async function deleteEntries(entryIds: EntryId[]): Promise<AxiosResponse<MessageResponse>> {
|
||||||
|
return axios.delete(rundownPath, { data: { ids: entryIds } });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import axios, { AxiosResponse } from 'axios';
|
import axios, { AxiosResponse } from 'axios';
|
||||||
import { AuthenticationStatus, CustomFields, OntimeRundown } from 'ontime-types';
|
import { AuthenticationStatus, CustomFields, Rundown } from 'ontime-types';
|
||||||
import { ImportMap } from 'ontime-utils';
|
import { ImportMap } from 'ontime-utils';
|
||||||
|
|
||||||
import { apiEntryUrl } from './constants';
|
import { apiEntryUrl } from './constants';
|
||||||
@@ -54,7 +54,7 @@ export const previewRundown = async (
|
|||||||
sheetId: string,
|
sheetId: string,
|
||||||
options: ImportMap,
|
options: ImportMap,
|
||||||
): Promise<{
|
): Promise<{
|
||||||
rundown: OntimeRundown;
|
rundown: Rundown;
|
||||||
customFields: CustomFields;
|
customFields: CustomFields;
|
||||||
}> => {
|
}> => {
|
||||||
const response = await axios.post(`${sheetsPath}/${sheetId}/read`, { options });
|
const response = await axios.post(`${sheetsPath}/${sheetId}/read`, { options });
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { addLog } from '../stores/logger';
|
|||||||
import { nowInMillis } from '../utils/time';
|
import { nowInMillis } from '../utils/time';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility unrwap a potential axios error
|
* Utility unwrap a potential axios error
|
||||||
* @param error
|
* @param error
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
@@ -34,7 +34,7 @@ export function maybeAxiosError(error: unknown) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility unrwaps a potential axios error and sends to logger
|
* Utility unwraps a potential axios error and sends to logger
|
||||||
* @param prepend
|
* @param prepend
|
||||||
* @param error
|
* @param error
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
@use '../../../theme/viewerDefs' as *;
|
||||||
|
|
||||||
|
.baseButton {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5em;
|
||||||
|
|
||||||
|
width: fit-content;
|
||||||
|
padding-inline: 1em;
|
||||||
|
|
||||||
|
border: 1px solid transparent;
|
||||||
|
border-radius: 3px;
|
||||||
|
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
opacity: 0.4;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.subtle {
|
||||||
|
background: $gray-1050;
|
||||||
|
color: $blue-400;
|
||||||
|
|
||||||
|
&:hover:not(:disabled):not(:active) {
|
||||||
|
background: $gray-1000;
|
||||||
|
color: $blue-500;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active:not(:disabled) {
|
||||||
|
background: $gray-1100;
|
||||||
|
border-color: $gray-1250;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.primary {
|
||||||
|
background: $blue-700;
|
||||||
|
color: $ui-white;
|
||||||
|
|
||||||
|
&:hover:not(:disabled):not(:active) {
|
||||||
|
background: $blue-600;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active:not(:disabled) {
|
||||||
|
background: $blue-800;
|
||||||
|
border-color: $blue-900;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
opacity: $viewer-opacity-disabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.medium {
|
||||||
|
height: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.large {
|
||||||
|
height: 3.5rem;
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { ButtonHTMLAttributes } from 'react';
|
||||||
|
|
||||||
|
import { cx } from '../../utils/styleUtils';
|
||||||
|
|
||||||
|
import style from './Button.module.scss';
|
||||||
|
|
||||||
|
interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
||||||
|
variant?: 'subtle' | 'primary';
|
||||||
|
size?: 'medium' | 'large';
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Button(props: ButtonProps) {
|
||||||
|
const { className, children, variant = 'subtle', size = 'medium', ...buttonProps } = props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button className={cx([style.baseButton, style[variant], style[size], className])} type='button' {...buttonProps}>
|
||||||
|
{children}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,21 +1,28 @@
|
|||||||
.subtle {
|
@use '../../../theme/viewerDefs' as *;
|
||||||
|
|
||||||
|
.baseIconButton {
|
||||||
aspect-ratio: 1;
|
aspect-ratio: 1;
|
||||||
height: 2rem;
|
height: 2rem;
|
||||||
height: 2rem;
|
width: 2rem;
|
||||||
display: grid;
|
display: grid;
|
||||||
place-content: center;
|
place-content: center;
|
||||||
|
|
||||||
background: $gray-1050;
|
|
||||||
color: $blue-400;
|
|
||||||
border: 1px solid transparent;
|
border: 1px solid transparent;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
|
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.subtle {
|
||||||
|
background: $gray-1050;
|
||||||
|
color: $blue-400;
|
||||||
|
|
||||||
&:hover:not(:disabled):not(:active) {
|
&:hover:not(:disabled):not(:active) {
|
||||||
background: $gray-1000;
|
background: $gray-1000;
|
||||||
color: $blue-500;
|
color: $blue-500;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:active {
|
&:active:not(:disabled){
|
||||||
background: $gray-1100;
|
background: $gray-1100;
|
||||||
border-color: $gray-1250;
|
border-color: $gray-1250;
|
||||||
}
|
}
|
||||||
@@ -24,3 +31,37 @@
|
|||||||
background: $gray-1050;
|
background: $gray-1050;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.subtle-white {
|
||||||
|
background: $gray-1050;
|
||||||
|
color: $ui-white;
|
||||||
|
|
||||||
|
&:hover:not(:disabled):not(:active) {
|
||||||
|
background: $gray-1000;
|
||||||
|
color: $ui-white;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active:not(:disabled) {
|
||||||
|
background: $gray-1100;
|
||||||
|
border-color: $gray-1250;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
background: $gray-1050;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.destructive {
|
||||||
|
background: $red-700;
|
||||||
|
color: $ui-white;
|
||||||
|
|
||||||
|
&:hover:not(:disabled):not(:active) {
|
||||||
|
background: $red-600;
|
||||||
|
color: $ui-white;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active:not(:disabled) {
|
||||||
|
background: $red-800;
|
||||||
|
border-color: $red-900;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,10 +4,15 @@ import { cx } from '../../utils/styleUtils';
|
|||||||
|
|
||||||
import style from './IconButton.module.scss';
|
import style from './IconButton.module.scss';
|
||||||
|
|
||||||
export default function IconButton(props: ButtonHTMLAttributes<HTMLButtonElement>) {
|
interface IconButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
||||||
const { className, children, ...buttonProps } = props;
|
variant?: 'subtle' | 'subtle-white' | 'destructive';
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function IconButton(props: IconButtonProps) {
|
||||||
|
const { className, children, variant = 'subtle', ...buttonProps } = props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button className={cx([style.subtle, className])} {...buttonProps}>
|
<button className={cx([style.baseIconButton, style[variant], className])} type='button' {...buttonProps}>
|
||||||
{children}
|
{children}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export type OptionWithoutGroup = {
|
|||||||
withDivider?: boolean;
|
withDivider?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type OptionWithGroup = {
|
type OptionWithGroup = {
|
||||||
label: string;
|
label: string;
|
||||||
group: Omit<OptionWithoutGroup, 'isGroup'>[];
|
group: Omit<OptionWithoutGroup, 'isGroup'>[];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import React from 'react';
|
|||||||
// skipcq: JS-C1003 - sentry does not expose itself as an ES Module.
|
// skipcq: JS-C1003 - sentry does not expose itself as an ES Module.
|
||||||
import * as Sentry from '@sentry/react';
|
import * as Sentry from '@sentry/react';
|
||||||
|
|
||||||
import { runtimeStore } from '@/common/stores/runtime';
|
import { hasConnected, reconnectAttempts } from '../../../common/utils/socket';
|
||||||
import { hasConnected, reconnectAttempts, shouldReconnect } from '@/common/utils/socket';
|
import { runtimeStore } from '../../stores/runtime';
|
||||||
|
|
||||||
import style from './ErrorBoundary.module.scss';
|
import style from './ErrorBoundary.module.scss';
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ class ErrorBoundary extends React.Component {
|
|||||||
scope.setExtras({
|
scope.setExtras({
|
||||||
error,
|
error,
|
||||||
store: appState,
|
store: appState,
|
||||||
hasSocket: { hasConnected, shouldReconnect, reconnectAttempts },
|
hasSocket: { hasConnected, reconnectAttempts },
|
||||||
});
|
});
|
||||||
const eventId = Sentry.captureException(error);
|
const eventId = Sentry.captureException(error);
|
||||||
this.setState({ eventId, info });
|
this.setState({ eventId, info });
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { KeyboardEvent, useEffect, useRef, useState } from 'react';
|
|||||||
import { Input, Radio, RadioGroup } from '@chakra-ui/react';
|
import { Input, Radio, RadioGroup } from '@chakra-ui/react';
|
||||||
import { millisToString, parseUserTime } from 'ontime-utils';
|
import { millisToString, parseUserTime } from 'ontime-utils';
|
||||||
|
|
||||||
import { useEventAction } from '../../../hooks/useEventAction';
|
import { useEntryActions } from '../../../hooks/useEntryAction';
|
||||||
|
|
||||||
import style from './DelayInput.module.scss';
|
import style from './DelayInput.module.scss';
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ interface DelayInputProps {
|
|||||||
|
|
||||||
export default function DelayInput(props: DelayInputProps) {
|
export default function DelayInput(props: DelayInputProps) {
|
||||||
const { eventId, duration } = props;
|
const { eventId, duration } = props;
|
||||||
const { updateEvent } = useEventAction();
|
const { updateEntry } = useEntryActions();
|
||||||
|
|
||||||
const [value, setValue] = useState<string>('');
|
const [value, setValue] = useState<string>('');
|
||||||
const inputRef = useRef<HTMLInputElement | null>(null);
|
const inputRef = useRef<HTMLInputElement | null>(null);
|
||||||
@@ -54,7 +54,7 @@ export default function DelayInput(props: DelayInputProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const submitChange = (value: number) => {
|
const submitChange = (value: number) => {
|
||||||
updateEvent({
|
updateEntry({
|
||||||
id: eventId,
|
id: eventId,
|
||||||
duration: value,
|
duration: value,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
font-size: $text-body-size;
|
font-size: $text-body-size;
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
text-underline-offset: 2px;
|
text-underline-offset: 2px;
|
||||||
|
color: $blue-400;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
color: $blue-400;
|
color: $blue-500;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
$loader-size: 4rem;
|
|
||||||
|
|
||||||
.overlay {
|
|
||||||
position: absolute;
|
|
||||||
z-index: 10;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
display: grid;
|
|
||||||
place-content: center;
|
|
||||||
background-color: $black-10;
|
|
||||||
backdrop-filter: blur(5px);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.loader {
|
|
||||||
width: $loader-size;
|
|
||||||
height: $loader-size;
|
|
||||||
background: $blue-500;
|
|
||||||
display: inline-block;
|
|
||||||
border-radius: 50%;
|
|
||||||
box-sizing: border-box;
|
|
||||||
animation: animloader 1s ease-in infinite;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes animloader {
|
|
||||||
0% {
|
|
||||||
transform: scale(0);
|
|
||||||
opacity: 0.6;
|
|
||||||
}
|
|
||||||
100% {
|
|
||||||
transform: scale(1);
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes animloader {
|
|
||||||
0% {
|
|
||||||
transform: scale(0);
|
|
||||||
opacity: 0.6;
|
|
||||||
}
|
|
||||||
100% {
|
|
||||||
transform: scale(1);
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import style from './LoaderOverlay.module.scss';
|
|
||||||
|
|
||||||
export default function LoaderOverlay() {
|
|
||||||
return (
|
|
||||||
<div className={style.overlay}>
|
|
||||||
<span className={style.loader} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,7 @@ import { IoSettingsOutline } from 'react-icons/io5';
|
|||||||
|
|
||||||
import { useFadeOutOnInactivity } from '../../hooks/useFadeOutOnInactivity';
|
import { useFadeOutOnInactivity } from '../../hooks/useFadeOutOnInactivity';
|
||||||
import { cx } from '../../utils/styleUtils';
|
import { cx } from '../../utils/styleUtils';
|
||||||
|
import IconButton from '../buttons/IconButton';
|
||||||
|
|
||||||
import style from './NavigationMenu.module.scss';
|
import style from './NavigationMenu.module.scss';
|
||||||
|
|
||||||
@@ -17,22 +18,24 @@ export default function FloatingNavigation(props: FloatingNavigationProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cx([style.fadeable, style.buttonContainer, !isButtonShown && style.hidden])}>
|
<div className={cx([style.fadeable, style.buttonContainer, !isButtonShown && style.hidden])}>
|
||||||
<button
|
<IconButton
|
||||||
|
variant='subtle-white'
|
||||||
|
className={style.navButton}
|
||||||
onClick={toggleMenu}
|
onClick={toggleMenu}
|
||||||
aria-label='toggle menu'
|
aria-label='toggle menu'
|
||||||
className={style.navButton}
|
|
||||||
data-testid='navigation__toggle-menu'
|
data-testid='navigation__toggle-menu'
|
||||||
>
|
>
|
||||||
<IoApps />
|
<IoApps />
|
||||||
</button>
|
</IconButton>
|
||||||
<button
|
<IconButton
|
||||||
className={style.button}
|
variant='subtle-white'
|
||||||
|
className={style.navButton}
|
||||||
onClick={toggleSettings}
|
onClick={toggleSettings}
|
||||||
aria-label='toggle settings'
|
aria-label='toggle settings'
|
||||||
data-testid='navigation__toggle-settings'
|
data-testid='navigation__toggle-settings'
|
||||||
>
|
>
|
||||||
<IoSettingsOutline />
|
<IoSettingsOutline />
|
||||||
</button>
|
</IconButton>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
$menu-hover-bg: $gray-1350;
|
$menu-hover-bg: $gray-1350;
|
||||||
$menu-focus-bg: $gray-1300;
|
$menu-focus-bg: $gray-1300;
|
||||||
|
|
||||||
$icon-color: $ui-white;
|
|
||||||
$button-bg: $gray-1050;
|
|
||||||
$button-size: 3rem;
|
$button-size: 3rem;
|
||||||
|
|
||||||
.fadeable {
|
.fadeable {
|
||||||
@@ -15,6 +13,7 @@ $button-size: 3rem;
|
|||||||
|
|
||||||
&.hidden {
|
&.hidden {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,20 +40,10 @@ $button-size: 3rem;
|
|||||||
z-index: 12;
|
z-index: 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button {
|
|
||||||
font-size: 1.5rem;
|
|
||||||
color: $icon-color;
|
|
||||||
background-color: $button-bg;
|
|
||||||
width: $button-size;
|
|
||||||
height: $button-size;
|
|
||||||
display: grid;
|
|
||||||
place-content: center;
|
|
||||||
border-radius: 3px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.navButton {
|
.navButton {
|
||||||
@extend .button;
|
font-size: 1.5rem;
|
||||||
z-index: 3;
|
height: $button-size;
|
||||||
|
width: $button-size;;
|
||||||
}
|
}
|
||||||
|
|
||||||
.link {
|
.link {
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
import { memo } from 'react';
|
|
||||||
|
|
||||||
import NavigationMenu from './NavigationMenu';
|
|
||||||
|
|
||||||
interface ProductionNavigationMenuProps {
|
|
||||||
isMenuOpen: boolean;
|
|
||||||
onMenuClose: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
function ProductionNavigationMenu(props: ProductionNavigationMenuProps) {
|
|
||||||
const { isMenuOpen, onMenuClose } = props;
|
|
||||||
|
|
||||||
return <NavigationMenu isOpen={isMenuOpen} onClose={onMenuClose} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default memo(ProductionNavigationMenu);
|
|
||||||
@@ -4,10 +4,10 @@ import type { MultiselectOptions, ParamField } from './types';
|
|||||||
|
|
||||||
export const makeOptionsFromCustomFields = (
|
export const makeOptionsFromCustomFields = (
|
||||||
customFields: CustomFields,
|
customFields: CustomFields,
|
||||||
additionalOptions: Record<string, string> = {},
|
additionalOptions: Readonly<Record<string, string>> = {},
|
||||||
filterImageType = true,
|
filterImageType = true,
|
||||||
) => {
|
) => {
|
||||||
const options = structuredClone(additionalOptions);
|
const options = { ...additionalOptions };
|
||||||
for (const [key, value] of Object.entries(customFields)) {
|
for (const [key, value] of Object.entries(customFields)) {
|
||||||
if (filterImageType && value.type === 'image') {
|
if (filterImageType && value.type === 'image') {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ type OptionsField = {
|
|||||||
defaultValue?: string;
|
defaultValue?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type MultiselectOption = { value: string; label: string; colour: string };
|
type MultiselectOption = { value: string; label: string; colour: string };
|
||||||
export type MultiselectOptions = Record<string, MultiselectOption>;
|
export type MultiselectOptions = Record<string, MultiselectOption>;
|
||||||
type MultiOptionsField = {
|
type MultiOptionsField = {
|
||||||
type: 'multi-option';
|
type: 'multi-option';
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
// roughly from https://github.com/juliencrn/usehooks-ts/blob/master/packages/usehooks-ts/src/useMediaQuery/useMediaQuery.ts
|
|
||||||
|
|
||||||
import { useCallback, useEffect, useState } from 'react';
|
|
||||||
|
|
||||||
function getMatches(query: string): boolean {
|
|
||||||
return window.matchMedia(query).matches;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: debounce handleChange
|
|
||||||
export default function useMediaQuery(query: string): boolean {
|
|
||||||
const [matches, setMatches] = useState<boolean>(getMatches(query));
|
|
||||||
|
|
||||||
const handleChange = useCallback(() => {
|
|
||||||
setMatches(getMatches(query));
|
|
||||||
}, [query]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const matchMedia = window.matchMedia(query);
|
|
||||||
|
|
||||||
// Triggered at the first client-side load and if query changes
|
|
||||||
handleChange();
|
|
||||||
|
|
||||||
// Listen matchMedia
|
|
||||||
matchMedia.addEventListener('change', handleChange);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
matchMedia.removeEventListener('change', handleChange);
|
|
||||||
};
|
|
||||||
}, [handleChange, query]);
|
|
||||||
|
|
||||||
return matches;
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
import { useMutation, useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
|
||||||
import { queryRefetchIntervalSlow } from '../../ontimeConfig';
|
import { queryRefetchIntervalSlow } from '../../ontimeConfig';
|
||||||
import { editAutomationSettings, getAutomationSettings } from '../api/automation';
|
import { getAutomationSettings } from '../api/automation';
|
||||||
import { AUTOMATION } from '../api/constants';
|
import { AUTOMATION } from '../api/constants';
|
||||||
import { logAxiosError } from '../api/utils';
|
|
||||||
import { automationPlaceholderSettings } from '../models/AutomationSettings';
|
import { automationPlaceholderSettings } from '../models/AutomationSettings';
|
||||||
import { ontimeQueryClient } from '../queryClient';
|
|
||||||
|
|
||||||
export default function useAutomationSettings() {
|
export default function useAutomationSettings() {
|
||||||
const { data, status, isFetching, isError, refetch } = useQuery({
|
const { data, status, isFetching, isError, refetch } = useQuery({
|
||||||
@@ -20,15 +18,3 @@ export default function useAutomationSettings() {
|
|||||||
|
|
||||||
return { data: data ?? automationPlaceholderSettings, status, isFetching, isError, refetch };
|
return { data: data ?? automationPlaceholderSettings, status, isFetching, isError, refetch };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useAutomationSettingsMutation() {
|
|
||||||
const { isPending, mutateAsync } = useMutation({
|
|
||||||
mutationFn: editAutomationSettings,
|
|
||||||
onError: (error) => logAxiosError('Error saving Automation settings', error),
|
|
||||||
onSuccess: (data) => {
|
|
||||||
ontimeQueryClient.setQueryData(AUTOMATION, data);
|
|
||||||
},
|
|
||||||
onSettled: () => ontimeQueryClient.invalidateQueries({ queryKey: AUTOMATION }),
|
|
||||||
});
|
|
||||||
return { isPending, mutateAsync };
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const placeholderProjectList: ProjectFileListResponse = {
|
|||||||
lastLoadedProject: '',
|
lastLoadedProject: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useProjectList() {
|
function useProjectList() {
|
||||||
const { data, status, refetch } = useQuery({
|
const { data, status, refetch } = useQuery({
|
||||||
queryKey: PROJECT_LIST,
|
queryKey: PROJECT_LIST,
|
||||||
queryFn: getProjects,
|
queryFn: getProjects,
|
||||||
|
|||||||
@@ -1,23 +1,30 @@
|
|||||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { NormalisedRundown, OntimeRundown, OntimeRundownEntry, RundownCached } from 'ontime-types';
|
import { OntimeEntry, Rundown } from 'ontime-types';
|
||||||
|
|
||||||
import { queryRefetchIntervalSlow } from '../../ontimeConfig';
|
import { queryRefetchIntervalSlow } from '../../ontimeConfig';
|
||||||
import { RUNDOWN } from '../api/constants';
|
import { RUNDOWN } from '../api/constants';
|
||||||
import { fetchNormalisedRundown } from '../api/rundown';
|
import { fetchCurrentRundown } from '../api/rundown';
|
||||||
|
|
||||||
import useProjectData from './useProjectData';
|
import useProjectData from './useProjectData';
|
||||||
|
|
||||||
// revision is -1 so that the remote revision is higher
|
// revision is -1 so that the remote revision is higher
|
||||||
const cachedRundownPlaceholder = { order: [] as string[], rundown: {} as NormalisedRundown, revision: -1 };
|
const cachedRundownPlaceholder: Rundown = {
|
||||||
|
id: 'default',
|
||||||
|
title: '',
|
||||||
|
order: [],
|
||||||
|
flatOrder: [],
|
||||||
|
entries: {},
|
||||||
|
revision: -1,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalised rundown data
|
* Normalised rundown data
|
||||||
*/
|
*/
|
||||||
export default function useRundown() {
|
export default function useRundown() {
|
||||||
const { data, status, isError, refetch, isFetching } = useQuery<RundownCached>({
|
const { data, status, isError, refetch, isFetching } = useQuery<Rundown>({
|
||||||
queryKey: RUNDOWN,
|
queryKey: RUNDOWN,
|
||||||
queryFn: fetchNormalisedRundown,
|
queryFn: fetchCurrentRundown,
|
||||||
placeholderData: (previousData, _previousQuery) => previousData,
|
placeholderData: (previousData, _previousQuery) => previousData,
|
||||||
retry: 5,
|
retry: 5,
|
||||||
retryDelay: (attempt) => attempt * 2500,
|
retryDelay: (attempt) => attempt * 2500,
|
||||||
@@ -37,16 +44,16 @@ export function useFlatRundown() {
|
|||||||
|
|
||||||
const loadedProject = useRef<string>('');
|
const loadedProject = useRef<string>('');
|
||||||
const [prevRevision, setPrevRevision] = useState<number>(-1);
|
const [prevRevision, setPrevRevision] = useState<number>(-1);
|
||||||
const [flatRunDown, setFlatRunDown] = useState<OntimeRundown>([]);
|
const [flatRundown, setFlatRundown] = useState<OntimeEntry[]>([]);
|
||||||
|
|
||||||
// update data whenever the revision changes
|
// update data whenever the revision changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data.revision !== -1 && data.revision !== prevRevision) {
|
if (data.revision !== -1 && data.revision !== prevRevision) {
|
||||||
const flatRundown = data.order.map((id) => data.rundown[id]);
|
const flatRundown = data.flatOrder.map((id) => data.entries[id]);
|
||||||
setFlatRunDown(flatRundown);
|
setFlatRundown(flatRundown);
|
||||||
setPrevRevision(data.revision);
|
setPrevRevision(data.revision);
|
||||||
}
|
}
|
||||||
}, [data.order, data.revision, data.rundown, prevRevision]);
|
}, [data.entries, data.flatOrder, data.revision, prevRevision]);
|
||||||
|
|
||||||
// TODO: should we have a project id field?
|
// TODO: should we have a project id field?
|
||||||
// invalidate current version if project changes
|
// invalidate current version if project changes
|
||||||
@@ -57,13 +64,13 @@ export function useFlatRundown() {
|
|||||||
}
|
}
|
||||||
}, [projectData]);
|
}, [projectData]);
|
||||||
|
|
||||||
return { data: flatRunDown, status };
|
return { data: flatRundown, status };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides access to a partial rundown based on a filter callback
|
* Provides access to a partial rundown based on a filter callback
|
||||||
*/
|
*/
|
||||||
export function usePartialRundown(cb: (event: OntimeRundownEntry) => boolean) {
|
export function usePartialRundown(cb: (event: OntimeEntry) => boolean) {
|
||||||
const { data, status } = useFlatRundown();
|
const { data, status } = useFlatRundown();
|
||||||
const filteredData = useMemo(() => {
|
const filteredData = useMemo(() => {
|
||||||
return data.filter(cb);
|
return data.filter(cb);
|
||||||
|
|||||||
@@ -0,0 +1,806 @@
|
|||||||
|
import { useCallback } from 'react';
|
||||||
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||||
|
import {
|
||||||
|
EntryId,
|
||||||
|
isOntimeBlock,
|
||||||
|
isOntimeEvent,
|
||||||
|
MaybeString,
|
||||||
|
OntimeBlock,
|
||||||
|
OntimeEntry,
|
||||||
|
OntimeEvent,
|
||||||
|
Rundown,
|
||||||
|
TimeField,
|
||||||
|
TimeStrategy,
|
||||||
|
TransientEventPayload,
|
||||||
|
} from 'ontime-types';
|
||||||
|
import { dayInMs, generateId, MILLIS_PER_SECOND, parseUserTime, swapEventData } from 'ontime-utils';
|
||||||
|
|
||||||
|
import { moveDown, moveUp } from '../../features/rundown/rundown.utils';
|
||||||
|
import { RUNDOWN } from '../api/constants';
|
||||||
|
import {
|
||||||
|
deleteEntries,
|
||||||
|
patchReorderEntry,
|
||||||
|
postAddEntry,
|
||||||
|
postCloneEntry,
|
||||||
|
putBatchEditEvents,
|
||||||
|
putEditEntry,
|
||||||
|
ReorderEntry,
|
||||||
|
requestApplyDelay,
|
||||||
|
requestDeleteAll,
|
||||||
|
requestEventSwap,
|
||||||
|
requestGroupEntries,
|
||||||
|
requestUngroup,
|
||||||
|
SwapEntry,
|
||||||
|
} from '../api/rundown';
|
||||||
|
import { logAxiosError } from '../api/utils';
|
||||||
|
import { useEditorSettings } from '../stores/editorSettings';
|
||||||
|
|
||||||
|
export type EventOptions = Partial<{
|
||||||
|
// options to any new block (event / delay / block)
|
||||||
|
after: MaybeString;
|
||||||
|
before: MaybeString;
|
||||||
|
// options to blocks of type OntimeEvent
|
||||||
|
defaultPublic: boolean;
|
||||||
|
linkPrevious: boolean;
|
||||||
|
lastEventId: MaybeString;
|
||||||
|
}>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gather utilities for actions on entries
|
||||||
|
*/
|
||||||
|
export const useEntryActions = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const {
|
||||||
|
defaultPublic,
|
||||||
|
linkPrevious,
|
||||||
|
defaultTimeStrategy,
|
||||||
|
defaultDuration,
|
||||||
|
defaultWarnTime,
|
||||||
|
defaultDangerTime,
|
||||||
|
defaultTimerType,
|
||||||
|
defaultEndAction,
|
||||||
|
} = useEditorSettings();
|
||||||
|
|
||||||
|
const getEntryById = useCallback(
|
||||||
|
(eventId: string): OntimeEntry | undefined => {
|
||||||
|
const cachedRundown = queryClient.getQueryData<Rundown>(RUNDOWN);
|
||||||
|
if (!cachedRundown?.entries) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return cachedRundown.entries[eventId];
|
||||||
|
},
|
||||||
|
[queryClient],
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls mutation to add new entry
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
const _addEntryMutation = useMutation({
|
||||||
|
// TODO(v4): optimistic create entry
|
||||||
|
mutationFn: postAddEntry,
|
||||||
|
onSettled: () => queryClient.invalidateQueries({ queryKey: RUNDOWN }),
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an entry to rundown
|
||||||
|
*/
|
||||||
|
const addEntry = useCallback(
|
||||||
|
async (entry: Partial<OntimeEntry>, options?: EventOptions) => {
|
||||||
|
const newEntry: TransientEventPayload = { ...entry, id: generateId() };
|
||||||
|
|
||||||
|
// ************* CHECK OPTIONS specific to events
|
||||||
|
if (isOntimeEvent(newEntry)) {
|
||||||
|
// merge creation time options with event settings
|
||||||
|
const applicationOptions = {
|
||||||
|
after: options?.after,
|
||||||
|
before: options?.before,
|
||||||
|
defaultPublic: options?.defaultPublic ?? defaultPublic,
|
||||||
|
lastEventId: options?.lastEventId,
|
||||||
|
linkPrevious: options?.linkPrevious ?? linkPrevious,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (applicationOptions?.lastEventId) {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- we know this is a value
|
||||||
|
const rundownData = queryClient.getQueryData<Rundown>(RUNDOWN)!;
|
||||||
|
const previousEvent = rundownData.entries[applicationOptions.lastEventId];
|
||||||
|
if (isOntimeEvent(previousEvent)) {
|
||||||
|
newEntry.timeStart = previousEvent.timeEnd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Override event with options from editor settings
|
||||||
|
newEntry.linkStart = applicationOptions.linkPrevious;
|
||||||
|
newEntry.isPublic = applicationOptions.defaultPublic;
|
||||||
|
|
||||||
|
if (newEntry.duration === undefined && newEntry.timeEnd === undefined) {
|
||||||
|
newEntry.duration = parseUserTime(defaultDuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newEntry.timeDanger === undefined) {
|
||||||
|
newEntry.timeDanger = parseUserTime(defaultDangerTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newEntry.timeWarning === undefined) {
|
||||||
|
newEntry.timeWarning = parseUserTime(defaultWarnTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newEntry.timerType === undefined) {
|
||||||
|
newEntry.timerType = defaultTimerType;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newEntry.endAction === undefined) {
|
||||||
|
newEntry.endAction = defaultEndAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newEntry.timeStrategy === undefined) {
|
||||||
|
newEntry.timeStrategy = defaultTimeStrategy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle adding options that concern all event type
|
||||||
|
if (options?.after) {
|
||||||
|
(newEntry as TransientEventPayload).after = options.after;
|
||||||
|
}
|
||||||
|
if (options?.before) {
|
||||||
|
(newEntry as TransientEventPayload).before = options.before;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await _addEntryMutation.mutateAsync(newEntry);
|
||||||
|
} catch (error) {
|
||||||
|
logAxiosError('Failed adding event', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[
|
||||||
|
_addEntryMutation,
|
||||||
|
defaultDangerTime,
|
||||||
|
defaultDuration,
|
||||||
|
defaultEndAction,
|
||||||
|
defaultPublic,
|
||||||
|
defaultTimerType,
|
||||||
|
defaultTimeStrategy,
|
||||||
|
defaultWarnTime,
|
||||||
|
linkPrevious,
|
||||||
|
queryClient,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls mutation to clone a selection
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
const _cloneMutation = useMutation({
|
||||||
|
mutationFn: postCloneEntry,
|
||||||
|
onSettled: () => queryClient.invalidateQueries({ queryKey: RUNDOWN }),
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clone a selection
|
||||||
|
*/
|
||||||
|
const clone = useCallback(
|
||||||
|
async (entryId: EntryId) => {
|
||||||
|
try {
|
||||||
|
await _cloneMutation.mutateAsync(entryId);
|
||||||
|
} catch (error) {
|
||||||
|
logAxiosError('Error cloning entry', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[_cloneMutation],
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls mutation to update existing entry
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
const _updateEntryMutation = useMutation({
|
||||||
|
mutationFn: putEditEntry,
|
||||||
|
// we optimistically update here
|
||||||
|
onMutate: async (newEvent) => {
|
||||||
|
// cancel ongoing queries
|
||||||
|
await queryClient.cancelQueries({ queryKey: RUNDOWN });
|
||||||
|
|
||||||
|
// Snapshot the previous value
|
||||||
|
const previousData = queryClient.getQueryData<Rundown>(RUNDOWN);
|
||||||
|
const eventId = newEvent.id;
|
||||||
|
|
||||||
|
if (previousData && eventId) {
|
||||||
|
// optimistically update object
|
||||||
|
const newRundown = { ...previousData.entries };
|
||||||
|
// @ts-expect-error -- we expect the events to be of same type
|
||||||
|
newRundown[eventId] = { ...newRundown[eventId], ...newEvent };
|
||||||
|
queryClient.setQueryData<Rundown>(RUNDOWN, {
|
||||||
|
id: previousData.id,
|
||||||
|
title: previousData.title,
|
||||||
|
order: previousData.order,
|
||||||
|
flatOrder: previousData.flatOrder,
|
||||||
|
entries: newRundown,
|
||||||
|
revision: -1,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a context with the previous and new events
|
||||||
|
return { previousData, newEvent };
|
||||||
|
},
|
||||||
|
// Mutation fails, rollback undoes optimist update
|
||||||
|
onError: (_error, _newEvent, context) => {
|
||||||
|
queryClient.setQueryData<Rundown>(RUNDOWN, context?.previousData);
|
||||||
|
},
|
||||||
|
// Mutation finished, failed or successful
|
||||||
|
// Fetch anyway, just to be sure
|
||||||
|
onSettled: async () => {
|
||||||
|
await queryClient.invalidateQueries({ queryKey: RUNDOWN });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates existing entry
|
||||||
|
*/
|
||||||
|
const updateEntry = useCallback(
|
||||||
|
async (event: Partial<OntimeEntry>) => {
|
||||||
|
try {
|
||||||
|
await _updateEntryMutation.mutateAsync(event);
|
||||||
|
} catch (error) {
|
||||||
|
logAxiosError('Error updating event', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[_updateEntryMutation],
|
||||||
|
);
|
||||||
|
|
||||||
|
const updateCustomField = useCallback(
|
||||||
|
async (entryId: EntryId, field: string, value: string) => {
|
||||||
|
updateEntry({ id: entryId, custom: { [field]: value } });
|
||||||
|
},
|
||||||
|
[updateEntry],
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates time of existing event
|
||||||
|
* @param eventId {EntryId} - id of the event
|
||||||
|
* @param field {TimeField} - field to update
|
||||||
|
* @param value {string} - new value string to be parsed
|
||||||
|
* @param lockOnUpdate {boolean} - whether we will apply the lock / release on update
|
||||||
|
*/
|
||||||
|
const updateTimer = useCallback(
|
||||||
|
async (eventId: EntryId, field: TimeField, value: string, lockOnUpdate?: boolean) => {
|
||||||
|
// an empty value with no lock has no domain validity
|
||||||
|
if (!lockOnUpdate && value === '') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newEvent: Partial<OntimeEvent> = {
|
||||||
|
id: eventId,
|
||||||
|
};
|
||||||
|
|
||||||
|
// check if we should lock the field
|
||||||
|
if (lockOnUpdate) {
|
||||||
|
if (field === 'timeEnd') {
|
||||||
|
// an empty value indicates that we should unlock the field
|
||||||
|
newEvent.timeStrategy = value === '' ? TimeStrategy.LockDuration : TimeStrategy.LockEnd;
|
||||||
|
newEvent.timeEnd = value === '' ? undefined : calculateNewValue();
|
||||||
|
} else if (field === 'duration') {
|
||||||
|
// an empty value indicates that we should unlock the field
|
||||||
|
newEvent.timeStrategy = value === '' ? TimeStrategy.LockEnd : TimeStrategy.LockDuration;
|
||||||
|
newEvent.duration = value === '' ? undefined : calculateNewValue();
|
||||||
|
} else if (field === 'timeStart') {
|
||||||
|
// an empty values means we should link to the previous
|
||||||
|
newEvent.linkStart = value === '';
|
||||||
|
newEvent.timeStart = value === '' ? undefined : calculateNewValue();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newEvent[field] = calculateNewValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await _updateEntryMutation.mutateAsync(newEvent);
|
||||||
|
} catch (error) {
|
||||||
|
logAxiosError('Error updating event', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility function to calculate the new time value
|
||||||
|
*/
|
||||||
|
function calculateNewValue(): number {
|
||||||
|
let newValMillis = 0;
|
||||||
|
|
||||||
|
// check for previous keyword
|
||||||
|
if (value === 'p' || value === 'prev' || value === 'previous') {
|
||||||
|
newValMillis = getPreviousEnd();
|
||||||
|
|
||||||
|
// check for adding time keyword
|
||||||
|
} else if (value.startsWith('+') || value.startsWith('p+') || value.startsWith('p +')) {
|
||||||
|
// TODO: is this logic solid?
|
||||||
|
const remainingString = value.substring(1);
|
||||||
|
newValMillis = getPreviousEnd() + parseUserTime(remainingString);
|
||||||
|
} else {
|
||||||
|
newValMillis = parseUserTime(value);
|
||||||
|
}
|
||||||
|
// dont allow timer values over 23:59:59
|
||||||
|
return Math.min(newValMillis, dayInMs - MILLIS_PER_SECOND);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility function to get the previous event end time
|
||||||
|
*/
|
||||||
|
function getPreviousEnd(): number {
|
||||||
|
const cachedRundown = queryClient.getQueryData<Rundown>(RUNDOWN);
|
||||||
|
|
||||||
|
if (!cachedRundown?.order || !cachedRundown?.entries) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const index = cachedRundown.order.indexOf(eventId);
|
||||||
|
if (index === 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
let previousEnd = 0;
|
||||||
|
for (let i = index - 1; i >= 0; i--) {
|
||||||
|
const event = cachedRundown.entries[cachedRundown.order[i]];
|
||||||
|
if (isOntimeEvent(event)) {
|
||||||
|
previousEnd = event.timeEnd;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return previousEnd;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[_updateEntryMutation, queryClient],
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls mutation to edit multiple events
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
const _batchUpdateEventsMutation = useMutation({
|
||||||
|
mutationFn: putBatchEditEvents,
|
||||||
|
onMutate: async ({ ids, data }) => {
|
||||||
|
// cancel ongoing queries
|
||||||
|
await queryClient.cancelQueries({ queryKey: RUNDOWN });
|
||||||
|
|
||||||
|
// Snapshot the previous value
|
||||||
|
const previousRundown = queryClient.getQueryData<Rundown>(RUNDOWN);
|
||||||
|
|
||||||
|
if (previousRundown) {
|
||||||
|
const eventIds = new Set(ids);
|
||||||
|
const newRundown = { ...previousRundown.entries };
|
||||||
|
|
||||||
|
eventIds.forEach((eventId) => {
|
||||||
|
if (Object.hasOwn(newRundown, eventId)) {
|
||||||
|
const event = newRundown[eventId];
|
||||||
|
if (isOntimeEvent(event)) {
|
||||||
|
newRundown[eventId] = {
|
||||||
|
...event,
|
||||||
|
...data,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
queryClient.setQueryData<Rundown>(RUNDOWN, {
|
||||||
|
id: previousRundown.id,
|
||||||
|
title: previousRundown.title,
|
||||||
|
order: previousRundown.order,
|
||||||
|
flatOrder: previousRundown.flatOrder,
|
||||||
|
entries: newRundown,
|
||||||
|
revision: -1,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a context with the previous rundown
|
||||||
|
return { previousRundown };
|
||||||
|
},
|
||||||
|
onSuccess: (response) => {
|
||||||
|
if (!response.data) return;
|
||||||
|
|
||||||
|
const { id, title, order, flatOrder, entries, revision } = response.data;
|
||||||
|
queryClient.setQueryData<Rundown>(RUNDOWN, {
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
order,
|
||||||
|
flatOrder,
|
||||||
|
entries,
|
||||||
|
revision,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onError: (_error, _newEvent, context) => {
|
||||||
|
queryClient.setQueryData<Rundown>(RUNDOWN, context?.previousRundown);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const batchUpdateEvents = useCallback(
|
||||||
|
async (data: Partial<OntimeEvent>, eventIds: string[]) => {
|
||||||
|
try {
|
||||||
|
await _batchUpdateEventsMutation.mutateAsync({ ids: eventIds, data });
|
||||||
|
} catch (error) {
|
||||||
|
logAxiosError('Error updating events', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[_batchUpdateEventsMutation],
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls mutation to delete an entry
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
const _deleteEntryMutation = useMutation({
|
||||||
|
mutationFn: deleteEntries,
|
||||||
|
// we optimistically update here
|
||||||
|
onMutate: async (entryIds: EntryId[]) => {
|
||||||
|
// cancel ongoing queries
|
||||||
|
await queryClient.cancelQueries({ queryKey: RUNDOWN });
|
||||||
|
|
||||||
|
// Snapshot the previous value
|
||||||
|
const previousData = queryClient.getQueryData<Rundown>(RUNDOWN);
|
||||||
|
|
||||||
|
if (previousData) {
|
||||||
|
// optimistically update object
|
||||||
|
const { entries, order, flatOrder } = optimisticDeleteEntries(entryIds, previousData);
|
||||||
|
|
||||||
|
queryClient.setQueryData<Rundown>(RUNDOWN, {
|
||||||
|
id: previousData.id,
|
||||||
|
title: previousData.title,
|
||||||
|
order,
|
||||||
|
flatOrder,
|
||||||
|
entries,
|
||||||
|
revision: -1,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a context with the previous and new events
|
||||||
|
return { previousData };
|
||||||
|
},
|
||||||
|
|
||||||
|
// Mutation fails, rollback undoes optimist update
|
||||||
|
onError: (_error, _entryIds, context) => {
|
||||||
|
queryClient.setQueryData<Rundown>(RUNDOWN, context?.previousData);
|
||||||
|
},
|
||||||
|
// Mutation finished, failed or successful
|
||||||
|
// Fetch anyway, just to be sure
|
||||||
|
onSettled: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: RUNDOWN });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes an event entry from the rundown
|
||||||
|
*/
|
||||||
|
const deleteEntry = useCallback(
|
||||||
|
async (entryIds: EntryId[]) => {
|
||||||
|
try {
|
||||||
|
await _deleteEntryMutation.mutateAsync(entryIds);
|
||||||
|
} catch (error) {
|
||||||
|
logAxiosError('Error deleting event', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[_deleteEntryMutation],
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls mutation to delete all events
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
const _deleteAllEntriesMutation = useMutation({
|
||||||
|
mutationFn: requestDeleteAll,
|
||||||
|
// we optimistically update here
|
||||||
|
onMutate: async () => {
|
||||||
|
// cancel ongoing queries
|
||||||
|
await queryClient.cancelQueries({ queryKey: RUNDOWN });
|
||||||
|
|
||||||
|
// Snapshot the previous value
|
||||||
|
const previousData = queryClient.getQueryData<Rundown>(RUNDOWN);
|
||||||
|
|
||||||
|
// optimistically update object
|
||||||
|
queryClient.setQueryData<Rundown>(RUNDOWN, {
|
||||||
|
id: previousData?.id ?? 'default',
|
||||||
|
title: previousData?.title ?? '',
|
||||||
|
order: [],
|
||||||
|
flatOrder: [],
|
||||||
|
entries: {},
|
||||||
|
revision: -1,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Return a context with the previous and new events
|
||||||
|
return { previousData };
|
||||||
|
},
|
||||||
|
|
||||||
|
// Mutation fails, rollback optimist update
|
||||||
|
onError: (_error, _, context) => {
|
||||||
|
queryClient.setQueryData<Rundown>(RUNDOWN, context?.previousData);
|
||||||
|
},
|
||||||
|
// Mutation finished, failed or successful
|
||||||
|
// Fetch anyway, just to be sure
|
||||||
|
onSettled: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: RUNDOWN });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes all entries in the rundown
|
||||||
|
*/
|
||||||
|
const deleteAllEntries = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
await _deleteAllEntriesMutation.mutateAsync();
|
||||||
|
} catch (error) {
|
||||||
|
logAxiosError('Error deleting events', error);
|
||||||
|
}
|
||||||
|
}, [_deleteAllEntriesMutation]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls mutation to apply a delay
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
const _applyDelayMutation = useMutation({
|
||||||
|
mutationFn: requestApplyDelay,
|
||||||
|
onSuccess: (response) => {
|
||||||
|
if (!response.data) return;
|
||||||
|
|
||||||
|
const { id, title, order, flatOrder, entries, revision } = response.data;
|
||||||
|
queryClient.setQueryData<Rundown>(RUNDOWN, {
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
order,
|
||||||
|
flatOrder,
|
||||||
|
entries,
|
||||||
|
revision,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// Mutation finished, failed or successful
|
||||||
|
onSettled: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: RUNDOWN });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies a given delay
|
||||||
|
*/
|
||||||
|
const applyDelay = useCallback(
|
||||||
|
async (delayEventId: EntryId) => {
|
||||||
|
try {
|
||||||
|
await _applyDelayMutation.mutateAsync(delayEventId);
|
||||||
|
} catch (error) {
|
||||||
|
logAxiosError('Error applying delay', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[_applyDelayMutation],
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls mutation to dissolve a block
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
const _ungroupMutation = useMutation({
|
||||||
|
mutationFn: requestUngroup,
|
||||||
|
onSuccess: (response) => {
|
||||||
|
if (!response.data) return;
|
||||||
|
|
||||||
|
const { id, title, order, flatOrder, entries, revision } = response.data;
|
||||||
|
queryClient.setQueryData<Rundown>(RUNDOWN, {
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
order,
|
||||||
|
flatOrder,
|
||||||
|
entries,
|
||||||
|
revision,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onSettled: () => queryClient.invalidateQueries({ queryKey: RUNDOWN }),
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a block and moves its events to the top level
|
||||||
|
*/
|
||||||
|
const ungroup = useCallback(
|
||||||
|
async (blockId: EntryId) => {
|
||||||
|
try {
|
||||||
|
await _ungroupMutation.mutateAsync(blockId);
|
||||||
|
} catch (error) {
|
||||||
|
logAxiosError('Error dissolving block', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[_ungroupMutation],
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls mutation to create a block with a selection
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
const _groupEntriesMutation = useMutation({
|
||||||
|
mutationFn: requestGroupEntries,
|
||||||
|
onSuccess: (response) => {
|
||||||
|
if (!response.data) return;
|
||||||
|
|
||||||
|
const { id, title, order, flatOrder, entries, revision } = response.data;
|
||||||
|
queryClient.setQueryData<Rundown>(RUNDOWN, {
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
order,
|
||||||
|
flatOrder,
|
||||||
|
entries,
|
||||||
|
revision,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onSettled: () => queryClient.invalidateQueries({ queryKey: RUNDOWN }),
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a block with a selection
|
||||||
|
*/
|
||||||
|
const groupEntries = useCallback(
|
||||||
|
async (entryIds: EntryId[]) => {
|
||||||
|
try {
|
||||||
|
await _groupEntriesMutation.mutateAsync(entryIds);
|
||||||
|
} catch (error) {
|
||||||
|
logAxiosError('Error grouping entries', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[_groupEntriesMutation],
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls mutation to reorder an entry
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
const _reorderEntryMutation = useMutation({
|
||||||
|
mutationFn: patchReorderEntry,
|
||||||
|
// Mutation finished, failed or successful
|
||||||
|
// Fetch anyway, just to be sure
|
||||||
|
onSettled: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: RUNDOWN });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reorders a given entry
|
||||||
|
*/
|
||||||
|
const reorderEntry = useCallback(
|
||||||
|
async (entryId: EntryId, destinationId: EntryId, order: 'before' | 'after' | 'insert') => {
|
||||||
|
try {
|
||||||
|
const reorderObject: ReorderEntry = {
|
||||||
|
entryId,
|
||||||
|
destinationId,
|
||||||
|
order,
|
||||||
|
};
|
||||||
|
await _reorderEntryMutation.mutateAsync(reorderObject);
|
||||||
|
} catch (error) {
|
||||||
|
logAxiosError('Error re-ordering event', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[_reorderEntryMutation],
|
||||||
|
);
|
||||||
|
|
||||||
|
const move = useCallback(async (entryId: EntryId, direction: 'up' | 'down') => {
|
||||||
|
const cachedRundown = queryClient.getQueryData<Rundown>(RUNDOWN);
|
||||||
|
if (!cachedRundown?.order) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { destinationId, order } =
|
||||||
|
direction === 'up'
|
||||||
|
? moveUp(entryId, cachedRundown.order, cachedRundown.entries)
|
||||||
|
: moveDown(entryId, cachedRundown.order, cachedRundown.entries);
|
||||||
|
|
||||||
|
if (destinationId) {
|
||||||
|
try {
|
||||||
|
const reorderObject: ReorderEntry = {
|
||||||
|
entryId,
|
||||||
|
destinationId,
|
||||||
|
order: order as 'before' | 'after' | 'insert',
|
||||||
|
};
|
||||||
|
await _reorderEntryMutation.mutateAsync(reorderObject);
|
||||||
|
} catch (error) {
|
||||||
|
logAxiosError('Error re-ordering event', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls mutation to swap events
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
const _swapEvents = useMutation({
|
||||||
|
mutationFn: requestEventSwap,
|
||||||
|
// we optimistically update here
|
||||||
|
onMutate: async ({ from, to }) => {
|
||||||
|
// cancel ongoing queries
|
||||||
|
await queryClient.cancelQueries({ queryKey: RUNDOWN });
|
||||||
|
|
||||||
|
// Snapshot the previous value
|
||||||
|
const previousData = queryClient.getQueryData<Rundown>(RUNDOWN);
|
||||||
|
if (previousData) {
|
||||||
|
// optimistically update object
|
||||||
|
const newRundown = { ...previousData.entries };
|
||||||
|
const eventA = previousData.entries[from];
|
||||||
|
const eventB = previousData.entries[to];
|
||||||
|
|
||||||
|
if (!isOntimeEvent(eventA) || !isOntimeEvent(eventB)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [newA, newB] = swapEventData(eventA, eventB);
|
||||||
|
newRundown[from] = newA;
|
||||||
|
newRundown[to] = newB;
|
||||||
|
|
||||||
|
queryClient.setQueryData<Rundown>(RUNDOWN, {
|
||||||
|
id: previousData.id,
|
||||||
|
title: previousData.title,
|
||||||
|
order: previousData.order,
|
||||||
|
flatOrder: previousData.flatOrder,
|
||||||
|
entries: newRundown,
|
||||||
|
revision: -1,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a context with the previous events
|
||||||
|
return { previousData };
|
||||||
|
},
|
||||||
|
|
||||||
|
// Mutation fails, rollback undoes optimist update
|
||||||
|
onError: (_error, _eventId, context) => {
|
||||||
|
queryClient.setQueryData<Rundown>(RUNDOWN, context?.previousData);
|
||||||
|
},
|
||||||
|
// Mutation finished, failed or successful
|
||||||
|
// Fetch anyway, just to be sure
|
||||||
|
onSettled: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: RUNDOWN });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swaps the schedule of two events
|
||||||
|
*/
|
||||||
|
const swapEvents = useCallback(
|
||||||
|
async ({ from, to }: SwapEntry) => {
|
||||||
|
try {
|
||||||
|
await _swapEvents.mutateAsync({ from, to });
|
||||||
|
} catch (error) {
|
||||||
|
logAxiosError('Error re-ordering event', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[_swapEvents],
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
addEntry,
|
||||||
|
applyDelay,
|
||||||
|
batchUpdateEvents,
|
||||||
|
clone,
|
||||||
|
deleteEntry,
|
||||||
|
deleteAllEntries,
|
||||||
|
ungroup,
|
||||||
|
getEntryById,
|
||||||
|
groupEntries,
|
||||||
|
move,
|
||||||
|
reorderEntry,
|
||||||
|
swapEvents,
|
||||||
|
updateEntry,
|
||||||
|
updateTimer,
|
||||||
|
updateCustomField,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility to optimistically delete entries from client cache
|
||||||
|
*/
|
||||||
|
function optimisticDeleteEntries(entryIds: EntryId[], rundown: Rundown) {
|
||||||
|
const entries = { ...rundown.entries };
|
||||||
|
let order = [...rundown.order];
|
||||||
|
let flatOrder = [...rundown.flatOrder];
|
||||||
|
|
||||||
|
for (let i = 0; i < entryIds.length; i++) {
|
||||||
|
const entry = entries[entryIds[i]];
|
||||||
|
deleteEntry(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteEntry(entry: OntimeEntry) {
|
||||||
|
if (isOntimeBlock(entry) || !entry.parent) {
|
||||||
|
order = order.filter((id) => id !== entry.id);
|
||||||
|
} else {
|
||||||
|
const parent = entries[entry.parent] as OntimeBlock;
|
||||||
|
parent.events = parent.events.filter((event) => event !== entry.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete entries[entry.id];
|
||||||
|
flatOrder = flatOrder.filter((id) => id !== entry.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { entries, order, flatOrder };
|
||||||
|
}
|
||||||
@@ -1,636 +0,0 @@
|
|||||||
import { useCallback } from 'react';
|
|
||||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
||||||
import {
|
|
||||||
isOntimeEvent,
|
|
||||||
OntimeBlock,
|
|
||||||
OntimeDelay,
|
|
||||||
OntimeEvent,
|
|
||||||
OntimeRundownEntry,
|
|
||||||
RundownCached,
|
|
||||||
TimeField,
|
|
||||||
TimeStrategy,
|
|
||||||
TransientEventPayload,
|
|
||||||
} from 'ontime-types';
|
|
||||||
import { dayInMs, MILLIS_PER_SECOND, parseUserTime, reorderArray, swapEventData } from 'ontime-utils';
|
|
||||||
|
|
||||||
import { RUNDOWN } from '../api/constants';
|
|
||||||
import {
|
|
||||||
ReorderEntry,
|
|
||||||
requestApplyDelay,
|
|
||||||
requestBatchPutEvents,
|
|
||||||
requestDelete,
|
|
||||||
requestDeleteAll,
|
|
||||||
requestEventSwap,
|
|
||||||
requestPostEvent,
|
|
||||||
requestPutEvent,
|
|
||||||
requestReorderEvent,
|
|
||||||
SwapEntry,
|
|
||||||
} from '../api/rundown';
|
|
||||||
import { logAxiosError } from '../api/utils';
|
|
||||||
import { useEditorSettings } from '../stores/editorSettings';
|
|
||||||
|
|
||||||
export type EventOptions = Partial<{
|
|
||||||
// options to any new block (event / delay / block)
|
|
||||||
after: string;
|
|
||||||
before: string;
|
|
||||||
// options to blocks of type OntimeEvent
|
|
||||||
defaultPublic: boolean;
|
|
||||||
linkPrevious: boolean;
|
|
||||||
lastEventId: string;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Set of utilities for events //TODO: should this be called useEntryAction and so on
|
|
||||||
*/
|
|
||||||
export const useEventAction = () => {
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
const {
|
|
||||||
defaultPublic,
|
|
||||||
linkPrevious,
|
|
||||||
defaultTimeStrategy,
|
|
||||||
defaultDuration,
|
|
||||||
defaultWarnTime,
|
|
||||||
defaultDangerTime,
|
|
||||||
defaultTimerType,
|
|
||||||
defaultEndAction,
|
|
||||||
} = useEditorSettings();
|
|
||||||
|
|
||||||
const getEventById = useCallback(
|
|
||||||
(eventId: string) => {
|
|
||||||
const cachedRundown = queryClient.getQueryData<RundownCached>(RUNDOWN);
|
|
||||||
if (!cachedRundown?.rundown) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return cachedRundown.rundown[eventId];
|
|
||||||
},
|
|
||||||
[queryClient],
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls mutation to add new event
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
const _addEventMutation = useMutation({
|
|
||||||
mutationFn: requestPostEvent,
|
|
||||||
onSettled: () => {
|
|
||||||
queryClient.invalidateQueries({ queryKey: RUNDOWN });
|
|
||||||
},
|
|
||||||
networkMode: 'always',
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds an event to rundown
|
|
||||||
*/
|
|
||||||
const addEvent = useCallback(
|
|
||||||
async (event: Partial<OntimeEvent | OntimeDelay | OntimeBlock>, options?: EventOptions) => {
|
|
||||||
const newEvent: TransientEventPayload = { ...event };
|
|
||||||
|
|
||||||
// ************* CHECK OPTIONS specific to events
|
|
||||||
if (isOntimeEvent(newEvent)) {
|
|
||||||
// merge creation time options with event settings
|
|
||||||
const applicationOptions = {
|
|
||||||
after: options?.after,
|
|
||||||
before: options?.before,
|
|
||||||
defaultPublic: options?.defaultPublic ?? defaultPublic,
|
|
||||||
lastEventId: options?.lastEventId,
|
|
||||||
linkPrevious: options?.linkPrevious ?? linkPrevious,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (applicationOptions.linkPrevious && applicationOptions?.lastEventId) {
|
|
||||||
newEvent.linkStart = applicationOptions.lastEventId;
|
|
||||||
} else if (applicationOptions?.lastEventId) {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- we know this is a value
|
|
||||||
const rundownData = queryClient.getQueryData<RundownCached>(RUNDOWN)!;
|
|
||||||
const { rundown } = rundownData;
|
|
||||||
const previousEvent = rundown[applicationOptions.lastEventId];
|
|
||||||
if (isOntimeEvent(previousEvent)) {
|
|
||||||
newEvent.timeStart = previousEvent.timeEnd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Override event with options from editor settings
|
|
||||||
if (applicationOptions.defaultPublic) {
|
|
||||||
newEvent.isPublic = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newEvent.duration === undefined && newEvent.timeEnd === undefined) {
|
|
||||||
newEvent.duration = parseUserTime(defaultDuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newEvent.timeDanger === undefined) {
|
|
||||||
newEvent.timeDanger = parseUserTime(defaultDangerTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newEvent.timeWarning === undefined) {
|
|
||||||
newEvent.timeWarning = parseUserTime(defaultWarnTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newEvent.timerType === undefined) {
|
|
||||||
newEvent.timerType = defaultTimerType;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newEvent.endAction === undefined) {
|
|
||||||
newEvent.endAction = defaultEndAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newEvent.timeStrategy === undefined) {
|
|
||||||
newEvent.timeStrategy = defaultTimeStrategy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle adding options that concern all event type
|
|
||||||
if (options?.after) {
|
|
||||||
// @ts-expect-error -- not sure how to type this, <after> is a transient property
|
|
||||||
newEvent.after = options.after;
|
|
||||||
}
|
|
||||||
if (options?.before) {
|
|
||||||
// @ts-expect-error -- not sure how to type this, <before> is a transient property
|
|
||||||
newEvent.before = options.before;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await _addEventMutation.mutateAsync(newEvent as TransientEventPayload);
|
|
||||||
} catch (error) {
|
|
||||||
logAxiosError('Failed adding event', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[
|
|
||||||
_addEventMutation,
|
|
||||||
defaultDangerTime,
|
|
||||||
defaultDuration,
|
|
||||||
defaultEndAction,
|
|
||||||
defaultPublic,
|
|
||||||
defaultTimerType,
|
|
||||||
defaultTimeStrategy,
|
|
||||||
defaultWarnTime,
|
|
||||||
linkPrevious,
|
|
||||||
queryClient,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls mutation to update existing event
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
const _updateEventMutation = useMutation({
|
|
||||||
mutationFn: requestPutEvent,
|
|
||||||
// we optimistically update here
|
|
||||||
onMutate: async (newEvent) => {
|
|
||||||
// cancel ongoing queries
|
|
||||||
await queryClient.cancelQueries({ queryKey: RUNDOWN });
|
|
||||||
|
|
||||||
// Snapshot the previous value
|
|
||||||
const previousData = queryClient.getQueryData<RundownCached>(RUNDOWN);
|
|
||||||
const eventId = newEvent.id;
|
|
||||||
|
|
||||||
if (previousData && eventId) {
|
|
||||||
// optimistically update object
|
|
||||||
const newRundown = { ...previousData.rundown };
|
|
||||||
// @ts-expect-error -- we expect the events to be of same type
|
|
||||||
newRundown[eventId] = { ...newRundown[eventId], ...newEvent };
|
|
||||||
queryClient.setQueryData(RUNDOWN, { order: previousData.order, rundown: newRundown, revision: -1 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return a context with the previous and new events
|
|
||||||
return { previousData, newEvent };
|
|
||||||
},
|
|
||||||
// Mutation fails, rollback undoes optimist update
|
|
||||||
onError: (_error, _newEvent, context) => {
|
|
||||||
queryClient.setQueryData(RUNDOWN, context?.previousData);
|
|
||||||
},
|
|
||||||
// Mutation finished, failed or successful
|
|
||||||
// Fetch anyway, just to be sure
|
|
||||||
onSettled: async () => {
|
|
||||||
await queryClient.invalidateQueries({ queryKey: RUNDOWN });
|
|
||||||
},
|
|
||||||
networkMode: 'always',
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates existing event
|
|
||||||
*/
|
|
||||||
const updateEvent = useCallback(
|
|
||||||
async (event: Partial<OntimeRundownEntry>) => {
|
|
||||||
try {
|
|
||||||
await _updateEventMutation.mutateAsync(event);
|
|
||||||
} catch (error) {
|
|
||||||
logAxiosError('Error updating event', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[_updateEventMutation],
|
|
||||||
);
|
|
||||||
|
|
||||||
const updateCustomField = useCallback(
|
|
||||||
async (eventId: string, field: string, value: string) => {
|
|
||||||
updateEvent({ id: eventId, custom: { [field]: value } });
|
|
||||||
},
|
|
||||||
[updateEvent],
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates time of existing event
|
|
||||||
* @param eventId {string} - id of the event
|
|
||||||
* @param field {TimeField} - field to update
|
|
||||||
* @param value {string} - new value string to be parsed
|
|
||||||
* @param lockOnUpdate {boolean} - whether we will apply the lock / release on update
|
|
||||||
*/
|
|
||||||
const updateTimer = useCallback(
|
|
||||||
async (eventId: string, field: TimeField, value: string, lockOnUpdate?: boolean) => {
|
|
||||||
// an empty value with no lock has no domain validity
|
|
||||||
if (!lockOnUpdate && value === '') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const newEvent: Partial<OntimeEvent> = {
|
|
||||||
id: eventId,
|
|
||||||
};
|
|
||||||
|
|
||||||
// check if we should lock the field
|
|
||||||
if (lockOnUpdate) {
|
|
||||||
if (field === 'timeEnd') {
|
|
||||||
// an empty value indicates that we should unlock the field
|
|
||||||
newEvent.timeStrategy = value === '' ? TimeStrategy.LockDuration : TimeStrategy.LockEnd;
|
|
||||||
newEvent.timeEnd = value === '' ? undefined : calculateNewValue();
|
|
||||||
} else if (field === 'duration') {
|
|
||||||
// an empty value indicates that we should unlock the field
|
|
||||||
newEvent.timeStrategy = value === '' ? TimeStrategy.LockEnd : TimeStrategy.LockDuration;
|
|
||||||
newEvent.duration = value === '' ? undefined : calculateNewValue();
|
|
||||||
} else if (field === 'timeStart') {
|
|
||||||
// an empty values means we should link to the previous
|
|
||||||
newEvent.linkStart = value === '' ? 'true' : null;
|
|
||||||
newEvent.timeStart = value === '' ? undefined : calculateNewValue();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
newEvent[field] = calculateNewValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await _updateEventMutation.mutateAsync(newEvent);
|
|
||||||
} catch (error) {
|
|
||||||
logAxiosError('Error updating event', error);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility function to calculate the new time value
|
|
||||||
*/
|
|
||||||
function calculateNewValue(): number {
|
|
||||||
let newValMillis = 0;
|
|
||||||
|
|
||||||
// check for previous keyword
|
|
||||||
if (value === 'p' || value === 'prev' || value === 'previous') {
|
|
||||||
newValMillis = getPreviousEnd();
|
|
||||||
|
|
||||||
// check for adding time keyword
|
|
||||||
} else if (value.startsWith('+') || value.startsWith('p+') || value.startsWith('p +')) {
|
|
||||||
// TODO: is this logic solid?
|
|
||||||
const remainingString = value.substring(1);
|
|
||||||
newValMillis = getPreviousEnd() + parseUserTime(remainingString);
|
|
||||||
} else {
|
|
||||||
newValMillis = parseUserTime(value);
|
|
||||||
}
|
|
||||||
// dont allow timer values over 23:59:59
|
|
||||||
return Math.min(newValMillis, dayInMs - MILLIS_PER_SECOND);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility function to get the previous event end time
|
|
||||||
*/
|
|
||||||
function getPreviousEnd(): number {
|
|
||||||
const cachedRundown = queryClient.getQueryData<RundownCached>(RUNDOWN);
|
|
||||||
|
|
||||||
if (!cachedRundown?.order || !cachedRundown?.rundown) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const index = cachedRundown.order.indexOf(eventId);
|
|
||||||
if (index === 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
let previousEnd = 0;
|
|
||||||
for (let i = index - 1; i >= 0; i--) {
|
|
||||||
const event = cachedRundown.rundown[cachedRundown.order[i]];
|
|
||||||
if (isOntimeEvent(event)) {
|
|
||||||
previousEnd = event.timeEnd;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return previousEnd;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[_updateEventMutation, queryClient],
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls mutation to edit multiple events
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
const _batchUpdateEventsMutation = useMutation({
|
|
||||||
mutationFn: requestBatchPutEvents,
|
|
||||||
onMutate: async ({ ids, data }) => {
|
|
||||||
// cancel ongoing queries
|
|
||||||
await queryClient.cancelQueries({ queryKey: RUNDOWN });
|
|
||||||
|
|
||||||
// Snapshot the previous value
|
|
||||||
const previousEvents = queryClient.getQueryData<RundownCached>(RUNDOWN);
|
|
||||||
|
|
||||||
if (previousEvents) {
|
|
||||||
const eventIds = new Set(ids);
|
|
||||||
const newRundown = { ...previousEvents.rundown };
|
|
||||||
|
|
||||||
eventIds.forEach((eventId) => {
|
|
||||||
if (Object.hasOwn(newRundown, eventId)) {
|
|
||||||
const event = newRundown[eventId];
|
|
||||||
if (isOntimeEvent(event)) {
|
|
||||||
newRundown[eventId] = {
|
|
||||||
...event,
|
|
||||||
...data,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
queryClient.setQueryData(RUNDOWN, { order: previousEvents.order, rundown: newRundown, revision: -1 });
|
|
||||||
}
|
|
||||||
// Return a context with the previous and new events
|
|
||||||
return { previousEvents };
|
|
||||||
},
|
|
||||||
onSettled: async () => {
|
|
||||||
await queryClient.invalidateQueries({ queryKey: RUNDOWN });
|
|
||||||
},
|
|
||||||
onError: (_error, _newEvent, context) => {
|
|
||||||
queryClient.setQueryData(RUNDOWN, context?.previousEvents);
|
|
||||||
},
|
|
||||||
networkMode: 'always',
|
|
||||||
});
|
|
||||||
|
|
||||||
const batchUpdateEvents = useCallback(
|
|
||||||
async (data: Partial<OntimeEvent>, eventIds: string[]) => {
|
|
||||||
try {
|
|
||||||
await _batchUpdateEventsMutation.mutateAsync({ ids: eventIds, data });
|
|
||||||
} catch (error) {
|
|
||||||
logAxiosError('Error updating events', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[_batchUpdateEventsMutation],
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls mutation to delete an event
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
const _deleteEventMutation = useMutation({
|
|
||||||
mutationFn: requestDelete,
|
|
||||||
// we optimistically update here
|
|
||||||
onMutate: async (eventIds: string[]) => {
|
|
||||||
// cancel ongoing queries
|
|
||||||
await queryClient.cancelQueries({ queryKey: RUNDOWN });
|
|
||||||
|
|
||||||
// Snapshot the previous value
|
|
||||||
const previousData = queryClient.getQueryData<RundownCached>(RUNDOWN);
|
|
||||||
|
|
||||||
if (previousData) {
|
|
||||||
// optimistically update object
|
|
||||||
const newOrder = previousData.order.filter((id) => !eventIds.includes(id));
|
|
||||||
const newRundown = { ...previousData.rundown };
|
|
||||||
for (const eventId of eventIds) {
|
|
||||||
delete newRundown[eventId];
|
|
||||||
}
|
|
||||||
|
|
||||||
queryClient.setQueryData(RUNDOWN, {
|
|
||||||
order: newOrder,
|
|
||||||
rundown: newRundown,
|
|
||||||
revision: -1,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return a context with the previous and new events
|
|
||||||
return { previousData };
|
|
||||||
},
|
|
||||||
|
|
||||||
// Mutation fails, rollback undoes optimist update
|
|
||||||
onError: (_error, _eventId, context) => {
|
|
||||||
queryClient.setQueryData(RUNDOWN, context?.previousData);
|
|
||||||
},
|
|
||||||
// Mutation finished, failed or successful
|
|
||||||
// Fetch anyway, just to be sure
|
|
||||||
onSettled: () => {
|
|
||||||
queryClient.invalidateQueries({ queryKey: RUNDOWN });
|
|
||||||
},
|
|
||||||
networkMode: 'always',
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes an event form the list
|
|
||||||
*/
|
|
||||||
const deleteEvent = useCallback(
|
|
||||||
async (eventIds: string[]) => {
|
|
||||||
try {
|
|
||||||
await _deleteEventMutation.mutateAsync(eventIds);
|
|
||||||
} catch (error) {
|
|
||||||
logAxiosError('Error deleting event', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[_deleteEventMutation],
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls mutation to delete all events
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
const _deleteAllEventsMutation = useMutation({
|
|
||||||
mutationFn: requestDeleteAll,
|
|
||||||
// we optimistically update here
|
|
||||||
onMutate: async () => {
|
|
||||||
// cancel ongoing queries
|
|
||||||
await queryClient.cancelQueries({ queryKey: RUNDOWN });
|
|
||||||
|
|
||||||
// Snapshot the previous value
|
|
||||||
const previousData = queryClient.getQueryData<RundownCached>(RUNDOWN);
|
|
||||||
|
|
||||||
// optimistically update object
|
|
||||||
queryClient.setQueryData(RUNDOWN, { rundown: {}, order: [], revision: -1 });
|
|
||||||
|
|
||||||
// Return a context with the previous and new events
|
|
||||||
return { previousData };
|
|
||||||
},
|
|
||||||
|
|
||||||
// Mutation fails, rollback undos optimist update
|
|
||||||
onError: (_error, _eventId, context) => {
|
|
||||||
queryClient.setQueryData(RUNDOWN, context?.previousData);
|
|
||||||
},
|
|
||||||
// Mutation finished, failed or successful
|
|
||||||
// Fetch anyway, just to be sure
|
|
||||||
onSettled: () => {
|
|
||||||
queryClient.invalidateQueries({ queryKey: RUNDOWN });
|
|
||||||
},
|
|
||||||
networkMode: 'always',
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes all events from list
|
|
||||||
*/
|
|
||||||
const deleteAllEvents = useCallback(async () => {
|
|
||||||
try {
|
|
||||||
await _deleteAllEventsMutation.mutateAsync();
|
|
||||||
} catch (error) {
|
|
||||||
logAxiosError('Error deleting events', error);
|
|
||||||
}
|
|
||||||
}, [_deleteAllEventsMutation]);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls mutation to apply a delay
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
const _applyDelayMutation = useMutation({
|
|
||||||
mutationFn: requestApplyDelay,
|
|
||||||
// Mutation finished, failed or successful
|
|
||||||
onSettled: () => {
|
|
||||||
queryClient.invalidateQueries({ queryKey: RUNDOWN });
|
|
||||||
},
|
|
||||||
networkMode: 'always',
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Applies a given delay block
|
|
||||||
*/
|
|
||||||
const applyDelay = useCallback(
|
|
||||||
async (delayEventId: string) => {
|
|
||||||
try {
|
|
||||||
await _applyDelayMutation.mutateAsync(delayEventId);
|
|
||||||
} catch (error) {
|
|
||||||
logAxiosError('Error applying delay', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[_applyDelayMutation],
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls mutation to reorder an event
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
const _reorderEventMutation = useMutation({
|
|
||||||
mutationFn: requestReorderEvent,
|
|
||||||
// we optimistically update here
|
|
||||||
onMutate: async (data) => {
|
|
||||||
// cancel ongoing queries
|
|
||||||
await queryClient.cancelQueries({ queryKey: RUNDOWN });
|
|
||||||
|
|
||||||
// Snapshot the previous value
|
|
||||||
const previousData = queryClient.getQueryData<RundownCached>(RUNDOWN);
|
|
||||||
|
|
||||||
if (previousData) {
|
|
||||||
// optimistically update object
|
|
||||||
const newOrder = reorderArray(previousData.order, data.from, data.to);
|
|
||||||
|
|
||||||
queryClient.setQueryData(RUNDOWN, { order: newOrder, rundown: previousData.rundown, revision: -1 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return a context with the previous and new events
|
|
||||||
return { previousData };
|
|
||||||
},
|
|
||||||
|
|
||||||
// Mutation fails, rollback undoes optimist update
|
|
||||||
onError: (_error, _eventId, context) => {
|
|
||||||
queryClient.setQueryData(RUNDOWN, context?.previousData);
|
|
||||||
},
|
|
||||||
// Mutation finished, failed or successful
|
|
||||||
// Fetch anyway, just to be sure
|
|
||||||
onSettled: () => {
|
|
||||||
queryClient.invalidateQueries({ queryKey: RUNDOWN });
|
|
||||||
},
|
|
||||||
networkMode: 'always',
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reorders a given event
|
|
||||||
*/
|
|
||||||
const reorderEvent = useCallback(
|
|
||||||
async (eventId: string, from: number, to: number) => {
|
|
||||||
try {
|
|
||||||
const reorderObject: ReorderEntry = {
|
|
||||||
eventId,
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
};
|
|
||||||
await _reorderEventMutation.mutateAsync(reorderObject);
|
|
||||||
} catch (error) {
|
|
||||||
logAxiosError('Error re-ordering event', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[_reorderEventMutation],
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls mutation to swap events
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
const _swapEvents = useMutation({
|
|
||||||
mutationFn: requestEventSwap,
|
|
||||||
// we optimistically update here
|
|
||||||
onMutate: async ({ from, to }) => {
|
|
||||||
// cancel ongoing queries
|
|
||||||
await queryClient.cancelQueries({ queryKey: RUNDOWN });
|
|
||||||
|
|
||||||
// Snapshot the previous value
|
|
||||||
const previousData = queryClient.getQueryData<RundownCached>(RUNDOWN);
|
|
||||||
if (previousData) {
|
|
||||||
// optimistically update object
|
|
||||||
const newRundown = { ...previousData.rundown };
|
|
||||||
const eventA = previousData.rundown[from];
|
|
||||||
const eventB = previousData.rundown[to];
|
|
||||||
|
|
||||||
if (!isOntimeEvent(eventA) || !isOntimeEvent(eventB)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { newA, newB } = swapEventData(eventA, eventB);
|
|
||||||
newRundown[from] = newA;
|
|
||||||
newRundown[to] = newB;
|
|
||||||
|
|
||||||
queryClient.setQueryData(RUNDOWN, { order: previousData.order, rundown: newRundown, revision: -1 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return a context with the previous events
|
|
||||||
return { previousData };
|
|
||||||
},
|
|
||||||
|
|
||||||
// Mutation fails, rollback undoes optimist update
|
|
||||||
onError: (_error, _eventId, context) => {
|
|
||||||
queryClient.setQueryData(RUNDOWN, context?.previousData);
|
|
||||||
},
|
|
||||||
// Mutation finished, failed or successful
|
|
||||||
// Fetch anyway, just to be sure
|
|
||||||
onSettled: () => {
|
|
||||||
queryClient.invalidateQueries({ queryKey: RUNDOWN });
|
|
||||||
},
|
|
||||||
networkMode: 'always',
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Swaps the schedule of two events
|
|
||||||
*/
|
|
||||||
const swapEvents = useCallback(
|
|
||||||
async ({ from, to }: SwapEntry) => {
|
|
||||||
try {
|
|
||||||
await _swapEvents.mutateAsync({ from, to });
|
|
||||||
} catch (error) {
|
|
||||||
logAxiosError('Error re-ordering event', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[_swapEvents],
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
|
||||||
addEvent,
|
|
||||||
applyDelay,
|
|
||||||
batchUpdateEvents,
|
|
||||||
deleteEvent,
|
|
||||||
deleteAllEvents,
|
|
||||||
getEventById,
|
|
||||||
reorderEvent,
|
|
||||||
swapEvents,
|
|
||||||
updateEvent,
|
|
||||||
updateTimer,
|
|
||||||
updateCustomField,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -2,31 +2,38 @@ import { useEffect, useState } from 'react';
|
|||||||
|
|
||||||
import { throttle } from '../utils/throttle';
|
import { throttle } from '../utils/throttle';
|
||||||
|
|
||||||
|
const inactiveTime = 3000; // 3 seconds
|
||||||
|
|
||||||
export const useFadeOutOnInactivity = () => {
|
/**
|
||||||
const [isMouseMoved, setIsMouseMoved] = useState(false);
|
* Provides whether there has been mouse movement in the page in the last <inactiveTime>
|
||||||
|
*/
|
||||||
|
export const useFadeOutOnInactivity = (initialState = false) => {
|
||||||
|
const [isUserActive, setIsUserActive] = useState(initialState);
|
||||||
|
|
||||||
// show on mouse move
|
// show on mouse move
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let fadeOut: NodeJS.Timeout | null = null;
|
let fadeOut: NodeJS.Timeout | null = null;
|
||||||
const setShowMenuTrue = () => {
|
const setShowMenuTrue = () => {
|
||||||
setIsMouseMoved(true);
|
setIsUserActive(true);
|
||||||
if (fadeOut) {
|
if (fadeOut) {
|
||||||
clearTimeout(fadeOut);
|
clearTimeout(fadeOut);
|
||||||
}
|
}
|
||||||
fadeOut = setTimeout(() => setIsMouseMoved(false), 3000);
|
fadeOut = setTimeout(() => setIsUserActive(false), inactiveTime);
|
||||||
};
|
};
|
||||||
|
|
||||||
const throttledShowMenu = throttle(setShowMenuTrue, 1000);
|
const throttledShowMenu = throttle(setShowMenuTrue, 1000);
|
||||||
|
|
||||||
document.addEventListener('mousemove', throttledShowMenu);
|
document.addEventListener('mousemove', throttledShowMenu);
|
||||||
|
document.addEventListener('keydown', throttledShowMenu);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener('mousemove', throttledShowMenu);
|
document.removeEventListener('mousemove', throttledShowMenu);
|
||||||
|
document.removeEventListener('keydown', throttledShowMenu);
|
||||||
if (fadeOut) {
|
if (fadeOut) {
|
||||||
clearTimeout(fadeOut);
|
clearTimeout(fadeOut);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return isMouseMoved;
|
return isUserActive;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ type noop = (this: any, ...args: any[]) => any;
|
|||||||
|
|
||||||
type PickFunction<T extends noop> = (this: ThisParameterType<T>, ...args: Parameters<T>) => ReturnType<T>;
|
type PickFunction<T extends noop> = (this: ThisParameterType<T>, ...args: Parameters<T>) => ReturnType<T>;
|
||||||
|
|
||||||
export const isFunction = (value: unknown): value is (...args: any) => any => typeof value === 'function';
|
const isFunction = (value: unknown): value is (...args: any) => any => typeof value === 'function';
|
||||||
|
|
||||||
export default function useMemoisedFn<T extends noop>(fn: T) {
|
export default function useMemoisedFn<T extends noop>(fn: T) {
|
||||||
if (isDev) {
|
if (isDev) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { RuntimeStore, SimpleDirection, SimplePlayback, TimerMessage } from 'ontime-types';
|
import { OffsetMode, RuntimeStore, SimpleDirection, SimplePlayback, TimerMessage } from 'ontime-types';
|
||||||
|
|
||||||
import { useRuntimeStore } from '../stores/runtime';
|
import { useRuntimeStore } from '../stores/runtime';
|
||||||
import { socketSendJson } from '../utils/socket';
|
import { socketSendJson } from '../utils/socket';
|
||||||
@@ -91,14 +91,6 @@ export const setPlayback = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useInfoPanel = createSelector((state: RuntimeStore) => ({
|
|
||||||
eventNow: state.eventNow,
|
|
||||||
eventNext: state.eventNext,
|
|
||||||
playback: state.timer.playback,
|
|
||||||
selectedEventIndex: state.runtime.selectedEventIndex,
|
|
||||||
numEvents: state.runtime.numEvents,
|
|
||||||
}));
|
|
||||||
|
|
||||||
export const useAuxTimerTime = createSelector((state: RuntimeStore) => state.auxtimer1.current);
|
export const useAuxTimerTime = createSelector((state: RuntimeStore) => state.auxtimer1.current);
|
||||||
|
|
||||||
export const useAuxTimerControl = createSelector((state: RuntimeStore) => ({
|
export const useAuxTimerControl = createSelector((state: RuntimeStore) => ({
|
||||||
@@ -145,8 +137,6 @@ export const useProgressData = createSelector((state: RuntimeStore) => ({
|
|||||||
timeDanger: state.eventNow?.timeDanger ?? null,
|
timeDanger: state.eventNow?.timeDanger ?? null,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const setClientName = (newName: string) => socketSendJson('set-client-name', newName);
|
|
||||||
|
|
||||||
export const useRuntimeOverview = createSelector((state: RuntimeStore) => ({
|
export const useRuntimeOverview = createSelector((state: RuntimeStore) => ({
|
||||||
plannedStart: state.runtime.plannedStart,
|
plannedStart: state.runtime.plannedStart,
|
||||||
actualStart: state.runtime.actualStart,
|
actualStart: state.runtime.actualStart,
|
||||||
@@ -160,7 +150,7 @@ export const useRuntimePlaybackOverview = createSelector((state: RuntimeStore) =
|
|||||||
|
|
||||||
numEvents: state.runtime.numEvents,
|
numEvents: state.runtime.numEvents,
|
||||||
selectedEventIndex: state.runtime.selectedEventIndex,
|
selectedEventIndex: state.runtime.selectedEventIndex,
|
||||||
offset: state.runtime.offset,
|
offset: state.runtime.offsetMode === OffsetMode.Absolute ? state.runtime.offset : state.runtime.relativeOffset,
|
||||||
|
|
||||||
currentBlock: state.currentBlock,
|
currentBlock: state.currentBlock,
|
||||||
}));
|
}));
|
||||||
@@ -172,8 +162,15 @@ export const useTimelineStatus = createSelector((state: RuntimeStore) => ({
|
|||||||
|
|
||||||
export const useTimeUntilData = createSelector((state: RuntimeStore) => ({
|
export const useTimeUntilData = createSelector((state: RuntimeStore) => ({
|
||||||
clock: state.clock,
|
clock: state.clock,
|
||||||
offset: state.runtime.offset,
|
offset: state.runtime.offsetMode === OffsetMode.Absolute ? state.runtime.offset : state.runtime.relativeOffset,
|
||||||
currentDay: state.eventNow?.dayOffset ?? 0, //The day of the currently running event
|
offsetMode: state.runtime.offsetMode,
|
||||||
|
currentDay: state.eventNow?.dayOffset ?? 0,
|
||||||
|
actualStart: state.runtime.actualStart,
|
||||||
|
plannedStart: state.runtime.plannedStart,
|
||||||
|
}));
|
||||||
|
|
||||||
|
export const useCurrentDay = createSelector((state: RuntimeStore) => ({
|
||||||
|
currentDay: state.eventNow?.dayOffset ?? 0,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const useRuntimeOffset = createSelector((state: RuntimeStore) => ({
|
export const useRuntimeOffset = createSelector((state: RuntimeStore) => ({
|
||||||
@@ -189,6 +186,12 @@ export const useIsOnline = createSelector((state: RuntimeStore) => ({
|
|||||||
isOnline: state.ping > 0,
|
isOnline: state.ping > 0,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
export const useOffsetMode = createSelector((state: RuntimeStore) => ({
|
||||||
|
offsetMode: state.runtime.offsetMode,
|
||||||
|
}));
|
||||||
|
|
||||||
|
export const setOffsetMode = (payload: OffsetMode) => socketSendJson('offsetmode', payload);
|
||||||
|
|
||||||
export const usePlayback = () => {
|
export const usePlayback = () => {
|
||||||
const featureSelector = (state: RuntimeStore) => ({
|
const featureSelector = (state: RuntimeStore) => ({
|
||||||
playback: state.timer.playback,
|
playback: state.timer.playback,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { GetInfo } from 'ontime-types';
|
|||||||
|
|
||||||
export const ontimePlaceholderInfo: GetInfo = {
|
export const ontimePlaceholderInfo: GetInfo = {
|
||||||
networkInterfaces: [],
|
networkInterfaces: [],
|
||||||
version: '2.0.0',
|
version: '4.0.0',
|
||||||
serverPort: 4001,
|
serverPort: 4001,
|
||||||
publicDir: '',
|
publicDir: '',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import { Settings } from 'ontime-types';
|
import { Settings } from 'ontime-types';
|
||||||
|
|
||||||
export const ontimePlaceholderSettings: Settings = {
|
export const ontimePlaceholderSettings: Settings = {
|
||||||
app: 'ontime',
|
version: '4.0.0',
|
||||||
version: '2.0.0',
|
|
||||||
serverPort: 4001,
|
serverPort: 4001,
|
||||||
editorKey: null,
|
editorKey: null,
|
||||||
operatorKey: null,
|
operatorKey: null,
|
||||||
|
|||||||
@@ -8,4 +8,5 @@ export const projectDataPlaceholder: ProjectData = {
|
|||||||
backstageUrl: '',
|
backstageUrl: '',
|
||||||
backstageInfo: '',
|
backstageInfo: '',
|
||||||
projectLogo: null,
|
projectLogo: null,
|
||||||
|
custom: [],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,20 @@
|
|||||||
import { QueryClient } from '@tanstack/react-query';
|
import { QueryClient } from '@tanstack/react-query';
|
||||||
|
|
||||||
|
import { isOntimeCloud } from '../externals';
|
||||||
|
|
||||||
export const ontimeQueryClient = new QueryClient({
|
export const ontimeQueryClient = new QueryClient({
|
||||||
defaultOptions: {
|
defaultOptions: {
|
||||||
queries: {
|
queries: {
|
||||||
gcTime: 1000 * 60 * 10, // 10 min
|
gcTime: 1000 * 60 * 10, // 10 min
|
||||||
},
|
},
|
||||||
|
mutations: {
|
||||||
|
/**
|
||||||
|
* React Query detects whether the client is online
|
||||||
|
* However, web access is not required for the clients when deployed locally
|
||||||
|
* - use 'always' for clients that may be online
|
||||||
|
* - use 'online' for clients that are connected to the cloud
|
||||||
|
*/
|
||||||
|
networkMode: isOntimeCloud ? 'online' : 'always',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ type LogStore = {
|
|||||||
logs: Log[];
|
logs: Log[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const logger = createStore<LogStore>(() => ({
|
const logger = createStore<LogStore>(() => ({
|
||||||
logs: [],
|
logs: [],
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
@@ -14,18 +14,6 @@ export const runtimeStore = createWithEqualityFn<RuntimeStore>(
|
|||||||
export const useRuntimeStore = <T>(selector: (state: RuntimeStore) => T) =>
|
export const useRuntimeStore = <T>(selector: (state: RuntimeStore) => T) =>
|
||||||
useStoreWithEqualityFn(runtimeStore, selector, deepCompare);
|
useStoreWithEqualityFn(runtimeStore, selector, deepCompare);
|
||||||
|
|
||||||
let batchStore: Partial<RuntimeStore> = {};
|
|
||||||
|
|
||||||
export function addToBatchUpdates<K extends keyof RuntimeStore>(key: K, value: RuntimeStore[K]) {
|
|
||||||
batchStore[key] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function flushBatchUpdates() {
|
|
||||||
const state = runtimeStore.getState();
|
|
||||||
runtimeStore.setState({ ...state, ...batchStore });
|
|
||||||
batchStore = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows patching a property of the runtime store
|
* Allows patching a property of the runtime store
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
exports[`cx() > ignores falsy values 1`] = `""`;
|
exports[`cx() > ignores falsy values 1`] = `""`;
|
||||||
|
|
||||||
exports[`cx() > merges styles 1`] = `"_test_98a1e0 _another_98a1e0"`;
|
exports[`cx() > merges styles 1`] = `"_test_d5d33f _another_d5d33f"`;
|
||||||
|
|||||||
+12
-6
@@ -1,12 +1,12 @@
|
|||||||
import { EndAction, EventCustomFields, OntimeEvent, SupportedEvent, TimerType, TimeStrategy } from 'ontime-types';
|
import { EndAction, EntryCustomFields, OntimeEvent, SupportedEntry, TimerType, TimeStrategy } from 'ontime-types';
|
||||||
|
|
||||||
import { cloneEvent } from '../eventsManager';
|
import { cloneEvent } from '../clone';
|
||||||
|
|
||||||
describe('cloneEvent()', () => {
|
describe('cloneEvent()', () => {
|
||||||
it('creates a stem from a given event', () => {
|
it('creates a stem from a given event', () => {
|
||||||
const original: OntimeEvent = {
|
const original: OntimeEvent = {
|
||||||
id: 'unique',
|
id: 'unique',
|
||||||
type: SupportedEvent.Event,
|
type: SupportedEntry.Event,
|
||||||
title: 'title',
|
title: 'title',
|
||||||
cue: 'cue',
|
cue: 'cue',
|
||||||
note: 'note',
|
note: 'note',
|
||||||
@@ -15,7 +15,8 @@ describe('cloneEvent()', () => {
|
|||||||
timeEnd: 10,
|
timeEnd: 10,
|
||||||
timerType: TimerType.CountDown,
|
timerType: TimerType.CountDown,
|
||||||
timeStrategy: TimeStrategy.LockEnd,
|
timeStrategy: TimeStrategy.LockEnd,
|
||||||
linkStart: null,
|
parent: 'test',
|
||||||
|
linkStart: false,
|
||||||
countToEnd: false,
|
countToEnd: false,
|
||||||
endAction: EndAction.None,
|
endAction: EndAction.None,
|
||||||
isPublic: false,
|
isPublic: false,
|
||||||
@@ -27,17 +28,19 @@ describe('cloneEvent()', () => {
|
|||||||
delay: 0,
|
delay: 0,
|
||||||
dayOffset: 0,
|
dayOffset: 0,
|
||||||
gap: 0,
|
gap: 0,
|
||||||
|
triggers: [],
|
||||||
custom: {
|
custom: {
|
||||||
lighting: '3',
|
lighting: '3',
|
||||||
} as EventCustomFields,
|
} as EntryCustomFields,
|
||||||
};
|
};
|
||||||
|
|
||||||
const cloned = cloneEvent(original);
|
const cloned = cloneEvent(original);
|
||||||
expect(cloned).not.toBe(original);
|
expect(cloned).not.toBe(original);
|
||||||
expect(cloned.custom).not.toBe(original.custom);
|
expect(cloned.custom).not.toBe(original.custom);
|
||||||
|
expect(cloned.triggers).not.toBe(original.triggers);
|
||||||
|
|
||||||
expect(cloned).toMatchObject({
|
expect(cloned).toMatchObject({
|
||||||
type: SupportedEvent.Event,
|
type: SupportedEntry.Event,
|
||||||
title: original.title,
|
title: original.title,
|
||||||
note: original.note,
|
note: original.note,
|
||||||
timeStart: original.timeStart,
|
timeStart: original.timeStart,
|
||||||
@@ -45,6 +48,7 @@ describe('cloneEvent()', () => {
|
|||||||
timeEnd: original.timeEnd,
|
timeEnd: original.timeEnd,
|
||||||
timerType: original.timerType,
|
timerType: original.timerType,
|
||||||
timeStrategy: original.timeStrategy,
|
timeStrategy: original.timeStrategy,
|
||||||
|
parent: 'test',
|
||||||
countToEnd: original.countToEnd,
|
countToEnd: original.countToEnd,
|
||||||
linkStart: original.linkStart,
|
linkStart: original.linkStart,
|
||||||
endAction: original.endAction,
|
endAction: original.endAction,
|
||||||
@@ -57,6 +61,8 @@ describe('cloneEvent()', () => {
|
|||||||
gap: 0,
|
gap: 0,
|
||||||
timeWarning: original.timeWarning,
|
timeWarning: original.timeWarning,
|
||||||
timeDanger: original.timeDanger,
|
timeDanger: original.timeDanger,
|
||||||
|
triggers: original.triggers,
|
||||||
|
custom: original.custom,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
import { makeCSVFromArrayOfArrays } from '../csv';
|
import { OntimeEntry, ProjectRundowns, Rundown } from 'ontime-types';
|
||||||
|
|
||||||
|
import { aggregateRundowns, makeCSVFromArrayOfArrays } from '../csv';
|
||||||
|
|
||||||
describe('makeCSVFromArrayOfArrays()', () => {
|
describe('makeCSVFromArrayOfArrays()', () => {
|
||||||
it('joins an array of arrays with commas and newlines', () => {
|
it('joins an array of arrays with commas and newlines', () => {
|
||||||
@@ -11,3 +13,34 @@ after newline,after comma
|
|||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('aggregateRundowns()', () => {
|
||||||
|
it('flattens an object of rundowns into a single array', () => {
|
||||||
|
const rundowns = {
|
||||||
|
first: {
|
||||||
|
id: '',
|
||||||
|
title: '',
|
||||||
|
revision: 0,
|
||||||
|
order: ['1', '2'],
|
||||||
|
flatOrder: ['1', '2'],
|
||||||
|
entries: {
|
||||||
|
'1': { id: '1' } as OntimeEntry,
|
||||||
|
'2': { id: '2' } as OntimeEntry,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
second: {
|
||||||
|
id: '',
|
||||||
|
title: '',
|
||||||
|
revision: 0,
|
||||||
|
order: ['3', '4'],
|
||||||
|
flatOrder: ['3', '4'],
|
||||||
|
entries: {
|
||||||
|
'3': { id: '3' } as OntimeEntry,
|
||||||
|
'4': { id: '4' } as OntimeEntry,
|
||||||
|
},
|
||||||
|
} as Rundown,
|
||||||
|
} as ProjectRundowns;
|
||||||
|
|
||||||
|
expect(aggregateRundowns(rundowns)).toStrictEqual([{ id: '1' }, { id: '2' }, { id: '3' }, { id: '4' }]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import { OffsetMode } from 'ontime-types';
|
||||||
|
import { dayInMs } from 'ontime-utils';
|
||||||
|
|
||||||
import { calculateTimeUntilStart, formatTime, nowInMillis } from '../time';
|
import { calculateTimeUntilStart, formatTime, nowInMillis } from '../time';
|
||||||
|
|
||||||
describe('nowInMillis()', () => {
|
describe('nowInMillis()', () => {
|
||||||
@@ -40,82 +43,255 @@ describe('formatTime()', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('calculateTimeUntilStart()', () => {
|
describe('calculateTimeUntilStart()', () => {
|
||||||
test('ontime', () => {
|
describe('Absolute offset mode', () => {
|
||||||
|
test('ontime', () => {
|
||||||
|
const test = {
|
||||||
|
timeStart: 100,
|
||||||
|
dayOffset: 0,
|
||||||
|
delay: 0,
|
||||||
|
currentDay: 0,
|
||||||
|
totalGap: 0,
|
||||||
|
clock: 90,
|
||||||
|
offset: 0,
|
||||||
|
offsetMode: OffsetMode.Absolute,
|
||||||
|
actualStart: null,
|
||||||
|
plannedStart: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(10);
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: true })).toBe(10);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('running behind', () => {
|
||||||
|
const test = {
|
||||||
|
timeStart: 100,
|
||||||
|
dayOffset: 0,
|
||||||
|
delay: 0,
|
||||||
|
currentDay: 0,
|
||||||
|
totalGap: 0,
|
||||||
|
clock: 90,
|
||||||
|
offset: -20,
|
||||||
|
offsetMode: OffsetMode.Absolute,
|
||||||
|
actualStart: null,
|
||||||
|
plannedStart: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(30);
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: true })).toBe(30);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('running ahead', () => {
|
||||||
|
const test = {
|
||||||
|
timeStart: 100,
|
||||||
|
dayOffset: 0,
|
||||||
|
delay: 0,
|
||||||
|
currentDay: 0,
|
||||||
|
totalGap: 0,
|
||||||
|
clock: 80,
|
||||||
|
offset: 10,
|
||||||
|
offsetMode: OffsetMode.Absolute,
|
||||||
|
actualStart: null,
|
||||||
|
plannedStart: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(20); // <-- when running ahead the unlinked timer stays put
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: true })).toBe(10);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('running behind with enough gaps', () => {
|
||||||
|
const test = {
|
||||||
|
timeStart: 100,
|
||||||
|
dayOffset: 0,
|
||||||
|
delay: 0,
|
||||||
|
currentDay: 0,
|
||||||
|
totalGap: 20,
|
||||||
|
clock: 50,
|
||||||
|
offset: -20,
|
||||||
|
offsetMode: OffsetMode.Absolute,
|
||||||
|
actualStart: null,
|
||||||
|
plannedStart: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(50); // <-- when gap is enough to compensate for the running behind
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: true })).toBe(70); // This should not be possible
|
||||||
|
});
|
||||||
|
|
||||||
|
test('running behind with too little gaps', () => {
|
||||||
|
const test = {
|
||||||
|
timeStart: 100,
|
||||||
|
dayOffset: 0,
|
||||||
|
delay: 0,
|
||||||
|
currentDay: 0,
|
||||||
|
totalGap: 10,
|
||||||
|
clock: 50,
|
||||||
|
offset: -20,
|
||||||
|
offsetMode: OffsetMode.Absolute,
|
||||||
|
actualStart: 0,
|
||||||
|
plannedStart: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(60); // <-- when gap is not enough to compensate for the running behind it absorbs at much as possible
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: true })).toBe(70); // This should not be possible
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Relative offset mode', () => {
|
||||||
|
test('basic function', () => {
|
||||||
|
const test = {
|
||||||
|
timeStart: 0,
|
||||||
|
dayOffset: 0,
|
||||||
|
delay: 0,
|
||||||
|
currentDay: 0,
|
||||||
|
totalGap: 0,
|
||||||
|
clock: 100,
|
||||||
|
actualStart: 100,
|
||||||
|
plannedStart: 0,
|
||||||
|
offset: 0,
|
||||||
|
offsetMode: OffsetMode.Relative,
|
||||||
|
};
|
||||||
|
|
||||||
|
const timeStartEvent2 = 10;
|
||||||
|
const timeStartEvent3 = 20;
|
||||||
|
|
||||||
|
//event 1 is the currently running event
|
||||||
|
|
||||||
|
//event 2
|
||||||
|
expect(calculateTimeUntilStart({ ...test, timeStart: timeStartEvent2, isLinkedToLoaded: true })).toBe(10);
|
||||||
|
expect(calculateTimeUntilStart({ ...test, timeStart: timeStartEvent2, isLinkedToLoaded: false })).toBe(10);
|
||||||
|
|
||||||
|
//event 3
|
||||||
|
expect(calculateTimeUntilStart({ ...test, timeStart: timeStartEvent3, isLinkedToLoaded: true })).toBe(20);
|
||||||
|
expect(calculateTimeUntilStart({ ...test, timeStart: timeStartEvent3, isLinkedToLoaded: false })).toBe(20);
|
||||||
|
|
||||||
|
// When clock advances by 5ms, time until start should decrease by 5ms
|
||||||
|
test.clock = 105;
|
||||||
|
|
||||||
|
//event 2
|
||||||
|
expect(calculateTimeUntilStart({ ...test, timeStart: timeStartEvent2, isLinkedToLoaded: true })).toBe(5);
|
||||||
|
expect(calculateTimeUntilStart({ ...test, timeStart: timeStartEvent2, isLinkedToLoaded: false })).toBe(5);
|
||||||
|
|
||||||
|
//event 3
|
||||||
|
expect(calculateTimeUntilStart({ ...test, timeStart: timeStartEvent3, isLinkedToLoaded: true })).toBe(15);
|
||||||
|
expect(calculateTimeUntilStart({ ...test, timeStart: timeStartEvent3, isLinkedToLoaded: false })).toBe(15);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('gaps', () => {
|
||||||
|
const test = {
|
||||||
|
timeStart: 20,
|
||||||
|
dayOffset: 0,
|
||||||
|
delay: 0,
|
||||||
|
currentDay: 0,
|
||||||
|
totalGap: 10,
|
||||||
|
clock: 100,
|
||||||
|
actualStart: 100,
|
||||||
|
plannedStart: 0,
|
||||||
|
offset: 0,
|
||||||
|
offsetMode: OffsetMode.Relative,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: true })).toBe(20);
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(20);
|
||||||
|
|
||||||
|
// When clock advances by 5ms, time until start should decrease by 5ms
|
||||||
|
test.clock = 105;
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: true })).toBe(15);
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(15);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('added/remove time', () => {
|
||||||
|
const test = {
|
||||||
|
timeStart: 20,
|
||||||
|
dayOffset: 0,
|
||||||
|
delay: 0,
|
||||||
|
currentDay: 0,
|
||||||
|
totalGap: 0,
|
||||||
|
clock: 100,
|
||||||
|
actualStart: 100,
|
||||||
|
plannedStart: 0,
|
||||||
|
offset: 0,
|
||||||
|
offsetMode: OffsetMode.Relative,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: true })).toBe(20);
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(20);
|
||||||
|
|
||||||
|
test.offset = 5; // remove 5 with addtime - we are ahead of time
|
||||||
|
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: true })).toBe(15);
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(20); // unlocked evets will stay on schedule
|
||||||
|
|
||||||
|
test.offset = -5; // add 5 with addtime - we are behind
|
||||||
|
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: true })).toBe(25);
|
||||||
|
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(25);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('next day', () => {
|
||||||
|
const test = {
|
||||||
|
delay: 0,
|
||||||
|
currentDay: 0,
|
||||||
|
clock: 100,
|
||||||
|
actualStart: 100,
|
||||||
|
plannedStart: 0,
|
||||||
|
offset: 0,
|
||||||
|
offsetMode: OffsetMode.Relative,
|
||||||
|
};
|
||||||
|
|
||||||
|
// this event will start the current day
|
||||||
|
expect(
|
||||||
|
calculateTimeUntilStart({
|
||||||
|
...test,
|
||||||
|
timeStart: 10,
|
||||||
|
dayOffset: 0,
|
||||||
|
totalGap: 0,
|
||||||
|
isLinkedToLoaded: false,
|
||||||
|
}),
|
||||||
|
).toBe(10);
|
||||||
|
|
||||||
|
// this event will start the next day
|
||||||
|
// in absolute mode this would start in dayInMs - 100 since the gap would compensate
|
||||||
|
// but in relative mode with and actual start that is 100 offset it starts in dayInMs
|
||||||
|
expect(
|
||||||
|
calculateTimeUntilStart({
|
||||||
|
...test,
|
||||||
|
timeStart: 0,
|
||||||
|
dayOffset: 1,
|
||||||
|
totalGap: dayInMs - 20,
|
||||||
|
isLinkedToLoaded: false,
|
||||||
|
}),
|
||||||
|
).toBe(dayInMs);
|
||||||
|
|
||||||
|
// advancing 100ms
|
||||||
|
test.clock = 200;
|
||||||
|
|
||||||
|
expect(
|
||||||
|
calculateTimeUntilStart({
|
||||||
|
...test,
|
||||||
|
timeStart: 0,
|
||||||
|
dayOffset: 1,
|
||||||
|
totalGap: dayInMs - 20,
|
||||||
|
isLinkedToLoaded: false,
|
||||||
|
}),
|
||||||
|
).toBe(dayInMs - 100);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('overlap with negative total gap', () => {
|
||||||
const test = {
|
const test = {
|
||||||
timeStart: 100,
|
|
||||||
dayOffset: 0,
|
dayOffset: 0,
|
||||||
delay: 0,
|
delay: 0,
|
||||||
currentDay: 0,
|
currentDay: 0,
|
||||||
totalGap: 0,
|
clock: 100,
|
||||||
clock: 90,
|
actualStart: 100,
|
||||||
|
plannedStart: 0,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
|
offsetMode: OffsetMode.Relative,
|
||||||
|
isLinkedToLoaded: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(10);
|
// the overlap will be pushed out to the expected available time
|
||||||
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: true })).toBe(10);
|
expect(calculateTimeUntilStart({ ...test, timeStart: 5, totalGap: -5 })).toBe(10);
|
||||||
|
|
||||||
|
test.clock = 105;
|
||||||
});
|
});
|
||||||
|
|
||||||
test('running behind', () => {
|
|
||||||
const test = {
|
|
||||||
timeStart: 100,
|
|
||||||
dayOffset: 0,
|
|
||||||
delay: 0,
|
|
||||||
currentDay: 0,
|
|
||||||
totalGap: 0,
|
|
||||||
clock: 90,
|
|
||||||
offset: -20,
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(30);
|
|
||||||
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: true })).toBe(30);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('running ahead', () => {
|
|
||||||
const test = {
|
|
||||||
timeStart: 100,
|
|
||||||
dayOffset: 0,
|
|
||||||
delay: 0,
|
|
||||||
currentDay: 0,
|
|
||||||
totalGap: 0,
|
|
||||||
clock: 80,
|
|
||||||
offset: 10,
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(20); // <-- when running ahead the unlinked timer stays put
|
|
||||||
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: true })).toBe(10);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('running behind with enough gaps', () => {
|
|
||||||
const test = {
|
|
||||||
timeStart: 100,
|
|
||||||
dayOffset: 0,
|
|
||||||
delay: 0,
|
|
||||||
currentDay: 0,
|
|
||||||
totalGap: 20,
|
|
||||||
clock: 50,
|
|
||||||
offset: -20,
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(50);
|
|
||||||
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: true })).toBe(70); // This should not be possible
|
|
||||||
});
|
|
||||||
|
|
||||||
test('running behind with to little gaps', () => {
|
|
||||||
const test = {
|
|
||||||
timeStart: 100,
|
|
||||||
dayOffset: 0,
|
|
||||||
delay: 0,
|
|
||||||
currentDay: 0,
|
|
||||||
totalGap: 10,
|
|
||||||
clock: 50,
|
|
||||||
offset: -20,
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: false })).toBe(60);
|
|
||||||
expect(calculateTimeUntilStart({ ...test, isLinkedToLoaded: true })).toBe(70); // This should not be possible
|
|
||||||
});
|
|
||||||
|
|
||||||
//TODO: more indepth testing,
|
|
||||||
// including day offset handling
|
|
||||||
// and more?
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -64,13 +64,13 @@ describe('getRouteFromPreset()', () => {
|
|||||||
describe('handle url sharing edge cases', () => {
|
describe('handle url sharing edge cases', () => {
|
||||||
it('finds the correct preset when the url contains extra arguments', () => {
|
it('finds the correct preset when the url contains extra arguments', () => {
|
||||||
const location = resolvePath('/demopage?locked=true&token=123');
|
const location = resolvePath('/demopage?locked=true&token=123');
|
||||||
expect(getRouteFromPreset(location, presets)?.startsWith('timer?user=guest&alias=demopage')).toBeTruthy()
|
expect(getRouteFromPreset(location, presets)?.startsWith('timer?user=guest&alias=demopage')).toBeTruthy();
|
||||||
})
|
});
|
||||||
|
|
||||||
it('appends the feature params to the alias', () => {
|
it('appends the feature params to the alias', () => {
|
||||||
const location = resolvePath('/demopage?locked=true&token=123');
|
const location = resolvePath('/demopage?locked=true&token=123');
|
||||||
expect(getRouteFromPreset(location, presets)).toBe('timer?user=guest&alias=demopage&locked=true&token=123')
|
expect(getRouteFromPreset(location, presets)).toBe('timer?user=guest&alias=demopage&locked=true&token=123');
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -83,25 +83,26 @@ describe('generatePathFromPreset()', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('appends the feature params to the alias', () => {
|
test('appends the feature params to the alias', () => {
|
||||||
expect(generatePathFromPreset('timer?user=guest', 'demopage', 'true', '123')).toBe('timer?user=guest&alias=demopage&locked=true&token=123');
|
expect(generatePathFromPreset('timer?user=guest', 'demopage', 'true', '123')).toBe(
|
||||||
|
'timer?user=guest&alias=demopage&locked=true&token=123',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('arePathsEquivalent()', () => {
|
describe('arePathsEquivalent()', () => {
|
||||||
it("checks whether the paths match", () => {
|
it('checks whether the paths match', () => {
|
||||||
expect(arePathsEquivalent('demopage', 'timer')).toBeFalsy();
|
expect(arePathsEquivalent('demopage', 'timer')).toBeFalsy();
|
||||||
expect(arePathsEquivalent('timer', 'timer')).toBeTruthy();
|
expect(arePathsEquivalent('timer', 'timer')).toBeTruthy();
|
||||||
expect(arePathsEquivalent('timer?user=guest', 'timer?user=guest')).toBeTruthy();
|
expect(arePathsEquivalent('timer?user=guest', 'timer?user=guest')).toBeTruthy();
|
||||||
})
|
});
|
||||||
|
|
||||||
it("checks whether the params match", () => {
|
it('checks whether the params match', () => {
|
||||||
expect(arePathsEquivalent('timer?test=a', 'timer?test=b')).toBeFalsy();
|
expect(arePathsEquivalent('timer?test=a', 'timer?test=b')).toBeFalsy();
|
||||||
expect(arePathsEquivalent('timer?test=a', 'timer?test=a')).toBeTruthy();
|
expect(arePathsEquivalent('timer?test=a', 'timer?test=a')).toBeTruthy();
|
||||||
})
|
});
|
||||||
|
|
||||||
it("considers edge cases for the url sharing feature", () => {
|
it('considers edge cases for the url sharing feature', () => {
|
||||||
expect(arePathsEquivalent('timer?test=a&locked=true=token=123', 'timer?test=b')).toBeFalsy();
|
expect(arePathsEquivalent('timer?test=a&locked=true=token=123', 'timer?test=b')).toBeFalsy();
|
||||||
expect(arePathsEquivalent('timer?test=a&locked=true=token=123', 'timer?test=a')).toBeTruthy();
|
expect(arePathsEquivalent('timer?test=a&locked=true=token=123', 'timer?test=a')).toBeTruthy();
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+5
-3
@@ -1,4 +1,4 @@
|
|||||||
import { OntimeEvent, SupportedEvent } from 'ontime-types';
|
import { OntimeEvent, SupportedEntry } from 'ontime-types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Creates a safe duplicate of an event
|
* @description Creates a safe duplicate of an event
|
||||||
@@ -9,7 +9,7 @@ import { OntimeEvent, SupportedEvent } from 'ontime-types';
|
|||||||
type ClonedEvent = Omit<OntimeEvent, 'id' | 'cue'>;
|
type ClonedEvent = Omit<OntimeEvent, 'id' | 'cue'>;
|
||||||
export const cloneEvent = (event: OntimeEvent): ClonedEvent => {
|
export const cloneEvent = (event: OntimeEvent): ClonedEvent => {
|
||||||
return {
|
return {
|
||||||
type: SupportedEvent.Event,
|
type: SupportedEntry.Event,
|
||||||
title: event.title,
|
title: event.title,
|
||||||
note: event.note,
|
note: event.note,
|
||||||
timeStart: event.timeStart,
|
timeStart: event.timeStart,
|
||||||
@@ -23,12 +23,14 @@ export const cloneEvent = (event: OntimeEvent): ClonedEvent => {
|
|||||||
isPublic: event.isPublic,
|
isPublic: event.isPublic,
|
||||||
skip: event.skip,
|
skip: event.skip,
|
||||||
colour: event.colour,
|
colour: event.colour,
|
||||||
|
parent: event.parent,
|
||||||
revision: 0,
|
revision: 0,
|
||||||
delay: event.delay, // the events will be collocated, so having the same metadata is a good start
|
delay: event.delay, // the events will be collocated, so having the same metadata is a good start
|
||||||
dayOffset: event.dayOffset,
|
dayOffset: event.dayOffset,
|
||||||
gap: 0,
|
gap: 0,
|
||||||
timeWarning: event.timeWarning,
|
timeWarning: event.timeWarning,
|
||||||
timeDanger: event.timeDanger,
|
timeDanger: event.timeDanger,
|
||||||
custom: { ...event.custom },
|
triggers: structuredClone(event.triggers),
|
||||||
|
custom: structuredClone(event.custom),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -1,10 +1,31 @@
|
|||||||
import { stringify } from 'csv-stringify/browser/esm/sync';
|
import { stringify } from 'csv-stringify/browser/esm/sync';
|
||||||
|
import { OntimeEntry, ProjectRundowns } from 'ontime-types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Converts an array of arrays to a CSV file
|
* Converts an array of arrays to a CSV file
|
||||||
* @param {string[][]} arrayOfArrays
|
|
||||||
* @return {string}
|
|
||||||
*/
|
*/
|
||||||
export function makeCSVFromArrayOfArrays(arrayOfArrays: string[][]): string {
|
export function makeCSVFromArrayOfArrays(arrayOfArrays: string[][]): string {
|
||||||
return stringify(arrayOfArrays);
|
return stringify(arrayOfArrays);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receives an object of rundowns, and flattens them into a single, linear rundown
|
||||||
|
* Used for CSV export
|
||||||
|
*/
|
||||||
|
export function aggregateRundowns(rundowns: ProjectRundowns): OntimeEntry[] {
|
||||||
|
const rundownKeys = Object.keys(rundowns);
|
||||||
|
if (rundownKeys.length === 0) return [];
|
||||||
|
const flatRundown: OntimeEntry[] = [];
|
||||||
|
|
||||||
|
for (const key of rundownKeys) {
|
||||||
|
const { order, entries } = rundowns[key];
|
||||||
|
|
||||||
|
for (let i = 0; i < order.length; i++) {
|
||||||
|
const entryId = order[i];
|
||||||
|
const entry = entries[entryId];
|
||||||
|
|
||||||
|
flatRundown.push(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return flatRundown;
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { MaybeString } from 'ontime-types';
|
||||||
|
|
||||||
|
export default function safeParseNumber(value: MaybeString, defaultValue: number = 0): number {
|
||||||
|
if (!value) return defaultValue;
|
||||||
|
const number = Number(value);
|
||||||
|
if (isNaN(number)) return defaultValue;
|
||||||
|
return number;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Log, RundownCached, RuntimeStore } from 'ontime-types';
|
import { Log, Rundown, RuntimeStore } from 'ontime-types';
|
||||||
|
|
||||||
import { isProduction, websocketUrl } from '../../externals';
|
import { isProduction, websocketUrl } from '../../externals';
|
||||||
import { CLIENT_LIST, CUSTOM_FIELDS, REPORT, RUNDOWN, RUNTIME } from '../api/constants';
|
import { CLIENT_LIST, CUSTOM_FIELDS, REPORT, RUNDOWN, RUNTIME } from '../api/constants';
|
||||||
@@ -14,13 +14,12 @@ import {
|
|||||||
} from '../stores/clientStore';
|
} from '../stores/clientStore';
|
||||||
import { addDialog } from '../stores/dialogStore';
|
import { addDialog } from '../stores/dialogStore';
|
||||||
import { addLog } from '../stores/logger';
|
import { addLog } from '../stores/logger';
|
||||||
import { addToBatchUpdates, flushBatchUpdates, patchRuntime, patchRuntimeProperty } from '../stores/runtime';
|
import { patchRuntime, patchRuntimeProperty } from '../stores/runtime';
|
||||||
|
|
||||||
export let websocket: WebSocket | null = null;
|
let websocket: WebSocket | null = null;
|
||||||
let reconnectTimeout: NodeJS.Timeout | null = null;
|
let reconnectTimeout: NodeJS.Timeout | null = null;
|
||||||
const reconnectInterval = 1000;
|
const reconnectInterval = 1000;
|
||||||
|
|
||||||
export let shouldReconnect = true;
|
|
||||||
export let hasConnected = false;
|
export let hasConnected = false;
|
||||||
export let reconnectAttempts = 0;
|
export let reconnectAttempts = 0;
|
||||||
|
|
||||||
@@ -48,17 +47,18 @@ export const connectSocket = () => {
|
|||||||
|
|
||||||
websocket.onclose = () => {
|
websocket.onclose = () => {
|
||||||
console.warn('WebSocket disconnected');
|
console.warn('WebSocket disconnected');
|
||||||
setOnlineStatus(false);
|
|
||||||
|
|
||||||
if (shouldReconnect) {
|
// we decide to allows reconnect
|
||||||
reconnectTimeout = setTimeout(() => {
|
reconnectTimeout = setTimeout(() => {
|
||||||
console.warn('WebSocket: attempting reconnect');
|
if (reconnectAttempts > 2) {
|
||||||
if (websocket && websocket.readyState === WebSocket.CLOSED) {
|
setOnlineStatus(false);
|
||||||
reconnectAttempts += 1;
|
}
|
||||||
connectSocket();
|
console.warn('WebSocket: attempting reconnect');
|
||||||
}
|
if (websocket && websocket.readyState === WebSocket.CLOSED) {
|
||||||
}, reconnectInterval);
|
reconnectAttempts += 1;
|
||||||
}
|
connectSocket();
|
||||||
|
}
|
||||||
|
}, reconnectInterval);
|
||||||
};
|
};
|
||||||
|
|
||||||
websocket.onerror = (error) => {
|
websocket.onerror = (error) => {
|
||||||
@@ -141,59 +141,10 @@ export const connectSocket = () => {
|
|||||||
updateDevTools(serverPayload);
|
updateDevTools(serverPayload);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'ontime-clock': {
|
case 'ontime-patch': {
|
||||||
addToBatchUpdates('clock', payload);
|
const patch = payload as Partial<RuntimeStore>;
|
||||||
updateDevTools({ clock: payload });
|
patchRuntime(patch);
|
||||||
break;
|
updateDevTools(patch);
|
||||||
}
|
|
||||||
case 'ontime-timer': {
|
|
||||||
addToBatchUpdates('timer', payload);
|
|
||||||
updateDevTools({ timer: payload });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'ontime-onAir': {
|
|
||||||
addToBatchUpdates('onAir', payload);
|
|
||||||
updateDevTools({ onAir: payload });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'ontime-message': {
|
|
||||||
addToBatchUpdates('message', payload);
|
|
||||||
updateDevTools({ message: payload });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'ontime-runtime': {
|
|
||||||
addToBatchUpdates('runtime', payload);
|
|
||||||
updateDevTools({ runtime: payload });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'ontime-eventNow': {
|
|
||||||
addToBatchUpdates('eventNow', payload);
|
|
||||||
updateDevTools({ eventNow: payload });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'ontime-currentBlock': {
|
|
||||||
addToBatchUpdates('currentBlock', payload);
|
|
||||||
updateDevTools({ currentBlock: payload });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'ontime-publicEventNow': {
|
|
||||||
addToBatchUpdates('publicEventNow', payload);
|
|
||||||
updateDevTools({ publicEventNow: payload });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'ontime-eventNext': {
|
|
||||||
addToBatchUpdates('eventNext', payload);
|
|
||||||
updateDevTools({ eventNext: payload });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'ontime-publicEventNext': {
|
|
||||||
addToBatchUpdates('publicEventNext', payload);
|
|
||||||
updateDevTools({ publicEventNext: payload });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'ontime-auxtimer1': {
|
|
||||||
addToBatchUpdates('auxtimer1', payload);
|
|
||||||
updateDevTools({ auxtimer1: payload });
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'ontime-refetch': {
|
case 'ontime-refetch': {
|
||||||
@@ -203,7 +154,7 @@ export const connectSocket = () => {
|
|||||||
invalidateAllCaches();
|
invalidateAllCaches();
|
||||||
} else if (target === 'RUNDOWN') {
|
} else if (target === 'RUNDOWN') {
|
||||||
const { revision } = payload;
|
const { revision } = payload;
|
||||||
const currentRevision = ontimeQueryClient.getQueryData<RundownCached>(RUNDOWN)?.revision ?? -1;
|
const currentRevision = ontimeQueryClient.getQueryData<Rundown>(RUNDOWN)?.revision ?? -1;
|
||||||
if (revision > currentRevision) {
|
if (revision > currentRevision) {
|
||||||
ontimeQueryClient.invalidateQueries({ queryKey: RUNDOWN });
|
ontimeQueryClient.invalidateQueries({ queryKey: RUNDOWN });
|
||||||
ontimeQueryClient.invalidateQueries({ queryKey: CUSTOM_FIELDS });
|
ontimeQueryClient.invalidateQueries({ queryKey: CUSTOM_FIELDS });
|
||||||
@@ -213,8 +164,8 @@ export const connectSocket = () => {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'ontime-flush': {
|
default: {
|
||||||
flushBatchUpdates();
|
console.log('unknown WS message', type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -224,11 +175,6 @@ export const connectSocket = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const disconnectSocket = () => {
|
|
||||||
shouldReconnect = false;
|
|
||||||
websocket?.close();
|
|
||||||
};
|
|
||||||
|
|
||||||
export const socketSend = (message: any) => {
|
export const socketSend = (message: any) => {
|
||||||
if (websocket && websocket.readyState === WebSocket.OPEN) {
|
if (websocket && websocket.readyState === WebSocket.OPEN) {
|
||||||
websocket.send(message);
|
websocket.send(message);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { MaybeNumber, OntimeEvent, Settings, TimeFormat } from 'ontime-types';
|
import { MaybeNumber, OffsetMode, OntimeEvent, Settings, TimeFormat } from 'ontime-types';
|
||||||
import { dayInMs, formatFromMillis, MILLIS_PER_HOUR, MILLIS_PER_MINUTE, MILLIS_PER_SECOND } from 'ontime-utils';
|
import { dayInMs, formatFromMillis, MILLIS_PER_HOUR, MILLIS_PER_MINUTE, MILLIS_PER_SECOND } from 'ontime-utils';
|
||||||
|
|
||||||
import { FORMAT_12, FORMAT_24 } from '../../viewerConfig';
|
import { FORMAT_12, FORMAT_24 } from '../../viewerConfig';
|
||||||
@@ -35,7 +35,7 @@ function getFormatFromParams() {
|
|||||||
* Gets the format options from the applicaton settings
|
* Gets the format options from the applicaton settings
|
||||||
* @returns a string equivalent to the format, ie: hh:mm:ss a or HH:mm:ss
|
* @returns a string equivalent to the format, ie: hh:mm:ss a or HH:mm:ss
|
||||||
*/
|
*/
|
||||||
export function getFormatFromSettings(): TimeFormat {
|
function getFormatFromSettings(): TimeFormat {
|
||||||
const settings: Settings | undefined = ontimeQueryClient.getQueryData(APP_SETTINGS);
|
const settings: Settings | undefined = ontimeQueryClient.getQueryData(APP_SETTINGS);
|
||||||
return settings?.timeFormat ?? '24';
|
return settings?.timeFormat ?? '24';
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ export function formatDuration(duration: number, hideSeconds = true): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!hideSeconds) {
|
if (!hideSeconds) {
|
||||||
const seconds = Math.floor((duration % MILLIS_PER_MINUTE) / MILLIS_PER_SECOND);
|
const seconds = Math.ceil((duration % MILLIS_PER_MINUTE) / MILLIS_PER_SECOND);
|
||||||
if (seconds > 0) {
|
if (seconds > 0) {
|
||||||
result += `${seconds}s`;
|
result += `${seconds}s`;
|
||||||
}
|
}
|
||||||
@@ -140,8 +140,8 @@ export function useTimeUntilStart(
|
|||||||
isLinkedToLoaded: boolean;
|
isLinkedToLoaded: boolean;
|
||||||
},
|
},
|
||||||
): number {
|
): number {
|
||||||
const { offset, clock, currentDay } = useTimeUntilData();
|
const { offset, clock, currentDay, offsetMode, actualStart, plannedStart } = useTimeUntilData();
|
||||||
return calculateTimeUntilStart({ ...data, currentDay, clock, offset });
|
return calculateTimeUntilStart({ ...data, currentDay, clock, offset, offsetMode, actualStart, plannedStart });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -160,9 +160,24 @@ export function calculateTimeUntilStart(
|
|||||||
isLinkedToLoaded: boolean;
|
isLinkedToLoaded: boolean;
|
||||||
clock: number;
|
clock: number;
|
||||||
offset: number;
|
offset: number;
|
||||||
|
offsetMode: OffsetMode;
|
||||||
|
actualStart: MaybeNumber;
|
||||||
|
plannedStart: MaybeNumber;
|
||||||
},
|
},
|
||||||
): number {
|
): number {
|
||||||
const { timeStart, dayOffset, currentDay, totalGap, isLinkedToLoaded, clock, offset, delay } = data;
|
const {
|
||||||
|
timeStart,
|
||||||
|
dayOffset,
|
||||||
|
currentDay,
|
||||||
|
totalGap,
|
||||||
|
isLinkedToLoaded,
|
||||||
|
clock,
|
||||||
|
offset,
|
||||||
|
delay,
|
||||||
|
offsetMode,
|
||||||
|
actualStart,
|
||||||
|
plannedStart,
|
||||||
|
} = data;
|
||||||
|
|
||||||
//How many days from the currently running event to this one
|
//How many days from the currently running event to this one
|
||||||
const relativeDayOffset = dayOffset - currentDay;
|
const relativeDayOffset = dayOffset - currentDay;
|
||||||
@@ -172,20 +187,23 @@ export function calculateTimeUntilStart(
|
|||||||
//The normalised start time of this event relative to the currently running event
|
//The normalised start time of this event relative to the currently running event
|
||||||
const normalisedTimeStart = delayedStart + relativeDayOffset * dayInMs;
|
const normalisedTimeStart = delayedStart + relativeDayOffset * dayInMs;
|
||||||
|
|
||||||
const offsetTimestart = normalisedTimeStart - offset;
|
let relativeStartOffset = 0;
|
||||||
const offsetTimeUntil = offsetTimestart - clock;
|
|
||||||
|
if (offsetMode === OffsetMode.Relative) {
|
||||||
|
relativeStartOffset = (actualStart ?? 0) - (plannedStart ?? 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
const scheduledTimeUntil = normalisedTimeStart - clock + relativeStartOffset;
|
||||||
|
|
||||||
|
const offsetTimeUntil = scheduledTimeUntil - offset;
|
||||||
|
|
||||||
if (isLinkedToLoaded) {
|
if (isLinkedToLoaded) {
|
||||||
//if we are directly linked back to the loaded event we just follow the offset
|
//if we are directly linked back to the loaded event we just follow the offset
|
||||||
return offsetTimeUntil;
|
return offsetTimeUntil;
|
||||||
}
|
}
|
||||||
|
|
||||||
const scheduledTimeUntil = normalisedTimeStart - clock;
|
const gapsCanCompensateForOffset = totalGap + offset >= 0;
|
||||||
|
if (gapsCanCompensateForOffset) {
|
||||||
const isAheadOfSchedule = offset >= 0;
|
|
||||||
const gapsCanCompensadeForOffset = totalGap + offset >= 0;
|
|
||||||
|
|
||||||
if (isAheadOfSchedule || gapsCanCompensadeForOffset) {
|
|
||||||
// if we are ahead of schedule or the gap can compensate for the amount we are behind then expect to start at the scheduled time
|
// if we are ahead of schedule or the gap can compensate for the amount we are behind then expect to start at the scheduled time
|
||||||
return scheduledTimeUntil;
|
return scheduledTimeUntil;
|
||||||
}
|
}
|
||||||
|
|||||||
-11
@@ -1,11 +0,0 @@
|
|||||||
import { TestingLibraryMatchers } from '@testing-library/jest-dom/matchers';
|
|
||||||
|
|
||||||
import 'vitest';
|
|
||||||
|
|
||||||
// ugly hack because vite and pnpm are not playing ball with jest
|
|
||||||
// https://github.com/testing-library/jest-dom/issues/123
|
|
||||||
declare global {
|
|
||||||
namespace Vi {
|
|
||||||
type Assertion<T = any> = TestingLibraryMatchers<T, void>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -49,10 +49,7 @@ function resolveUrl(protocol: 'http' | 'ws', path: string) {
|
|||||||
url.pathname = baseURI ? `${baseURI}/${path}` : path;
|
url.pathname = baseURI ? `${baseURI}/${path}` : path;
|
||||||
|
|
||||||
// in development mode, we use the React port for UI, but need the requests to target the server
|
// in development mode, we use the React port for UI, but need the requests to target the server
|
||||||
if (isDev) {
|
// this is done with a proxy in the vite config to avoid CORS issues in the dev environment
|
||||||
// this is used as a fallback port for development
|
|
||||||
url.port = '4001';
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = url.toString();
|
const result = url.toString();
|
||||||
|
|
||||||
|
|||||||
@@ -207,6 +207,9 @@ $inner-padding: 1rem;
|
|||||||
&.end {
|
&.end {
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
|
&.apart {
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes animloader {
|
@keyframes animloader {
|
||||||
|
|||||||
@@ -113,8 +113,8 @@ export function BlockQuote({ children }: { children: ReactNode }) {
|
|||||||
return <blockquote className={style.blockquote}>{children}</blockquote>;
|
return <blockquote className={style.blockquote}>{children}</blockquote>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Error({ children }: { children: ReactNode }) {
|
export function Error({ children, className }: { children: ReactNode } & JSX.IntrinsicElements['div']) {
|
||||||
return <div className={style.fieldError}>{children}</div>;
|
return <div className={cx([style.fieldError, className])}>{children}</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Divider() {
|
export function Divider() {
|
||||||
@@ -136,7 +136,7 @@ type AllowedInlineTags = 'div' | 'td';
|
|||||||
type InlineProps<C extends AllowedInlineTags> = {
|
type InlineProps<C extends AllowedInlineTags> = {
|
||||||
as?: C;
|
as?: C;
|
||||||
relation?: 'inner' | 'component' | 'section';
|
relation?: 'inner' | 'component' | 'section';
|
||||||
align?: 'start' | 'end';
|
align?: 'start' | 'end' | 'apart';
|
||||||
className?: string;
|
className?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -29,8 +29,8 @@ export default function ReportSettings() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const combinedReport = useMemo(() => {
|
const combinedReport = useMemo(() => {
|
||||||
return getCombinedReport(reportData, data.rundown, data.order);
|
return getCombinedReport(reportData, data.entries, data.order);
|
||||||
}, [reportData, data.rundown, data.order]);
|
}, [reportData, data.entries, data.order]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Panel.Section>
|
<Panel.Section>
|
||||||
|
|||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { IoPencil, IoTrash } from 'react-icons/io5';
|
import { IoPencil, IoTrash } from 'react-icons/io5';
|
||||||
import { IconButton } from '@chakra-ui/react';
|
import { IconButton } from '@chakra-ui/react';
|
||||||
import { CustomField, CustomFieldLabel } from 'ontime-types';
|
import { CustomField, CustomFieldKey } from 'ontime-types';
|
||||||
|
|
||||||
import CopyTag from '../../../../../common/components/copy-tag/CopyTag';
|
import CopyTag from '../../../../../common/components/copy-tag/CopyTag';
|
||||||
import Swatch from '../../../../../common/components/input/colour-input/Swatch';
|
import Swatch from '../../../../../common/components/input/colour-input/Swatch';
|
||||||
@@ -17,8 +17,8 @@ interface CustomFieldEntryProps {
|
|||||||
label: string;
|
label: string;
|
||||||
fieldKey: string;
|
fieldKey: string;
|
||||||
type: 'string' | 'image';
|
type: 'string' | 'image';
|
||||||
onEdit: (label: CustomFieldLabel, patch: CustomField) => Promise<void>;
|
onEdit: (key: CustomFieldKey, patch: CustomField) => Promise<void>;
|
||||||
onDelete: (label: CustomFieldLabel) => Promise<void>;
|
onDelete: (key: CustomFieldKey) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function CustomFieldEntry(props: CustomFieldEntryProps) {
|
export default function CustomFieldEntry(props: CustomFieldEntryProps) {
|
||||||
|
|||||||
+5
-5
@@ -1,7 +1,7 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { IoAdd } from 'react-icons/io5';
|
import { IoAdd } from 'react-icons/io5';
|
||||||
import { Button } from '@chakra-ui/react';
|
import { Button } from '@chakra-ui/react';
|
||||||
import { CustomField, CustomFieldLabel } from 'ontime-types';
|
import { CustomField, CustomFieldKey } from 'ontime-types';
|
||||||
|
|
||||||
import { deleteCustomField, editCustomField, postCustomField } from '../../../../../common/api/customFields';
|
import { deleteCustomField, editCustomField, postCustomField } from '../../../../../common/api/customFields';
|
||||||
import Info from '../../../../../common/components/info/Info';
|
import Info from '../../../../../common/components/info/Info';
|
||||||
@@ -31,14 +31,14 @@ export default function CustomFields() {
|
|||||||
setIsAdding(false);
|
setIsAdding(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEditField = async (label: CustomFieldLabel, customField: CustomField) => {
|
const handleEditField = async (key: CustomFieldKey, customField: CustomField) => {
|
||||||
await editCustomField(label, customField);
|
await editCustomField(key, customField);
|
||||||
refetch();
|
refetch();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDelete = async (label: string) => {
|
const handleDelete = async (key: CustomFieldKey) => {
|
||||||
try {
|
try {
|
||||||
await deleteCustomField(label);
|
await deleteCustomField(key);
|
||||||
refetch();
|
refetch();
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
/** we do not handle errors here */
|
/** we do not handle errors here */
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
import { isOntimeEvent, MaybeNumber, NormalisedRundown, OntimeReport } from 'ontime-types';
|
import { EntryId, isOntimeEvent, MaybeNumber, OntimeReport, RundownEntries } from 'ontime-types';
|
||||||
|
|
||||||
import { makeCSVFromArrayOfArrays } from '../../../../common/utils/csv';
|
import { makeCSVFromArrayOfArrays } from '../../../../common/utils/csv';
|
||||||
import { formatTime } from '../../../../common/utils/time';
|
import { formatTime } from '../../../../common/utils/time';
|
||||||
@@ -16,7 +16,7 @@ export type CombinedReport = {
|
|||||||
/**
|
/**
|
||||||
* Creates a combined report with the rundown data
|
* Creates a combined report with the rundown data
|
||||||
*/
|
*/
|
||||||
export function getCombinedReport(report: OntimeReport, rundown: NormalisedRundown, order: string[]): CombinedReport[] {
|
export function getCombinedReport(report: OntimeReport, rundown: RundownEntries, order: EntryId[]): CombinedReport[] {
|
||||||
if (Object.keys(report).length === 0) return [];
|
if (Object.keys(report).length === 0) return [];
|
||||||
if (order.length === 0) return [];
|
if (order.length === 0) return [];
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,6 @@ import * as Panel from '../../panel-utils/PanelUtils';
|
|||||||
|
|
||||||
import GeneralPinInput from './GeneralPinInput';
|
import GeneralPinInput from './GeneralPinInput';
|
||||||
|
|
||||||
export type GeneralPanelFormValues = {
|
|
||||||
filename: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function GeneralPanelForm() {
|
export default function GeneralPanelForm() {
|
||||||
const { data, status, refetch } = useSettings();
|
const { data, status, refetch } = useSettings();
|
||||||
const {
|
const {
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
.wrapper {
|
||||||
|
max-height: 500px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import { forwardRef, memo, useEffect, useImperativeHandle, useState } from 'react';
|
||||||
|
import Editor from 'react-simple-code-editor';
|
||||||
|
import Prism from 'prismjs/components/prism-core';
|
||||||
|
|
||||||
|
import 'prismjs/components/prism-css';
|
||||||
|
import 'prismjs/themes/prism-tomorrow.min.css';
|
||||||
|
import style from './StyleEditor.module.scss';
|
||||||
|
|
||||||
|
interface CodeEditorProps {
|
||||||
|
language: string;
|
||||||
|
initialValue: string;
|
||||||
|
isDirty: boolean;
|
||||||
|
setIsDirty: (value: boolean) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CodeEditor = forwardRef((props: CodeEditorProps, cssRef) => {
|
||||||
|
const { language, initialValue, isDirty, setIsDirty } = props;
|
||||||
|
|
||||||
|
const [code, setCode] = useState(initialValue);
|
||||||
|
|
||||||
|
const highlight = (code: string) => {
|
||||||
|
const grammar = Prism.languages[language];
|
||||||
|
return grammar ? Prism.highlight(code, grammar, language) : code;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChange = (newCode: string) => {
|
||||||
|
setCode(newCode);
|
||||||
|
};
|
||||||
|
|
||||||
|
useImperativeHandle(cssRef, () => {
|
||||||
|
return {
|
||||||
|
getCss: () => code,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// add contents to editor on mount and any change in initialValue
|
||||||
|
useEffect(() => {
|
||||||
|
setCode(initialValue);
|
||||||
|
}, [initialValue]);
|
||||||
|
|
||||||
|
// handle dirty state on change
|
||||||
|
useEffect(() => {
|
||||||
|
if (initialValue.trim() !== code.trim() && !isDirty && code.length !== 0) {
|
||||||
|
setIsDirty(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (initialValue.trim() === code.trim() && isDirty) {
|
||||||
|
setIsDirty(false);
|
||||||
|
}
|
||||||
|
}, [initialValue, code, isDirty, setIsDirty]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={style.wrapper}>
|
||||||
|
<Editor
|
||||||
|
value={code}
|
||||||
|
padding={15}
|
||||||
|
onValueChange={handleChange}
|
||||||
|
highlight={highlight}
|
||||||
|
style={{
|
||||||
|
fontFamily: 'monospace',
|
||||||
|
fontSize: 12,
|
||||||
|
minHeight: 500,
|
||||||
|
background: '#2d2d2d', // Background of tomorrow theme
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
CodeEditor.displayName = 'StyleEditor';
|
||||||
|
|
||||||
|
export default memo(CodeEditor);
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
.editorActions {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.right {
|
||||||
|
align-self: end;
|
||||||
|
text-align: right
|
||||||
|
}
|
||||||
|
|
||||||
|
.column {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
import { lazy, useEffect, useRef, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Modal,
|
||||||
|
ModalBody,
|
||||||
|
ModalCloseButton,
|
||||||
|
ModalContent,
|
||||||
|
ModalFooter,
|
||||||
|
ModalHeader,
|
||||||
|
ModalOverlay,
|
||||||
|
} from '@chakra-ui/react';
|
||||||
|
|
||||||
|
import { getCSSContents, postCSSContents, restoreCSSContents } from '../../../../common/api/assets';
|
||||||
|
import Info from '../../../../common/components/info/Info';
|
||||||
|
import * as Panel from '../../panel-utils/PanelUtils';
|
||||||
|
|
||||||
|
import style from './StyleEditorModal.module.scss';
|
||||||
|
|
||||||
|
const CodeEditor = lazy(() => import('./StyleEditor'));
|
||||||
|
|
||||||
|
interface CodeEditorModalProps {
|
||||||
|
isOpen: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CSSRef {
|
||||||
|
getCss: () => string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function CodeEditorModal(props: CodeEditorModalProps) {
|
||||||
|
const { isOpen, onClose } = props;
|
||||||
|
|
||||||
|
const [css, setCSS] = useState('');
|
||||||
|
const [isDirty, setIsDirty] = useState(false);
|
||||||
|
const [saveLoading, setSaveLoading] = useState(false);
|
||||||
|
const [resetLoading, setResetLoading] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const cssRef = useRef<CSSRef>(null);
|
||||||
|
|
||||||
|
const handleRestore = async () => {
|
||||||
|
try {
|
||||||
|
setResetLoading(true);
|
||||||
|
const defaultCss = await restoreCSSContents();
|
||||||
|
setCSS(defaultCss);
|
||||||
|
} catch (_error) {
|
||||||
|
/** no error handling for now */
|
||||||
|
} finally {
|
||||||
|
setResetLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSave = async () => {
|
||||||
|
try {
|
||||||
|
setSaveLoading(true);
|
||||||
|
if (cssRef.current) {
|
||||||
|
await postCSSContents(cssRef.current.getCss());
|
||||||
|
setCSS(cssRef.current.getCss());
|
||||||
|
setIsDirty(false);
|
||||||
|
}
|
||||||
|
} catch (_error) {
|
||||||
|
/** no error handling for now */
|
||||||
|
} finally {
|
||||||
|
setSaveLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const clear = () => setCSS('');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function fetchServerCSS() {
|
||||||
|
// check for isOpen to fetch recent css
|
||||||
|
if (isOpen) {
|
||||||
|
try {
|
||||||
|
const css = await getCSSContents();
|
||||||
|
setCSS(css);
|
||||||
|
} catch (_error) {
|
||||||
|
setError('Failed to load CSS from server');
|
||||||
|
/** no error handling for now */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fetchServerCSS();
|
||||||
|
}, [isOpen]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal isOpen={isOpen} onClose={onClose} variant='ontime' isCentered>
|
||||||
|
<ModalOverlay />
|
||||||
|
<ModalContent maxWidth='max(800px, 40vw)'>
|
||||||
|
<ModalHeader>Edit CSS override</ModalHeader>
|
||||||
|
<ModalCloseButton />
|
||||||
|
<ModalBody>
|
||||||
|
<CodeEditor ref={cssRef} initialValue={css} language='css' isDirty={isDirty} setIsDirty={setIsDirty} />
|
||||||
|
</ModalBody>
|
||||||
|
|
||||||
|
<ModalFooter className={style.column}>
|
||||||
|
<Info>Invalid CSS will be refused by the browser</Info>
|
||||||
|
{error && <Panel.Error className={style.right}>{`Error: ${error}`}</Panel.Error>}
|
||||||
|
<Panel.InlineElements align='apart' className={style.editorActions}>
|
||||||
|
<Button
|
||||||
|
variant='ontime-ghosted'
|
||||||
|
onClick={handleRestore}
|
||||||
|
isDisabled={saveLoading || resetLoading}
|
||||||
|
isLoading={resetLoading}
|
||||||
|
>
|
||||||
|
Reset to example
|
||||||
|
</Button>
|
||||||
|
<Panel.InlineElements>
|
||||||
|
<Button variant='ontime-ghosted' onClick={clear}>
|
||||||
|
Clear
|
||||||
|
</Button>
|
||||||
|
<Button variant='ontime-subtle' onClick={onClose}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant='ontime-filled'
|
||||||
|
onClick={handleSave}
|
||||||
|
isDisabled={saveLoading || resetLoading || !isDirty}
|
||||||
|
isLoading={saveLoading}
|
||||||
|
>
|
||||||
|
Save changes
|
||||||
|
</Button>
|
||||||
|
</Panel.InlineElements>
|
||||||
|
</Panel.InlineElements>
|
||||||
|
</ModalFooter>
|
||||||
|
</ModalContent>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { Controller, useForm } from 'react-hook-form';
|
import { Controller, useForm } from 'react-hook-form';
|
||||||
import { Button, Input, Switch } from '@chakra-ui/react';
|
import { Button, Input, Switch, useDisclosure } from '@chakra-ui/react';
|
||||||
import { ViewSettings } from 'ontime-types';
|
import { ViewSettings } from 'ontime-types';
|
||||||
|
|
||||||
import { maybeAxiosError } from '../../../../common/api/utils';
|
import { maybeAxiosError } from '../../../../common/api/utils';
|
||||||
@@ -14,11 +14,14 @@ import { preventEscape } from '../../../../common/utils/keyEvent';
|
|||||||
import { isOntimeCloud } from '../../../../externals';
|
import { isOntimeCloud } from '../../../../externals';
|
||||||
import * as Panel from '../../panel-utils/PanelUtils';
|
import * as Panel from '../../panel-utils/PanelUtils';
|
||||||
|
|
||||||
|
import CodeEditorModal from './StyleEditorModal';
|
||||||
|
|
||||||
const cssOverrideDocsUrl = 'https://docs.getontime.no/features/custom-styling/';
|
const cssOverrideDocsUrl = 'https://docs.getontime.no/features/custom-styling/';
|
||||||
|
|
||||||
export default function ViewSettingsForm() {
|
export default function ViewSettingsForm() {
|
||||||
const { data, status, refetch } = useViewSettings();
|
const { data, status, refetch } = useViewSettings();
|
||||||
const { data: info, status: infoStatus } = useInfo();
|
const { data: info, status: infoStatus } = useInfo();
|
||||||
|
const { isOpen: isCodeEditorOpen, onOpen: onCodeEditorOpen, onClose: onCodeEditorClose } = useDisclosure();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
control,
|
control,
|
||||||
@@ -103,6 +106,7 @@ export default function ViewSettingsForm() {
|
|||||||
<Panel.Section>
|
<Panel.Section>
|
||||||
<Panel.Loader isLoading={isLoading} />
|
<Panel.Loader isLoading={isLoading} />
|
||||||
<Panel.ListGroup>
|
<Panel.ListGroup>
|
||||||
|
<CodeEditorModal isOpen={isCodeEditorOpen} onClose={onCodeEditorClose} />
|
||||||
<Panel.ListItem>
|
<Panel.ListItem>
|
||||||
<Panel.Field
|
<Panel.Field
|
||||||
title='Override CSS styles'
|
title='Override CSS styles'
|
||||||
@@ -115,6 +119,15 @@ export default function ViewSettingsForm() {
|
|||||||
<Switch variant='ontime' size='lg' isChecked={value} onChange={onChange} ref={ref} />
|
<Switch variant='ontime' size='lg' isChecked={value} onChange={onChange} ref={ref} />
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<Button
|
||||||
|
onClick={onCodeEditorOpen}
|
||||||
|
variant='ontime-subtle'
|
||||||
|
size='sm'
|
||||||
|
isDisabled={isSubmitting}
|
||||||
|
width='fit-content'
|
||||||
|
>
|
||||||
|
Edit CSS override
|
||||||
|
</Button>
|
||||||
</Panel.ListItem>
|
</Panel.ListItem>
|
||||||
</Panel.ListGroup>
|
</Panel.ListGroup>
|
||||||
<Panel.ListGroup>
|
<Panel.ListGroup>
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
declare module 'prismjs/components/prism-core' {
|
||||||
|
export * from 'prismjs';
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module 'prismjs/components/prism-css';
|
||||||
@@ -102,7 +102,6 @@ export default function EditorSettingsForm() {
|
|||||||
onChange={(event) => setDefaultEndAction(event.target.value as EndAction)}
|
onChange={(event) => setDefaultEndAction(event.target.value as EndAction)}
|
||||||
>
|
>
|
||||||
<option value={EndAction.None}>None</option>
|
<option value={EndAction.None}>None</option>
|
||||||
<option value={EndAction.Stop}>Stop</option>
|
|
||||||
<option value={EndAction.LoadNext}>Load next</option>
|
<option value={EndAction.LoadNext}>Load next</option>
|
||||||
<option value={EndAction.PlayNext}>Play next</option>
|
<option value={EndAction.PlayNext}>Play next</option>
|
||||||
</Select>
|
</Select>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useFieldArray, useForm } from 'react-hook-form';
|
||||||
|
import { IoTrash } from 'react-icons/io5';
|
||||||
import { Button, Input, Textarea } from '@chakra-ui/react';
|
import { Button, Input, Textarea } from '@chakra-ui/react';
|
||||||
import { useQueryClient } from '@tanstack/react-query';
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ type ProjectCreateFormValues = {
|
|||||||
publicUrl?: string;
|
publicUrl?: string;
|
||||||
backstageInfo?: string;
|
backstageInfo?: string;
|
||||||
backstageUrl?: string;
|
backstageUrl?: string;
|
||||||
|
custom?: { title: string; value: string }[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function ProjectCreateForm(props: ProjectCreateFromProps) {
|
export default function ProjectCreateForm(props: ProjectCreateFromProps) {
|
||||||
@@ -34,6 +36,7 @@ export default function ProjectCreateForm(props: ProjectCreateFromProps) {
|
|||||||
const {
|
const {
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
register,
|
register,
|
||||||
|
control,
|
||||||
formState: { isSubmitting, isValid },
|
formState: { isSubmitting, isValid },
|
||||||
setFocus,
|
setFocus,
|
||||||
} = useForm<ProjectCreateFormValues>({
|
} = useForm<ProjectCreateFormValues>({
|
||||||
@@ -44,6 +47,11 @@ export default function ProjectCreateForm(props: ProjectCreateFromProps) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { fields, append, remove } = useFieldArray({
|
||||||
|
control,
|
||||||
|
name: 'custom',
|
||||||
|
});
|
||||||
|
|
||||||
// set focus to first field
|
// set focus to first field
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setFocus('title');
|
setFocus('title');
|
||||||
@@ -59,6 +67,7 @@ export default function ProjectCreateForm(props: ProjectCreateFromProps) {
|
|||||||
...values,
|
...values,
|
||||||
filename,
|
filename,
|
||||||
});
|
});
|
||||||
|
|
||||||
await queryClient.invalidateQueries({ queryKey: PROJECT_LIST });
|
await queryClient.invalidateQueries({ queryKey: PROJECT_LIST });
|
||||||
onClose();
|
onClose();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -66,6 +75,10 @@ export default function ProjectCreateForm(props: ProjectCreateFromProps) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleAddCustom = () => {
|
||||||
|
append({ title: '', value: '' });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Panel.Section
|
<Panel.Section
|
||||||
as='form'
|
as='form'
|
||||||
@@ -151,6 +164,42 @@ export default function ProjectCreateForm(props: ProjectCreateFromProps) {
|
|||||||
{...register('backstageUrl')}
|
{...register('backstageUrl')}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
<Panel.Section>
|
||||||
|
<Panel.ListItem>
|
||||||
|
<Panel.Field title='Custom data' description='Add custom data for your project' />
|
||||||
|
<Button variant='ontime-subtle' onClick={handleAddCustom}>
|
||||||
|
+
|
||||||
|
</Button>
|
||||||
|
</Panel.ListItem>
|
||||||
|
{fields.map((field, idx) => (
|
||||||
|
<div key={field.id} className={style.customDataItem}>
|
||||||
|
<Panel.Paragraph>{idx + 1}.</Panel.Paragraph>
|
||||||
|
<label>
|
||||||
|
Title
|
||||||
|
<Input
|
||||||
|
variant='ontime-filled'
|
||||||
|
size='sm'
|
||||||
|
placeholder={field.title}
|
||||||
|
autoComplete='off'
|
||||||
|
{...register(`custom.${idx}.title` as const)}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
Value
|
||||||
|
<Input
|
||||||
|
variant='ontime-filled'
|
||||||
|
size='sm'
|
||||||
|
placeholder={field.value}
|
||||||
|
autoComplete='off'
|
||||||
|
{...register(`custom.${idx}.value` as const)}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<Button variant='ontime-ghosted' onClick={() => remove(idx)}>
|
||||||
|
<IoTrash />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</Panel.Section>
|
||||||
</Panel.Section>
|
</Panel.Section>
|
||||||
</Panel.Section>
|
</Panel.Section>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { ChangeEvent, useEffect, useRef } from 'react';
|
import { ChangeEvent, useEffect, useRef } from 'react';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useFieldArray, useForm } from 'react-hook-form';
|
||||||
import { IoDownloadOutline, IoTrash } from 'react-icons/io5';
|
import { IoAdd, IoDownloadOutline, IoTrash } from 'react-icons/io5';
|
||||||
import { Button, Input, Textarea } from '@chakra-ui/react';
|
import { Button, Input, Textarea } from '@chakra-ui/react';
|
||||||
import { type ProjectData } from 'ontime-types';
|
import { type ProjectData } from 'ontime-types';
|
||||||
|
|
||||||
@@ -25,6 +25,7 @@ export default function ProjectData() {
|
|||||||
formState: { isSubmitting, isValid, isDirty, errors },
|
formState: { isSubmitting, isValid, isDirty, errors },
|
||||||
setError,
|
setError,
|
||||||
watch,
|
watch,
|
||||||
|
control,
|
||||||
setValue,
|
setValue,
|
||||||
} = useForm({
|
} = useForm({
|
||||||
defaultValues: data,
|
defaultValues: data,
|
||||||
@@ -32,6 +33,12 @@ export default function ProjectData() {
|
|||||||
resetOptions: {
|
resetOptions: {
|
||||||
keepDirtyValues: true,
|
keepDirtyValues: true,
|
||||||
},
|
},
|
||||||
|
mode: 'onChange',
|
||||||
|
});
|
||||||
|
|
||||||
|
const { fields, append, remove } = useFieldArray({
|
||||||
|
control,
|
||||||
|
name: 'custom',
|
||||||
});
|
});
|
||||||
|
|
||||||
// reset form values if data changes
|
// reset form values if data changes
|
||||||
@@ -77,6 +84,10 @@ export default function ProjectData() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleAddCustom = () => {
|
||||||
|
append({ title: '', value: '' });
|
||||||
|
};
|
||||||
|
|
||||||
const onSubmit = async (formData: ProjectData) => {
|
const onSubmit = async (formData: ProjectData) => {
|
||||||
try {
|
try {
|
||||||
await postProjectData(formData);
|
await postProjectData(formData);
|
||||||
@@ -231,6 +242,69 @@ export default function ProjectData() {
|
|||||||
{...register('backstageUrl')}
|
{...register('backstageUrl')}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
<Panel.Section style={{ marginTop: 0 }}>
|
||||||
|
<Panel.ListItem>
|
||||||
|
<Panel.Field title='Custom data' description='' />
|
||||||
|
<Button leftIcon={<IoAdd />} size='sm' variant='ontime-subtle' onClick={handleAddCustom}>
|
||||||
|
Add
|
||||||
|
</Button>
|
||||||
|
</Panel.ListItem>
|
||||||
|
{fields.length > 0 &&
|
||||||
|
fields.map((field, idx) => {
|
||||||
|
const rowErrors = errors.custom?.[idx] as
|
||||||
|
| {
|
||||||
|
title?: { message?: string };
|
||||||
|
value?: { message?: string };
|
||||||
|
}
|
||||||
|
| undefined;
|
||||||
|
return (
|
||||||
|
<div key={field.id} className={style.customDataItem}>
|
||||||
|
<div>
|
||||||
|
<div className={style.titleRow}>
|
||||||
|
<label>
|
||||||
|
Title
|
||||||
|
<Input
|
||||||
|
variant='ontime-filled'
|
||||||
|
size='sm'
|
||||||
|
defaultValue={field.title}
|
||||||
|
placeholder='Title of your custom data'
|
||||||
|
autoComplete='off'
|
||||||
|
{...register(`custom.${idx}.title`, {
|
||||||
|
required: { value: true, message: 'Field cannot be empty' },
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<Button
|
||||||
|
size='sm'
|
||||||
|
variant='ontime-subtle'
|
||||||
|
color='#FA5656' // $red-500
|
||||||
|
onClick={() => remove(idx)}
|
||||||
|
leftIcon={<IoTrash />}
|
||||||
|
>
|
||||||
|
Delete Entry
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{rowErrors?.title?.message && <Panel.Error>{rowErrors.title.message}</Panel.Error>}
|
||||||
|
</div>
|
||||||
|
<label>
|
||||||
|
Value
|
||||||
|
<Textarea
|
||||||
|
variant='ontime-filled'
|
||||||
|
resize='none'
|
||||||
|
size='sm'
|
||||||
|
defaultValue={field.value}
|
||||||
|
autoComplete='off'
|
||||||
|
placeholder='Text of your custom data'
|
||||||
|
{...register(`custom.${idx}.value`, {
|
||||||
|
required: { value: true, message: 'Field cannot be empty' },
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
{rowErrors?.value?.message && <Panel.Error>{rowErrors.value.message}</Panel.Error>}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Panel.Section>
|
||||||
</Panel.Section>
|
</Panel.Section>
|
||||||
</Panel.Card>
|
</Panel.Card>
|
||||||
</Panel.Section>
|
</Panel.Section>
|
||||||
|
|||||||
@@ -57,3 +57,18 @@
|
|||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.customDataItem {
|
||||||
|
display: contents;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
.titleRow{
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
align-items: end;
|
||||||
|
|
||||||
|
label {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export async function makeProjectPatch(data: DatabaseModel, mergeKeys: Record<st
|
|||||||
for (const key in mergeKeys) {
|
for (const key in mergeKeys) {
|
||||||
if (isKeyOfType(key, data) && mergeKeys[key]) {
|
if (isKeyOfType(key, data) && mergeKeys[key]) {
|
||||||
// if the rundown is merged we also need the custom fields
|
// if the rundown is merged we also need the custom fields
|
||||||
if (key === 'rundown') {
|
if (key === 'rundowns') {
|
||||||
patchObject.customFields = data['customFields'];
|
patchObject.customFields = data['customFields'];
|
||||||
}
|
}
|
||||||
Object.assign(patchObject, { [key]: data[key] });
|
Object.assign(patchObject, { [key]: data[key] });
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Button } from '@chakra-ui/react';
|
import { Button } from '@chakra-ui/react';
|
||||||
import { CustomFields, OntimeRundown } from 'ontime-types';
|
import { CustomFields, Rundown } from 'ontime-types';
|
||||||
|
|
||||||
import * as Panel from '../../panel-utils/PanelUtils';
|
import * as Panel from '../../panel-utils/PanelUtils';
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ import useGoogleSheet from './useGoogleSheet';
|
|||||||
import { useSheetStore } from './useSheetStore';
|
import { useSheetStore } from './useSheetStore';
|
||||||
|
|
||||||
interface ImportReviewProps {
|
interface ImportReviewProps {
|
||||||
rundown: OntimeRundown;
|
rundown: Rundown;
|
||||||
customFields: CustomFields;
|
customFields: CustomFields;
|
||||||
onFinished: () => void;
|
onFinished: () => void;
|
||||||
onCancel: () => void;
|
onCancel: () => void;
|
||||||
@@ -29,7 +29,12 @@ export default function ImportReview(props: ImportReviewProps) {
|
|||||||
|
|
||||||
const applyImport = async () => {
|
const applyImport = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
await importRundown(rundown, customFields);
|
await importRundown(
|
||||||
|
{
|
||||||
|
[rundown.id]: rundown,
|
||||||
|
},
|
||||||
|
customFields,
|
||||||
|
);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
onFinished();
|
onFinished();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ export default function SourcesPanel() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmitImportPreview = async (importMap: ImportMap) => {
|
const handleSubmitImportPreview = async (importMap: ImportMap) => {
|
||||||
|
setError(''); // to clear previous error
|
||||||
if (importFlow === 'excel') {
|
if (importFlow === 'excel') {
|
||||||
try {
|
try {
|
||||||
const previewData = await importRundownPreviewExcel(importMap);
|
const previewData = await importRundownPreviewExcel(importMap);
|
||||||
|
|||||||
+10
-1
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useFieldArray, useForm } from 'react-hook-form';
|
import { useFieldArray, useForm } from 'react-hook-form';
|
||||||
import { IoAdd, IoTrash } from 'react-icons/io5';
|
import { IoAdd, IoTrash } from 'react-icons/io5';
|
||||||
import { Button, IconButton, Input, Select, Tooltip } from '@chakra-ui/react';
|
import { Button, IconButton, Input, Select, Tooltip } from '@chakra-ui/react';
|
||||||
@@ -28,6 +28,7 @@ export default function ImportMapForm(props: ImportMapFormProps) {
|
|||||||
control,
|
control,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
register,
|
register,
|
||||||
|
setValue,
|
||||||
formState: { errors, isValid },
|
formState: { errors, isValid },
|
||||||
} = useForm<NamedImportMap>({
|
} = useForm<NamedImportMap>({
|
||||||
mode: 'onChange',
|
mode: 'onChange',
|
||||||
@@ -45,6 +46,14 @@ export default function ImportMapForm(props: ImportMapFormProps) {
|
|||||||
|
|
||||||
const [loading, setLoading] = useState<'' | 'export' | 'import'>('');
|
const [loading, setLoading] = useState<'' | 'export' | 'import'>('');
|
||||||
|
|
||||||
|
// Set first sheet as default worksheet when 'event schedule' sheet is not there
|
||||||
|
useEffect(() => {
|
||||||
|
if (!worksheetNames || worksheetNames.length === 0) return;
|
||||||
|
if (!worksheetNames.includes(namedImportMap.Worksheet)) {
|
||||||
|
setValue('Worksheet', worksheetNames[0], { shouldValidate: true, shouldDirty: true });
|
||||||
|
}
|
||||||
|
}, [worksheetNames, setValue, namedImportMap.Worksheet]);
|
||||||
|
|
||||||
const handleExport = async (values: NamedImportMap) => {
|
const handleExport = async (values: NamedImportMap) => {
|
||||||
setLoading('export');
|
setLoading('export');
|
||||||
const importMap = convertToImportMap(values);
|
const importMap = convertToImportMap(values);
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ import { ImportCustom, ImportMap } from 'ontime-utils';
|
|||||||
export type NamedImportMap = typeof namedImportMap;
|
export type NamedImportMap = typeof namedImportMap;
|
||||||
|
|
||||||
// Record of label and import name
|
// Record of label and import name
|
||||||
export const namedImportMap = {
|
const namedImportMap = {
|
||||||
Worksheet: 'event schedule',
|
Worksheet: 'event schedule',
|
||||||
Start: 'time start',
|
Start: 'time start',
|
||||||
'Link start': 'link start',
|
'Link start': 'link start',
|
||||||
|
|||||||
+32
-31
@@ -1,6 +1,6 @@
|
|||||||
import { Fragment } from 'react';
|
import { Fragment } from 'react';
|
||||||
import { IoLink } from 'react-icons/io5';
|
import { IoLink } from 'react-icons/io5';
|
||||||
import { CustomFields, isOntimeBlock, isOntimeEvent, OntimeRundown } from 'ontime-types';
|
import { CustomFields, isOntimeBlock, isOntimeEvent, Rundown } from 'ontime-types';
|
||||||
import { millisToString } from 'ontime-utils';
|
import { millisToString } from 'ontime-utils';
|
||||||
|
|
||||||
import Tag from '../../../../../common/components/tag/Tag';
|
import Tag from '../../../../../common/components/tag/Tag';
|
||||||
@@ -10,7 +10,7 @@ import * as Panel from '../../../panel-utils/PanelUtils';
|
|||||||
import style from './PreviewRundown.module.scss';
|
import style from './PreviewRundown.module.scss';
|
||||||
|
|
||||||
interface PreviewRundownProps {
|
interface PreviewRundownProps {
|
||||||
rundown: OntimeRundown;
|
rundown: Rundown;
|
||||||
customFields: CustomFields;
|
customFields: CustomFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,75 +53,76 @@ export default function PreviewRundown(props: PreviewRundownProps) {
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{rundown.map((event) => {
|
{rundown.order.map((entryId) => {
|
||||||
if (isOntimeBlock(event)) {
|
const entry = rundown.entries[entryId];
|
||||||
|
if (isOntimeBlock(entry)) {
|
||||||
return (
|
return (
|
||||||
<tr key={event.id}>
|
<tr key={entry.id}>
|
||||||
<td className={style.center}>
|
<td className={style.center}>
|
||||||
<Tag>-</Tag>
|
<Tag>-</Tag>
|
||||||
</td>
|
</td>
|
||||||
<td className={style.center}>
|
<td className={style.center}>
|
||||||
<Tag>{event.type}</Tag>
|
<Tag>{entry.type}</Tag>
|
||||||
</td>
|
</td>
|
||||||
<td />
|
<td />
|
||||||
<td colSpan={99}>{event.title}</td>
|
<td colSpan={99}>{entry.title}</td>
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!isOntimeEvent(event)) {
|
if (!isOntimeEvent(entry)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
eventIndex += 1;
|
eventIndex += 1;
|
||||||
const colour = event.colour ? getAccessibleColour(event.colour) : {};
|
const colour = entry.colour ? getAccessibleColour(entry.colour) : {};
|
||||||
const countToEnd = booleanToText(event.countToEnd);
|
const countToEnd = booleanToText(entry.countToEnd);
|
||||||
const isPublic = booleanToText(event.isPublic);
|
const isPublic = booleanToText(entry.isPublic);
|
||||||
const skip = booleanToText(event.skip);
|
const skip = booleanToText(entry.skip);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment key={event.id}>
|
<Fragment key={entry.id}>
|
||||||
<tr>
|
<tr>
|
||||||
<td className={style.center}>
|
<td className={style.center}>
|
||||||
<Tag>{eventIndex}</Tag>
|
<Tag>{eventIndex}</Tag>
|
||||||
</td>
|
</td>
|
||||||
<td className={style.center}>
|
<td className={style.center}>
|
||||||
<Tag>{event.type}</Tag>
|
<Tag>{entry.type}</Tag>
|
||||||
</td>
|
</td>
|
||||||
<td className={style.nowrap}>{event.cue}</td>
|
<td className={style.nowrap}>{entry.cue}</td>
|
||||||
<td>{event.title}</td>
|
<td>{entry.title}</td>
|
||||||
<td className={style.flex}>
|
<td className={style.flex}>
|
||||||
<span className={event.linkStart ? style.subdued : undefined}>{millisToString(event.timeStart)}</span>
|
<span className={entry.linkStart ? style.subdued : undefined}>{millisToString(entry.timeStart)}</span>
|
||||||
{event.linkStart && <IoLink className={style.linkStartActive} />}
|
{entry.linkStart && <IoLink className={style.linkStartActive} />}
|
||||||
</td>
|
</td>
|
||||||
<td>{millisToString(event.timeEnd)}</td>
|
<td>{millisToString(entry.timeEnd)}</td>
|
||||||
<td>{millisToString(event.duration)}</td>
|
<td>{millisToString(entry.duration)}</td>
|
||||||
<td>{millisToString(event.timeWarning)}</td>
|
<td>{millisToString(entry.timeWarning)}</td>
|
||||||
<td>{millisToString(event.timeDanger)}</td>
|
<td>{millisToString(entry.timeDanger)}</td>
|
||||||
<td className={style.center}>{countToEnd && <Tag>{countToEnd}</Tag>}</td>
|
<td className={style.center}>{countToEnd && <Tag>{countToEnd}</Tag>}</td>
|
||||||
<td className={style.center}>{isPublic && <Tag>{isPublic}</Tag>}</td>
|
<td className={style.center}>{isPublic && <Tag>{isPublic}</Tag>}</td>
|
||||||
<td>{skip && <Tag>{skip}</Tag>}</td>
|
<td>{skip && <Tag>{skip}</Tag>}</td>
|
||||||
<td style={{ ...colour }}>{event.colour}</td>
|
<td style={{ ...colour }}>{entry.colour}</td>
|
||||||
<td className={style.center}>
|
<td className={style.center}>
|
||||||
<Tag>{event.timerType}</Tag>
|
<Tag>{entry.timerType}</Tag>
|
||||||
</td>
|
</td>
|
||||||
<td className={style.center}>
|
<td className={style.center}>
|
||||||
<Tag>{event.endAction}</Tag>
|
<Tag>{entry.endAction}</Tag>
|
||||||
</td>
|
</td>
|
||||||
{isOntimeEvent(event) &&
|
{isOntimeEvent(entry) &&
|
||||||
fieldKeys.map((field) => {
|
fieldKeys.map((field) => {
|
||||||
let value = '';
|
let value = '';
|
||||||
if (field in event.custom) {
|
if (field in entry.custom) {
|
||||||
value = event.custom[field];
|
value = entry.custom[field];
|
||||||
}
|
}
|
||||||
return <td key={field}>{value}</td>;
|
return <td key={field}>{value}</td>;
|
||||||
})}
|
})}
|
||||||
<td className={style.center}>
|
<td className={style.center}>
|
||||||
<Tag>{event.id}</Tag>
|
<Tag>{entry.id}</Tag>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{event.note && (
|
{entry.note && (
|
||||||
<tr>
|
<tr>
|
||||||
<td colSpan={99} className={style.secondaryRow}>
|
<td colSpan={99} className={style.secondaryRow}>
|
||||||
Note: {event.note}
|
Note: {entry.note}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useQueryClient } from '@tanstack/react-query';
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
import { AuthenticationStatus, CustomFields, OntimeRundown } from 'ontime-types';
|
import { AuthenticationStatus, CustomFields, ProjectRundowns } from 'ontime-types';
|
||||||
import { ImportMap } from 'ontime-utils';
|
import { ImportMap } from 'ontime-utils';
|
||||||
|
|
||||||
import { CUSTOM_FIELDS, RUNDOWN } from '../../../../common/api/constants';
|
import { CUSTOM_FIELDS, RUNDOWN } from '../../../../common/api/constants';
|
||||||
@@ -75,9 +75,9 @@ export default function useGoogleSheet() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** applies rundown and customFields to current project */
|
/** applies rundown and customFields to current project */
|
||||||
const importRundown = async (rundown: OntimeRundown, customFields: CustomFields) => {
|
const importRundown = async (rundowns: ProjectRundowns, customFields: CustomFields) => {
|
||||||
try {
|
try {
|
||||||
await patchData({ rundown, customFields });
|
await patchData({ rundowns, customFields });
|
||||||
// we are unable to optimistically set the rundown since we need
|
// we are unable to optimistically set the rundown since we need
|
||||||
// it to be normalised
|
// it to be normalised
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { AuthenticationStatus, CustomFields, OntimeRundown } from 'ontime-types';
|
import { AuthenticationStatus, CustomFields, Rundown } from 'ontime-types';
|
||||||
import { defaultImportMap, ImportMap } from 'ontime-utils';
|
import { defaultImportMap, ImportMap } from 'ontime-utils';
|
||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
|
|
||||||
@@ -15,8 +15,8 @@ type SheetStore = {
|
|||||||
setAuthenticationStatus: (status: AuthenticationStatus) => void;
|
setAuthenticationStatus: (status: AuthenticationStatus) => void;
|
||||||
|
|
||||||
// we get this from a preview response
|
// we get this from a preview response
|
||||||
rundown: OntimeRundown | null;
|
rundown: Rundown | null;
|
||||||
setRundown: (rundown: OntimeRundown | null) => void;
|
setRundown: (rundown: Rundown | null) => void;
|
||||||
|
|
||||||
// we get this from a preview response
|
// we get this from a preview response
|
||||||
customFields: CustomFields | null;
|
customFields: CustomFields | null;
|
||||||
@@ -60,7 +60,7 @@ export const useSheetStore = create<SheetStore>((set, get) => ({
|
|||||||
|
|
||||||
setAuthenticationStatus: (status: AuthenticationStatus) => set({ authenticationStatus: status }),
|
setAuthenticationStatus: (status: AuthenticationStatus) => set({ authenticationStatus: status }),
|
||||||
|
|
||||||
setRundown: (rundown: OntimeRundown | null) => set({ rundown }),
|
setRundown: (rundown: Rundown | null) => set({ rundown }),
|
||||||
|
|
||||||
setCustomFields: (customFields: CustomFields | null) => set({ customFields }),
|
setCustomFields: (customFields: CustomFields | null) => set({ customFields }),
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import { useEffect, useRef } from 'react';
|
import { PropsWithChildren, useEffect, useRef, useState } from 'react';
|
||||||
import { IoEye, IoEyeOffOutline } from 'react-icons/io5';
|
|
||||||
import { Input } from '@chakra-ui/react';
|
import { Input } from '@chakra-ui/react';
|
||||||
|
|
||||||
import TooltipActionBtn from '../../../common/components/buttons/TooltipActionBtn';
|
import { cx } from '../../../common/utils/styleUtils';
|
||||||
import { tooltipDelayMid } from '../../../ontimeConfig';
|
|
||||||
|
|
||||||
import style from './InputRow.module.scss';
|
import style from './InputRow.module.scss';
|
||||||
|
|
||||||
@@ -12,50 +10,53 @@ interface InputRowProps {
|
|||||||
placeholder: string;
|
placeholder: string;
|
||||||
text: string;
|
text: string;
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
actionHandler: () => void;
|
|
||||||
changeHandler: (newValue: string) => void;
|
changeHandler: (newValue: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function InputRow(props: InputRowProps) {
|
export default function InputRow(props: PropsWithChildren<InputRowProps>) {
|
||||||
const { label, placeholder, text, visible, actionHandler, changeHandler } = props;
|
const { label, placeholder, text, visible, changeHandler, children } = props;
|
||||||
|
|
||||||
|
const [value, setValue] = useState(text);
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
const cursorPositionRef = useRef(0);
|
const cursorPositionRef = useRef(0);
|
||||||
|
|
||||||
// sync cursor position with text
|
// sync cursor position with text
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (inputRef.current) {
|
if (inputRef.current && inputRef.current !== document.activeElement) {
|
||||||
inputRef.current.selectionStart = cursorPositionRef.current;
|
inputRef.current.selectionStart = cursorPositionRef.current;
|
||||||
inputRef.current.selectionEnd = cursorPositionRef.current;
|
inputRef.current.selectionEnd = cursorPositionRef.current;
|
||||||
}
|
}
|
||||||
}, [text]);
|
}, [text]);
|
||||||
|
|
||||||
|
// synchronise external text
|
||||||
|
useEffect(() => {
|
||||||
|
if (inputRef.current !== document.activeElement) {
|
||||||
|
setValue(text);
|
||||||
|
}
|
||||||
|
}, [text]);
|
||||||
|
|
||||||
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
cursorPositionRef.current = event.target.selectionStart ?? 0;
|
cursorPositionRef.current = event.target.selectionStart ?? 0;
|
||||||
|
setValue(event.target.value);
|
||||||
changeHandler(event.target.value);
|
changeHandler(event.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={style.inputRow}>
|
<div className={style.inputRow}>
|
||||||
<label className={`${style.label} ${visible ? style.active : ''}`}>{label}</label>
|
<label className={cx([style.label, visible ?? style.active])} htmlFor={label}>
|
||||||
|
{label}
|
||||||
|
</label>
|
||||||
<div className={style.inputItems}>
|
<div className={style.inputItems}>
|
||||||
<Input
|
<Input
|
||||||
|
id={label}
|
||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
size='sm'
|
size='sm'
|
||||||
variant='ontime-filled'
|
variant='ontime-filled'
|
||||||
value={text}
|
value={value}
|
||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
/>
|
/>
|
||||||
<TooltipActionBtn
|
{children}
|
||||||
clickHandler={actionHandler}
|
|
||||||
tooltip={visible ? 'Make invisible' : 'Make visible'}
|
|
||||||
aria-label={`Toggle ${label}`}
|
|
||||||
openDelay={tooltipDelayMid}
|
|
||||||
icon={visible ? <IoEye size='18px' /> : <IoEyeOffOutline size='18px' />}
|
|
||||||
variant={visible ? 'ontime-filled' : 'ontime-subtle'}
|
|
||||||
size='sm'
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
|
import { IoEye, IoEyeOffOutline } from 'react-icons/io5';
|
||||||
|
|
||||||
|
import TooltipActionBtn from '../../../common/components/buttons/TooltipActionBtn';
|
||||||
import { setMessage, useExternalMessageInput, useTimerMessageInput } from '../../../common/hooks/useSocket';
|
import { setMessage, useExternalMessageInput, useTimerMessageInput } from '../../../common/hooks/useSocket';
|
||||||
|
import { tooltipDelayMid } from '../../../ontimeConfig';
|
||||||
|
|
||||||
import InputRow from './InputRow';
|
import InputRow from './InputRow';
|
||||||
import TimerControlsPreview from './TimerViewControl';
|
import TimerControlsPreview from './TimerViewControl';
|
||||||
@@ -23,8 +27,17 @@ function TimerMessageInput() {
|
|||||||
text={text}
|
text={text}
|
||||||
visible={visible}
|
visible={visible}
|
||||||
changeHandler={(newValue) => setMessage.timerText(newValue)}
|
changeHandler={(newValue) => setMessage.timerText(newValue)}
|
||||||
actionHandler={() => setMessage.timerVisible(!visible)}
|
>
|
||||||
/>
|
<TooltipActionBtn
|
||||||
|
clickHandler={() => setMessage.timerVisible(!visible)}
|
||||||
|
tooltip={visible ? 'Make invisible' : 'Make visible'}
|
||||||
|
aria-label='Toggle timer message visibility'
|
||||||
|
openDelay={tooltipDelayMid}
|
||||||
|
icon={visible ? <IoEye size='18px' /> : <IoEyeOffOutline size='18px' />}
|
||||||
|
variant={visible ? 'ontime-filled' : 'ontime-subtle'}
|
||||||
|
size='sm'
|
||||||
|
/>
|
||||||
|
</InputRow>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +59,16 @@ function ExternalInput() {
|
|||||||
text={text}
|
text={text}
|
||||||
visible={visible}
|
visible={visible}
|
||||||
changeHandler={(newValue) => setMessage.externalText(newValue)}
|
changeHandler={(newValue) => setMessage.externalText(newValue)}
|
||||||
actionHandler={toggleExternal}
|
>
|
||||||
/>
|
<TooltipActionBtn
|
||||||
|
clickHandler={toggleExternal}
|
||||||
|
tooltip={visible ? 'Make invisible' : 'Make visible'}
|
||||||
|
aria-label='Toggle external message visibility'
|
||||||
|
openDelay={tooltipDelayMid}
|
||||||
|
icon={visible ? <IoEye size='18px' /> : <IoEyeOffOutline size='18px' />}
|
||||||
|
variant={visible ? 'ontime-filled' : 'ontime-subtle'}
|
||||||
|
size='sm'
|
||||||
|
/>
|
||||||
|
</InputRow>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { IoAdd, IoRemove } from 'react-icons/io5';
|
|||||||
import { Tooltip } from '@chakra-ui/react';
|
import { Tooltip } from '@chakra-ui/react';
|
||||||
import { useLocalStorage } from '@mantine/hooks';
|
import { useLocalStorage } from '@mantine/hooks';
|
||||||
import { Playback } from 'ontime-types';
|
import { Playback } from 'ontime-types';
|
||||||
import { MILLIS_PER_HOUR, MILLIS_PER_SECOND, parseUserTime } from 'ontime-utils';
|
import { MILLIS_PER_HOUR, parseUserTime } from 'ontime-utils';
|
||||||
|
|
||||||
import TimeInput from '../../../../common/components/input/time-input/TimeInput';
|
import TimeInput from '../../../../common/components/input/time-input/TimeInput';
|
||||||
import { setPlayback } from '../../../../common/hooks/useSocket';
|
import { setPlayback } from '../../../../common/hooks/useSocket';
|
||||||
@@ -17,29 +17,29 @@ interface AddTimeProps {
|
|||||||
|
|
||||||
export default function AddTime(props: AddTimeProps) {
|
export default function AddTime(props: AddTimeProps) {
|
||||||
const { playback } = props;
|
const { playback } = props;
|
||||||
const [time, setTime] = useLocalStorage({ key: 'add-time', defaultValue: 300_000 }); // 5 minutes
|
const [timeInMs, setTime] = useLocalStorage({ key: 'add-time', defaultValue: 300_000 }); // 5 minutes
|
||||||
|
|
||||||
const handleTimeChange = (_field: string, value: string) => {
|
const handleTimeChange = (_field: string, value: string) => {
|
||||||
const newTime = parseUserTime(value);
|
const newTimeInMs = parseUserTime(value);
|
||||||
// cap add time to 1 hour
|
// cap add time to 1 hour
|
||||||
setTime(Math.min(newTime, MILLIS_PER_HOUR));
|
setTime(Math.min(newTimeInMs, MILLIS_PER_HOUR));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAddTime = (direction: 'add' | 'remove') => {
|
const handleAddTime = (direction: 'add' | 'remove') => {
|
||||||
// API expects input in seconds
|
// API expects input in milliseconds
|
||||||
if (direction === 'add') {
|
if (direction === 'add') {
|
||||||
setPlayback.addTime(time / MILLIS_PER_SECOND);
|
setPlayback.addTime(timeInMs);
|
||||||
} else {
|
} else {
|
||||||
setPlayback.addTime((-1 * time) / MILLIS_PER_SECOND);
|
setPlayback.addTime(-1 * timeInMs);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const canAddTime = playback === Playback.Play || playback === Playback.Pause;
|
const canAddTime = playback === Playback.Play || playback === Playback.Pause;
|
||||||
const doDisableButtons = !canAddTime || time === 0;
|
const doDisableButtons = !canAddTime || timeInMs === 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={style.addTime}>
|
<div className={style.addTime}>
|
||||||
<TimeInput name='addtime' submitHandler={handleTimeChange} time={time} placeholder='Add time' />
|
<TimeInput name='addtime' submitHandler={handleTimeChange} time={timeInMs} placeholder='Add time' />
|
||||||
<div className={style.addButtons}>
|
<div className={style.addButtons}>
|
||||||
<Tooltip label='Remove time' openDelay={tooltipDelayMid} shouldWrapChildren>
|
<Tooltip label='Remove time' openDelay={tooltipDelayMid} shouldWrapChildren>
|
||||||
<TapButton onClick={() => handleAddTime('remove')} disabled={doDisableButtons} className={style.tallButtons}>
|
<TapButton onClick={() => handleAddTime('remove')} disabled={doDisableButtons} className={style.tallButtons}>
|
||||||
|
|||||||
@@ -59,15 +59,20 @@ export function AuxTimer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function AuxTimerInput() {
|
function AuxTimerInput() {
|
||||||
const time = useAuxTimerTime();
|
const newTimeInMs = useAuxTimerTime();
|
||||||
const { setDuration } = setAuxTimer;
|
const { setDuration } = setAuxTimer;
|
||||||
|
|
||||||
const handleTimeUpdate = (_field: string, value: string) => {
|
const handleTimeUpdate = (_field: string, value: string) => {
|
||||||
const newTime = parseUserTime(value);
|
const newTimeInMs = parseUserTime(value);
|
||||||
setDuration(newTime / 1000); // frontend api is seconds based
|
setDuration(newTimeInMs);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TimeInput<'auxTimer'> submitHandler={handleTimeUpdate} name='auxTimer' time={time} placeholder='Aux Timer 1' />
|
<TimeInput<'auxTimer'>
|
||||||
|
submitHandler={handleTimeUpdate}
|
||||||
|
name='auxTimer'
|
||||||
|
time={newTimeInMs}
|
||||||
|
placeholder='Aux Timer 1'
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import AppSettings from '../app-settings/AppSettings';
|
|||||||
import useAppSettingsNavigation from '../app-settings/useAppSettingsNavigation';
|
import useAppSettingsNavigation from '../app-settings/useAppSettingsNavigation';
|
||||||
import { EditorOverview } from '../overview/Overview';
|
import { EditorOverview } from '../overview/Overview';
|
||||||
|
|
||||||
import Finder from './finder/Finder';
|
|
||||||
import WelcomePlacement from './welcome/WelcomePlacement';
|
import WelcomePlacement from './welcome/WelcomePlacement';
|
||||||
|
|
||||||
import styles from './Editor.module.scss';
|
import styles from './Editor.module.scss';
|
||||||
@@ -22,7 +21,6 @@ const MessageControl = lazy(() => import('../control/message/MessageControlExpor
|
|||||||
export default function Editor() {
|
export default function Editor() {
|
||||||
const { isOpen: isSettingsOpen, setLocation, close } = useAppSettingsNavigation();
|
const { isOpen: isSettingsOpen, setLocation, close } = useAppSettingsNavigation();
|
||||||
const { isOpen: isMenuOpen, onOpen, onClose } = useDisclosure();
|
const { isOpen: isMenuOpen, onOpen, onClose } = useDisclosure();
|
||||||
const { isOpen: isFinderOpen, onToggle: onFinderToggle, onClose: onFinderClose } = useDisclosure();
|
|
||||||
|
|
||||||
useWindowTitle('Editor');
|
useWindowTitle('Editor');
|
||||||
|
|
||||||
@@ -46,16 +44,11 @@ export default function Editor() {
|
|||||||
}
|
}
|
||||||
}, [close, isSettingsOpen, setLocation]);
|
}, [close, isSettingsOpen, setLocation]);
|
||||||
|
|
||||||
useHotkeys([
|
useHotkeys([['mod + ,', toggleSettings]]);
|
||||||
['mod + ,', toggleSettings],
|
|
||||||
['mod + f', onFinderToggle],
|
|
||||||
['Escape', onFinderClose],
|
|
||||||
]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.mainContainer} data-testid='event-editor'>
|
<div className={styles.mainContainer} data-testid='event-editor'>
|
||||||
<WelcomePlacement />
|
<WelcomePlacement />
|
||||||
<Finder isOpen={isFinderOpen} onClose={onFinderClose} />
|
|
||||||
<NavigationMenu isOpen={isMenuOpen} onClose={onClose} />
|
<NavigationMenu isOpen={isMenuOpen} onClose={onClose} />
|
||||||
<EditorOverview>
|
<EditorOverview>
|
||||||
<IconButton
|
<IconButton
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { KeyboardEvent, useState } from 'react';
|
import { KeyboardEvent, useState } from 'react';
|
||||||
import { Input, Modal, ModalBody, ModalContent, ModalFooter, ModalOverlay } from '@chakra-ui/react';
|
import { Input, Modal, ModalBody, ModalContent, ModalFooter, ModalOverlay } from '@chakra-ui/react';
|
||||||
import { useDebouncedCallback } from '@mantine/hooks';
|
import { useDebouncedCallback } from '@mantine/hooks';
|
||||||
import { SupportedEvent } from 'ontime-types';
|
import { SupportedEntry } from 'ontime-types';
|
||||||
|
|
||||||
import { useEventSelection } from '../../rundown/useEventSelection';
|
import { useEventSelection } from '../../rundown/useEventSelection';
|
||||||
|
|
||||||
@@ -67,9 +67,9 @@ export default function Finder(props: FinderProps) {
|
|||||||
{results.length > 0 &&
|
{results.length > 0 &&
|
||||||
results.map((entry, index) => {
|
results.map((entry, index) => {
|
||||||
const isSelected = selected === index;
|
const isSelected = selected === index;
|
||||||
const displayIndex = entry.type === SupportedEvent.Event ? entry.eventIndex : '-';
|
const displayIndex = entry.type === SupportedEntry.Event ? entry.eventIndex : '-';
|
||||||
const displayCue = entry.type === SupportedEvent.Event ? entry.cue : '';
|
const displayCue = entry.type === SupportedEntry.Event ? entry.cue : '';
|
||||||
const colour = entry.type === SupportedEvent.Event ? entry.colour : '';
|
const colour = entry.type === SupportedEntry.Event ? entry.colour : '';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li
|
<li
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
import { ChangeEvent, useEffect, useRef, useState } from 'react';
|
import { ChangeEvent, useEffect, useRef, useState } from 'react';
|
||||||
import { isOntimeBlock, isOntimeEvent, MaybeString, SupportedEvent } from 'ontime-types';
|
import { isOntimeBlock, isOntimeEvent, MaybeString, SupportedEntry } from 'ontime-types';
|
||||||
|
|
||||||
import { useFlatRundown } from '../../../common/hooks-query/useRundown';
|
import { useFlatRundown } from '../../../common/hooks-query/useRundown';
|
||||||
|
|
||||||
const maxResults = 12;
|
const maxResults = 12;
|
||||||
|
|
||||||
type FilterableBlock = {
|
type FilterableBlock = {
|
||||||
type: SupportedEvent.Block;
|
type: SupportedEntry.Block;
|
||||||
id: string;
|
id: string;
|
||||||
index: number;
|
index: number;
|
||||||
title: string;
|
title: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type FilterableEvent = {
|
type FilterableEvent = {
|
||||||
type: SupportedEvent.Event;
|
type: SupportedEntry.Event;
|
||||||
id: string;
|
id: string;
|
||||||
index: number;
|
index: number;
|
||||||
eventIndex: number;
|
eventIndex: number;
|
||||||
@@ -59,7 +59,7 @@ export default function useFinder() {
|
|||||||
if (isOntimeEvent(event)) {
|
if (isOntimeEvent(event)) {
|
||||||
if (eventIndex === searchIndex) {
|
if (eventIndex === searchIndex) {
|
||||||
results.push({
|
results.push({
|
||||||
type: SupportedEvent.Event,
|
type: SupportedEntry.Event,
|
||||||
id: event.id,
|
id: event.id,
|
||||||
index: i,
|
index: i,
|
||||||
eventIndex,
|
eventIndex,
|
||||||
@@ -93,7 +93,7 @@ export default function useFinder() {
|
|||||||
if (event.cue.toLowerCase().includes(searchString)) {
|
if (event.cue.toLowerCase().includes(searchString)) {
|
||||||
remaining--;
|
remaining--;
|
||||||
results.push({
|
results.push({
|
||||||
type: SupportedEvent.Event,
|
type: SupportedEntry.Event,
|
||||||
id: event.id,
|
id: event.id,
|
||||||
index: i,
|
index: i,
|
||||||
eventIndex,
|
eventIndex,
|
||||||
@@ -126,7 +126,7 @@ export default function useFinder() {
|
|||||||
if (event.title.toLowerCase().includes(searchString)) {
|
if (event.title.toLowerCase().includes(searchString)) {
|
||||||
remaining--;
|
remaining--;
|
||||||
results.push({
|
results.push({
|
||||||
type: SupportedEvent.Event,
|
type: SupportedEntry.Event,
|
||||||
id: event.id,
|
id: event.id,
|
||||||
index: i,
|
index: i,
|
||||||
eventIndex,
|
eventIndex,
|
||||||
@@ -141,7 +141,7 @@ export default function useFinder() {
|
|||||||
if (event.title.toLowerCase().includes(searchString)) {
|
if (event.title.toLowerCase().includes(searchString)) {
|
||||||
remaining--;
|
remaining--;
|
||||||
results.push({
|
results.push({
|
||||||
type: SupportedEvent.Block,
|
type: SupportedEntry.Block,
|
||||||
id: event.id,
|
id: event.id,
|
||||||
index: i,
|
index: i,
|
||||||
title: event.title,
|
title: event.title,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { useSearchParams } from 'react-router-dom';
|
import { useSearchParams } from 'react-router-dom';
|
||||||
import { isOntimeEvent, OntimeEvent, SupportedEvent } from 'ontime-types';
|
import { isOntimeEvent, OntimeEvent, SupportedEntry } from 'ontime-types';
|
||||||
import { getFirstEventNormal, getLastEventNormal } from 'ontime-utils';
|
import { getFirstEventNormal, getLastEventNormal } from 'ontime-utils';
|
||||||
|
|
||||||
import EmptyPage from '../../common/components/state/EmptyPage';
|
import EmptyPage from '../../common/components/state/EmptyPage';
|
||||||
@@ -126,8 +126,8 @@ export default function Operator() {
|
|||||||
let isPast = Boolean(featureData.selectedEventId);
|
let isPast = Boolean(featureData.selectedEventId);
|
||||||
const hidePast = isStringBoolean(searchParams.get('hidepast'));
|
const hidePast = isStringBoolean(searchParams.get('hidepast'));
|
||||||
|
|
||||||
const { firstEvent } = getFirstEventNormal(data.rundown, data.order);
|
const { firstEvent } = getFirstEventNormal(data.entries, data.order);
|
||||||
const { lastEvent } = getLastEventNormal(data.rundown, data.order);
|
const { lastEvent } = getLastEventNormal(data.entries, data.order);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={style.operatorContainer}>
|
<div className={style.operatorContainer}>
|
||||||
@@ -152,7 +152,7 @@ export default function Operator() {
|
|||||||
|
|
||||||
<div className={style.operatorEvents} onWheel={handleScroll} onTouchMove={handleScroll} ref={scrollRef}>
|
<div className={style.operatorEvents} onWheel={handleScroll} onTouchMove={handleScroll} ref={scrollRef}>
|
||||||
{data.order.map((eventId) => {
|
{data.order.map((eventId) => {
|
||||||
const entry = data.rundown[eventId];
|
const entry = data.entries[eventId];
|
||||||
if (isOntimeEvent(entry)) {
|
if (isOntimeEvent(entry)) {
|
||||||
const isSelected = featureData.selectedEventId === entry.id;
|
const isSelected = featureData.selectedEventId === entry.id;
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
@@ -197,7 +197,7 @@ export default function Operator() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry.type === SupportedEvent.Block) {
|
if (entry.type === SupportedEntry.Block) {
|
||||||
return <OperatorBlock key={entry.id} title={entry.title} />;
|
return <OperatorBlock key={entry.id} title={entry.title} />;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { useRef, useState } from 'react';
|
|||||||
import { Button, Textarea } from '@chakra-ui/react';
|
import { Button, Textarea } from '@chakra-ui/react';
|
||||||
import { OntimeEvent } from 'ontime-types';
|
import { OntimeEvent } from 'ontime-types';
|
||||||
|
|
||||||
import { useEventAction } from '../../../common/hooks/useEventAction';
|
import { useEntryActions } from '../../../common/hooks/useEntryAction';
|
||||||
import type { EditEvent } from '../Operator';
|
import type { EditEvent } from '../Operator';
|
||||||
|
|
||||||
import style from './EditModal.module.scss';
|
import style from './EditModal.module.scss';
|
||||||
@@ -15,7 +15,7 @@ interface EditModalProps {
|
|||||||
export default function EditModal(props: EditModalProps) {
|
export default function EditModal(props: EditModalProps) {
|
||||||
const { event, onClose } = props;
|
const { event, onClose } = props;
|
||||||
|
|
||||||
const { updateEvent } = useEventAction();
|
const { updateEntry } = useEntryActions();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const inputRef = useRef<HTMLTextAreaElement[]>(new Array<HTMLTextAreaElement>());
|
const inputRef = useRef<HTMLTextAreaElement[]>(new Array<HTMLTextAreaElement>());
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ export default function EditModal(props: EditModalProps) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (patchObject.custom) {
|
if (patchObject.custom) {
|
||||||
await updateEvent(patchObject);
|
await updateEntry(patchObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
@@ -118,7 +118,8 @@
|
|||||||
padding-inline: 0.25rem;
|
padding-inline: 0.25rem;
|
||||||
background-color: $gray-1250;
|
background-color: $gray-1250;
|
||||||
color: $ui-white;
|
color: $ui-white;
|
||||||
white-space: pre;
|
// allow multi-line text but trim before
|
||||||
|
white-space: pre-line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ function OperatorEvent(props: OperatorEventProps) {
|
|||||||
<span className={style.mainField}>{main}</span>
|
<span className={style.mainField}>{main}</span>
|
||||||
<span className={style.schedule}>
|
<span className={style.schedule}>
|
||||||
<ClockTime value={timeStart} preferredFormat12='h:mm' preferredFormat24='HH:mm' />
|
<ClockTime value={timeStart} preferredFormat12='h:mm' preferredFormat24='HH:mm' />
|
||||||
-
|
→
|
||||||
<ClockTime value={timeEnd} preferredFormat12='h:mm' preferredFormat24='HH:mm' />
|
<ClockTime value={timeEnd} preferredFormat12='h:mm' preferredFormat24='HH:mm' />
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ export const getOperatorOptions = (customFields: CustomFields, timeFormat: strin
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'subscribe',
|
id: 'subscribe',
|
||||||
title: 'Highlight Field',
|
title: 'Highlight Fields',
|
||||||
description: 'Choose a custom field to highlight',
|
description: 'Choose custom fields to highlight',
|
||||||
type: 'multi-option',
|
type: 'multi-option',
|
||||||
values: customFieldSelect,
|
values: customFieldSelect,
|
||||||
},
|
},
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user