Skip to content

Commit 4778988

Browse files
committed
chore: remove remaining usages of react-timer-hoc
1 parent f35dc52 commit 4778988

File tree

6 files changed

+112
-131
lines changed

6 files changed

+112
-131
lines changed

packages/webui/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
"react-popper": "^2.3.0",
7979
"react-router-bootstrap": "^0.25.0",
8080
"react-router-dom": "^5.3.4",
81-
"react-timer-hoc": "^2.3.0",
8281
"semver": "^7.6.3",
8382
"sha.js": "^2.4.11",
8483
"shuttle-webhid": "^0.0.2",
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import Moment, { MomentProps } from 'react-moment'
22
import moment from 'moment'
3-
import { getCurrentTime } from './systemTime.js'
4-
import timer from 'react-timer-hoc'
3+
import { useCurrentTime } from './lib'
54

65
/**
76
* Use instead of <Moment fromNow></Moment>, its result is synced with getCurrentTime()
87
* @param args same as for Moment
98
*/
10-
export const MomentFromNow = timer(60000)(function MomentFromNow(args: MomentProps) {
11-
return <Moment {...args} from={moment(getCurrentTime())} interval={0}></Moment>
12-
})
9+
export function MomentFromNow(args: MomentProps): JSX.Element {
10+
const time = useCurrentTime(60000)
11+
12+
return <Moment {...args} from={moment(time)} interval={0}></Moment>
13+
}

packages/webui/src/client/ui/RundownView.tsx

Lines changed: 1 addition & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
} from '../lib/ReactMeteorData/react-meteor-data.js'
1212
import { VTContent, TSR, NoteSeverity, ISourceLayer } from '@sofie-automation/blueprints-integration'
1313
import { useTranslation, withTranslation } from 'react-i18next'
14-
import timer from 'react-timer-hoc'
1514
import * as CoreIcon from '@nrk/core-icons/jsx'
1615
import { Spinner } from '../lib/Spinner.js'
1716
import ClassNames from 'classnames'
@@ -172,117 +171,13 @@ import { PropertiesPanel } from './UserEditOperations/PropertiesPanel.js'
172171
import { PreviewPopUpContextProvider } from './PreviewPopUp/PreviewPopUpContext.js'
173172
import Navbar from 'react-bootstrap/Navbar'
174173
import { AnimatePresence } from 'motion/react'
174+
import { WarningDisplay } from './RundownView/WarningDisplay.js'
175175

176176
const REHEARSAL_MARGIN = 1 * 60 * 1000
177177
const HIDE_NOTIFICATIONS_AFTER_MOUNT: number | undefined = 5000
178178

179179
const DEFAULT_SEGMENT_VIEW_MODE = SegmentViewMode.Timeline
180180

181-
interface ITimingWarningProps {
182-
playlist: DBRundownPlaylist
183-
inActiveRundownView?: boolean
184-
studioMode: boolean
185-
oneMinuteBeforeAction: (e: Event, noResetOnActivate: boolean) => void
186-
}
187-
188-
interface ITimingWarningState {
189-
plannedStartCloseShown?: boolean
190-
plannedStartCloseShow?: boolean
191-
}
192-
const WarningDisplay = withTranslation()(
193-
timer(5000)(
194-
class WarningDisplay extends React.Component<Translated<ITimingWarningProps>, ITimingWarningState> {
195-
constructor(props: Translated<ITimingWarningProps>) {
196-
super(props)
197-
198-
this.state = {}
199-
}
200-
201-
componentDidUpdate(prevProps: ITimingWarningProps) {
202-
if (
203-
(this.props.playlist.activationId && !prevProps.playlist.activationId && this.props.playlist.rehearsal) ||
204-
this.props.playlist.rehearsal !== prevProps.playlist.rehearsal
205-
) {
206-
this.setState({
207-
plannedStartCloseShown: false,
208-
})
209-
}
210-
211-
const expectedStart = PlaylistTiming.getExpectedStart(this.props.playlist.timing)
212-
const expectedDuration = PlaylistTiming.getExpectedDuration(this.props.playlist.timing)
213-
214-
if (
215-
this.props.playlist.activationId &&
216-
this.props.playlist.rehearsal &&
217-
expectedStart &&
218-
// the expectedStart is near
219-
getCurrentTime() + REHEARSAL_MARGIN > expectedStart &&
220-
// but it's not horribly in the past
221-
getCurrentTime() < expectedStart + (expectedDuration || 60 * 60 * 1000) &&
222-
!this.props.inActiveRundownView &&
223-
!this.state.plannedStartCloseShown
224-
) {
225-
this.setState({
226-
plannedStartCloseShow: true,
227-
plannedStartCloseShown: true,
228-
})
229-
}
230-
}
231-
232-
discard = () => {
233-
this.setState({
234-
plannedStartCloseShow: false,
235-
})
236-
}
237-
238-
oneMinuteBeforeAction = (e: any, noResetOnActivate: boolean) => {
239-
this.setState({
240-
plannedStartCloseShow: false,
241-
})
242-
243-
this.props.oneMinuteBeforeAction(e, noResetOnActivate)
244-
}
245-
246-
render(): JSX.Element | null {
247-
const { t } = this.props
248-
249-
if (!this.props.playlist) return null
250-
251-
return (
252-
<ModalDialog
253-
title={t('Start time is close')}
254-
acceptText={t('Reset and Activate "On Air"')}
255-
secondaryText={t('Cancel')}
256-
actions={[
257-
{
258-
label: t('Activate "On Air"'),
259-
classNames: 'btn-secondary',
260-
on: (e) => {
261-
this.oneMinuteBeforeAction(e as Event, true) // this one activates without resetting
262-
},
263-
},
264-
]}
265-
onAccept={(e) => this.oneMinuteBeforeAction(e as Event, false)}
266-
onDiscard={this.discard}
267-
onSecondary={this.discard}
268-
show={
269-
this.props.studioMode &&
270-
this.state.plannedStartCloseShow &&
271-
!(this.props.playlist.activationId && !this.props.playlist.rehearsal) &&
272-
!!this.props.playlist.activationId
273-
}
274-
>
275-
<p>
276-
{t(
277-
'You are in rehearsal mode, the broadcast starts in less than 1 minute. Do you want to go into On-Air mode?'
278-
)}
279-
</p>
280-
</ModalDialog>
281-
)
282-
}
283-
}
284-
)
285-
)
286181
interface ITimingDisplayProps {
287182
rundownPlaylist: DBRundownPlaylist
288183
currentRundown: Rundown | undefined
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import type { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
2+
import { PlaylistTiming } from '@sofie-automation/corelib/dist/playout/rundownTiming'
3+
import React, { useEffect, useState } from 'react'
4+
import { useTranslation } from 'react-i18next'
5+
import { ModalDialog } from '../../lib/ModalDialog'
6+
import { useCurrentTime } from '../../lib/lib'
7+
8+
export const REHEARSAL_MARGIN = 1 * 60 * 1000
9+
10+
interface ITimingWarningProps {
11+
playlist: Pick<DBRundownPlaylist, '_id' | 'rehearsal' | 'activationId' | 'timing'>
12+
inActiveRundownView?: boolean
13+
studioMode: boolean
14+
oneMinuteBeforeAction: (e: Event, noResetOnActivate: boolean) => void
15+
}
16+
17+
export function WarningDisplay({
18+
playlist,
19+
inActiveRundownView,
20+
studioMode,
21+
oneMinuteBeforeAction,
22+
}: ITimingWarningProps): JSX.Element | null {
23+
const { t } = useTranslation()
24+
25+
const currentTime = useCurrentTime(5000)
26+
27+
const [plannedStartCloseShow, setPlannedStartCloseShow] = useState(false)
28+
const [plannedStartCloseShown, setPlannedStartCloseShown] = useState(false)
29+
30+
const discard = () => {
31+
setPlannedStartCloseShow(false)
32+
}
33+
34+
const oneMinuteBeforeAction2 = (e: any, noResetOnActivate: boolean) => {
35+
setPlannedStartCloseShow(false)
36+
37+
oneMinuteBeforeAction(e, noResetOnActivate)
38+
}
39+
40+
const prevPlaylist = React.useRef(playlist)
41+
useEffect(() => {
42+
if (
43+
(playlist.activationId && !prevPlaylist.current.activationId && playlist.rehearsal) ||
44+
playlist.rehearsal !== prevPlaylist.current.rehearsal
45+
) {
46+
setPlannedStartCloseShown(false)
47+
}
48+
49+
const expectedStart = PlaylistTiming.getExpectedStart(playlist.timing)
50+
const expectedDuration = PlaylistTiming.getExpectedDuration(playlist.timing)
51+
52+
if (
53+
playlist.activationId &&
54+
playlist.rehearsal &&
55+
expectedStart &&
56+
// the expectedStart is near
57+
currentTime + REHEARSAL_MARGIN > expectedStart &&
58+
// but it's not horribly in the past
59+
currentTime < expectedStart + (expectedDuration || 60 * 60 * 1000) &&
60+
!inActiveRundownView &&
61+
!plannedStartCloseShown
62+
) {
63+
setPlannedStartCloseShow(true)
64+
setPlannedStartCloseShown(true)
65+
}
66+
67+
prevPlaylist.current = playlist
68+
}, [playlist, inActiveRundownView, plannedStartCloseShown])
69+
70+
if (!playlist) return null
71+
72+
return (
73+
<ModalDialog
74+
title={t('Start time is close')}
75+
acceptText={t('Reset and Activate "On Air"')}
76+
secondaryText={t('Cancel')}
77+
actions={[
78+
{
79+
label: t('Activate "On Air"'),
80+
classNames: 'btn-secondary',
81+
on: (e) => {
82+
oneMinuteBeforeAction2(e as Event, true) // this one activates without resetting
83+
},
84+
},
85+
]}
86+
onAccept={(e) => oneMinuteBeforeAction2(e as Event, false)}
87+
onDiscard={discard}
88+
onSecondary={discard}
89+
show={
90+
studioMode &&
91+
plannedStartCloseShow &&
92+
!(playlist.activationId && !playlist.rehearsal) &&
93+
!!playlist.activationId
94+
}
95+
>
96+
<p>
97+
{t(
98+
'You are in rehearsal mode, the broadcast starts in less than 1 minute. Do you want to go into On-Air mode?',
99+
)}
100+
</p>
101+
</ModalDialog>
102+
)
103+
}

packages/webui/src/typings/react-time-hoc.d.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/yarn.lock

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6440,7 +6440,6 @@ __metadata:
64406440
react-popper: "npm:^2.3.0"
64416441
react-router-bootstrap: "npm:^0.25.0"
64426442
react-router-dom: "npm:^5.3.4"
6443-
react-timer-hoc: "npm:^2.3.0"
64446443
sass: "npm:^1.83.4"
64456444
semver: "npm:^7.6.3"
64466445
sha.js: "npm:^2.4.11"
@@ -16794,7 +16793,7 @@ asn1@evs-broadcast/node-asn1:
1679416793
languageName: node
1679516794
linkType: hard
1679616795

16797-
"invariant@npm:^2.2.4, invariant@npm:~2.2.2":
16796+
"invariant@npm:^2.2.4":
1679816797
version: 2.2.4
1679916798
resolution: "invariant@npm:2.2.4"
1680016799
dependencies:
@@ -24252,7 +24251,7 @@ asn1@evs-broadcast/node-asn1:
2425224251
languageName: node
2425324252
linkType: hard
2425424253

24255-
"prop-types@npm:^15.5.10, prop-types@npm:^15.6.0, prop-types@npm:^15.6.1, prop-types@npm:^15.6.2, prop-types@npm:^15.7.2, prop-types@npm:^15.8.1":
24254+
"prop-types@npm:^15.5.10, prop-types@npm:^15.6.1, prop-types@npm:^15.6.2, prop-types@npm:^15.7.2, prop-types@npm:^15.8.1":
2425624255
version: 15.8.1
2425724256
resolution: "prop-types@npm:15.8.1"
2425824257
dependencies:
@@ -25061,18 +25060,6 @@ asn1@evs-broadcast/node-asn1:
2506125060
languageName: node
2506225061
linkType: hard
2506325062

25064-
"react-timer-hoc@npm:^2.3.0":
25065-
version: 2.3.0
25066-
resolution: "react-timer-hoc@npm:2.3.0"
25067-
dependencies:
25068-
invariant: "npm:~2.2.2"
25069-
prop-types: "npm:^15.6.0"
25070-
peerDependencies:
25071-
react: ^15.0.0 || ^16.0.0
25072-
checksum: 10/caf5a75a81340344b05169d81cd48cbea833019c09c98767ef39d0e0961bbe3bfad1a0ea62d27450cc8971ec15cb4b44b001c76ed9b656f4a43da5dc20037abd
25073-
languageName: node
25074-
linkType: hard
25075-
2507625063
"react-transition-group@npm:^4.4.5":
2507725064
version: 4.4.5
2507825065
resolution: "react-transition-group@npm:4.4.5"

0 commit comments

Comments
 (0)