feat: presenter view

- connected to websockets
- some styling changes
- reusable components
- some small bugfixes
This commit is contained in:
cv
2021-04-17 23:54:00 +02:00
parent d9a1b5eb20
commit 8e95b06b8c
11 changed files with 197 additions and 90 deletions
@@ -1,16 +1,18 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import styles from './Countdown.module.css'; import styles from './Countdown.module.css';
function formatDisplay(seconds) { function formatDisplay(seconds, hideZero) {
const format = (val) => `0${Math.floor(val)}`.slice(-2); const format = (val) => `0${Math.floor(val)}`.slice(-2);
const hours = seconds / 3600; const hours = seconds / 3600;
const minutes = (seconds % 3600) / 60; const minutes = (seconds % 3600) / 60;
return [hours, minutes, seconds % 60].map(format).join(':'); if (hideZero && hours < 1)
return [minutes, seconds % 60].map(format).join(':');
else return [hours, minutes, seconds % 60].map(format).join(':');
} }
export default function Countdown(props) { export default function Countdown(props) {
const { time, small } = props; const { time, small, hideZeroHours } = props;
const [clock, setClock] = useState(time); const [clock, setClock] = useState(time);
let display = '-- : -- : --'; let display = '-- : -- : --';
@@ -19,7 +21,8 @@ export default function Countdown(props) {
}, [time]); }, [time]);
// prepare display string // prepare display string
if (clock != null && !isNaN(clock)) display = formatDisplay(clock); if (clock != null && !isNaN(clock))
display = formatDisplay(clock, hideZeroHours);
return ( return (
<div className={small ? styles.countdownClockSmall : styles.countdownClock}> <div className={small ? styles.countdownClockSmall : styles.countdownClock}>
@@ -9,11 +9,10 @@
/* Viewers */ /* Viewers */
.countdownClock { .countdownClock {
font-size: 18vw; font-size: 21vw;
margin-top: 6vh; line-height: 21vw;
margin-bottom: 5vh;
text-align: center; text-align: center;
letter-spacing: 0.125em; letter-spacing: 1vw;
} }
/* Editor */ /* Editor */
@@ -1,15 +1,15 @@
import { clamp } from '../../../app/utils'; import { clamp } from '../../../app/utils';
import styles from './MyProgressBar.module.css'; import styles from './MyProgressBar.module.css';
export default function MyProgressBar({ normalisedComplete }) { export default function MyProgressBar(props) {
const percentComplete = clamp(100 - normalisedComplete * 100, 0, 100); const { now, complete } = props;
const completeWidth = `${percentComplete}%`; const percentComplete = clamp((now * 100) / complete, 0, 100);
return ( return (
<div className={styles.progress}> <div className={styles.progress}>
<div <div
className={styles.progressBar} className={styles.progressBar}
style={{ width: completeWidth }} style={{ width: `${percentComplete}%` }}
></div> ></div>
</div> </div>
); );
@@ -1,21 +1,13 @@
.progress { .progress {
padding: 1vh; height: 2vh;
width: 90%; background-color: rgba(255, 255, 255, 0.13);
margin: 0 auto; border-radius: 4px;
background: rgba(0, 0, 0, 0.25);
border-radius: 6px;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 1px rgba(255, 255, 255, 0.08);
} }
.progressBar { .progressBar {
width: 30%;
height: 2vh; height: 2vh;
background: linear-gradient( background-color: rgba(255, 255, 255, 0.79);
90deg,
rgb(145, 255, 191, 1) 0%,
rgba(145, 255, 191, 0.8) 20%,
rgba(145, 255, 191, 0.5) 50%,
rgba(145, 255, 191, 0.2) 100%
);
border-radius: 4px; border-radius: 4px;
transition: 0.4s linear; transition: 0.4s linear;
transition-property: width, background-color; transition-property: width, background-color;
+4 -2
View File
@@ -10,11 +10,13 @@ export const stringFromMillis = (
) => { ) => {
if (ms === null) return ifNull; if (ms === null) return ifNull;
const showWith0 = (value) => (value < 10 ? `0${value}` : value); const showWith0 = (value) => (value < 10 ? `0${value}` : value);
const hours = showWith0(Math.floor((ms / (1000 * 60 * 60)) % 60)); const hours = showWith0(Math.floor(((ms / (1000 * 60 * 60)) % 60) % 24));
const minutes = showWith0(Math.floor((ms / (1000 * 60)) % 60)); const minutes = showWith0(Math.floor((ms / (1000 * 60)) % 60));
const seconds = showWith0(Math.floor((ms / 1000) % 60)); const seconds = showWith0(Math.floor((ms / 1000) % 60));
return showSeconds return showSeconds
? `${parseInt(hours) ? `${hours}${delim}` : ''}${minutes}${delim}${seconds}` ? `${
parseInt(hours) ? `${hours}${delim}` : `00${delim}`
}${minutes}${delim}${seconds}`
: `${parseInt(hours) ? `${hours}` : '00'}${delim}${minutes}`; : `${parseInt(hours) ? `${hours}` : '00'}${delim}${minutes}`;
}; };
@@ -85,7 +85,7 @@ export default function MessageControl() {
<div className={style.inputItems}> <div className={style.inputItems}>
<Editable <Editable
onChange={(event) => onChange={(event) =>
messageControl('pres-text', event.target.value) messageControl('pres-text', event)
} }
placeholder='only the presenter screens see this' placeholder='only the presenter screens see this'
className={style.inline} className={style.inline}
@@ -106,7 +106,7 @@ export default function MessageControl() {
<div className={style.inputItems}> <div className={style.inputItems}>
<Editable <Editable
onChange={(event) => onChange={(event) =>
messageControl('publ-text', event.target.value) messageControl('publ-text', event)
} }
placeholder='all screens will render this' placeholder='all screens will render this'
className={style.inline} className={style.inline}
@@ -127,7 +127,7 @@ export default function MessageControl() {
<div className={style.inputItems}> <div className={style.inputItems}>
<Editable <Editable
onChange={(event) => onChange={(event) =>
messageControl('lower-text', event.target.value) messageControl('lower-text', event)
} }
placeholder='visible in lower third screen' placeholder='visible in lower third screen'
className={style.inline} className={style.inline}
@@ -20,6 +20,7 @@ export default function PlaybackControl() {
const socket = useSocket(); const socket = useSocket();
const [playback, setPlayback] = useState(null); const [playback, setPlayback] = useState(null);
const [timer, setTimer] = useState({ const [timer, setTimer] = useState({
clock: null,
currentSeconds: null, currentSeconds: null,
startedAt: null, startedAt: null,
expectedFinish: null, expectedFinish: null,
@@ -1,39 +1,131 @@
import { useEffect, useState } from 'react';
import { useSocket } from '../../../app/context/socketContext';
import Countdown from '../../../common/components/countdown/Countdown';
import MyProgressBar from '../../../common/components/myProgressBar/MyProgressBar';
import { stringFromMillis } from '../../../common/dateConfig';
import style from './PresenterView.module.css'; import style from './PresenterView.module.css';
export default function PresenterView() { export default function PresenterView() {
const socket = useSocket();
const [pres, setPres] = useState({
text: '',
visible: false,
});
const [timer, setTimer] = useState({
clock: null,
currentSeconds: null,
durationSeconds: null,
startedAt: null,
expectedFinish: null,
});
const [titles, setTitles] = useState({
titleNow: '',
subtitleNow: '',
presenterNow: '',
titleNext: '',
subtitleNext: '',
presenterNext: '',
});
// Ask for update on load
useEffect(() => {
if (socket == null) return;
// Handle presenter messages
socket.on('messages-presenter', (data) => {
setPres({ ...data });
});
// Handle timer
socket.on('timer', (data) => {
setTimer({ ...data });
});
// Handle timer
socket.on('titles', (data) => {
setTitles({ ...data });
});
// Ask for up to data
socket.emit('get-presenter');
// Ask for up titles
socket.emit('get-titles');
// Clear listeners
return () => {
socket.off('messages-presenter');
socket.off('timer');
socket.off('titles');
};
}, [socket]);
// is there a next field?
let showNext = true;
if (!titles.titleNext && !titles.subtitleNext && !titles.presenterNext)
showNext = false;
// should show message overlay
let showOverlay = pres.visible && pres.text !== '';
// is timer finished
let finished = timer.currentSeconds <= 0;
// get clock
let clock = stringFromMillis(timer.clock);
return ( return (
<div className={style.container__gray}> <div
<div className={style.nowContainer}> className={
<div className={style.label}>Now</div> finished ? style.container__grayFinished : style.container__gray
<div className={style.title}>Are hamburguers real</div> }
<div className={style.subtitle}>A day in the life....</div> >
<div className={style.presenter}>Carlos Valente</div> <div
</div> className={
showOverlay ? style.messageOverlayActive : style.messageOverlay
<div className={style.nextContainer}> }
<div className={style.label}>Up Next</div> >
<div className={style.title}>Up to midnight</div> <div className={style.message}>{pres.text}</div>
<div className={style.subtitle}></div>
<div className={style.presenter}>Veronica</div>
</div>
{/* <div className={style.messageOverlayActive}>
<div className={style.message}>Remember to smile</div>
</div> */}
<div className={style.timerContainer}>
<div className={style.countdown}>01:03</div>
{/* <div className={style.finished}>TIME UP</div> */}
</div>
<div className={style.progress}>
<div className={style.progressed}></div>
</div> </div>
<div className={style.clockContainer}> <div className={style.clockContainer}>
<div className={style.label}>Time Now</div> <div className={style.label}>Time Now</div>
<div className={style.clock}>11:00:23</div> <div className={style.clock}>{clock}</div>
</div> </div>
<div className={style.timerContainer}>
{finished ? (
<div className={style.finished}>TIME UP</div>
) : (
<div className={style.countdown}>
<Countdown time={timer.currentSeconds} hideZeroHours />
</div>
)}
</div>
{!finished && (
<div className={style.progressContainer}>
<MyProgressBar
now={timer.currentSeconds}
complete={timer.durationSeconds}
/>
</div>
)}
<div className={style.nowContainer}>
<div className={style.label}>Now</div>
<div className={style.title}>{titles.titleNow}</div>
<div className={style.subtitle}>{titles.subtitleNow}</div>
<div className={style.presenter}>{titles.presenterNow}</div>
</div>
{showNext && (
<div className={style.nextContainer}>
<div className={style.label}>Next</div>
<div className={style.title}>{titles.titleNext}</div>
<div className={style.subtitle}>{titles.subtitleNext}</div>
<div className={style.presenter}>{titles.presenterNext}</div>
</div>
)}
</div> </div>
); );
} }
@@ -1,5 +1,11 @@
.container__gray, .container__gray,
.container__grayFinished { .container__grayFinished {
margin: 0;
padding: 0;
box-sizing: border-box; /* reset */
overflow: hidden;
width: 100%; /* restrict the page width to viewport */
background: radial-gradient(circle, #202020 0%, #121212 80%); background: radial-gradient(circle, #202020 0%, #121212 80%);
height: 100vh; height: 100vh;
color: #fffd; color: #fffd;
@@ -12,7 +18,9 @@
' prog prog prog prog prog' ' prog prog prog prog prog'
' now now .... next next'; ' now now .... next next';
gap: 1vw; gap: 1vw;
padding: 1vw;
} }
.container__graySimple, .container__graySimple,
.container__grayFinishedSimple { .container__grayFinishedSimple {
background: radial-gradient(circle, #202020 0%, #121212 80%); background: radial-gradient(circle, #202020 0%, #121212 80%);
@@ -76,40 +84,17 @@
} }
.finished { .finished {
font-size: 23vw; font-size: 18vw;
line-height: 18vw;
font-weight: 600; font-weight: 600;
color: #ff5353; color: #ff5353;
padding: 0;
} }
.countdown, .progressContainer {
.countdownBig {
letter-spacing: 4vw;
}
.countdown {
font-size: 23vw;
line-height: 23vw;
}
.countdownBig {
font-size: 30vw;
line-height: 30vw;
}
.progress {
grid-area: prog; grid-area: prog;
width: 80%; width: 80%;
margin: 0 auto; margin: 0 auto;
height: 2vh;
background-color: rgba(255, 255, 255, 0.13);
border-radius: 4px;
}
.progressed {
width: 30%;
height: 2vh;
background-color: rgba(255, 255, 255, 0.79);
border-radius: 4px;
} }
.container__grayFinished { .container__grayFinished {
@@ -130,13 +115,17 @@
background-color: rgba(0, 0, 0, 0.85); background-color: rgba(0, 0, 0, 0.85);
z-index: 2; z-index: 2;
opacity: 0; opacity: 0;
transition: 0.5s;
} }
.messageOverlayActive { .messageOverlayActive {
opacity: 1; opacity: 1;
transition: 0.5s;
} }
.message { .message {
width: inherit;
padding: 2vw;
position: absolute; position: absolute;
top: 50%; top: 50%;
left: 50%; left: 50%;
+30 -6
View File
@@ -21,15 +21,20 @@ class EventTimer extends Timer {
text: '', text: '',
visible: false, visible: false,
}; };
titles = { titles = {
title: '', titleNow: null,
subtitle: '', subtitleNow: null,
presenter: '', presenterNow: null,
titleNext: null,
subtitleNext: null,
presenterNext: null,
}; };
selectedEvent = null; selectedEvent = null;
selectedEventId = null; selectedEventId = null;
numEvents = null; numEvents = null;
_eventlist = null;
constructor() { constructor() {
super(); super();
@@ -77,9 +82,28 @@ class EventTimer extends Timer {
this.selectedEventId = e.id; this.selectedEventId = e.id;
// event titles // event titles
this.titles.title = e.title; this.titles.titleNow = e.title;
this.titles.subtitle = e.subtitle; this.titles.subtitleNow = e.subtitle;
this.titles.presenter = e.presenter; this.titles.presenterNow = e.presenter;
// assume tere is no next event
this.titles.titleNext = null;
this.titles.subtitleNext = null;
this.titles.presenterNext = null;
// look for event after
if (eventIndex < this.numEvents - 1) {
for (let i = eventIndex + 1 ; i < this.numEvents; i++) {
// check that is the right type
console.log(this._eventList[i]);
if (this._eventList[i].type === 'event') {
this.titles.titleNext = this._eventList[i].title;
this.titles.subtitleNext = this._eventList[i].subtitle;
this.titles.presenterNext = this._eventList[i].presenter;
break;
}
}
}
} }
print() { print() {
+5
View File
@@ -5,6 +5,7 @@
*/ */
class Timer { class Timer {
clock = null;
duration = null; duration = null;
current = null; current = null;
_finishAt = null; _finishAt = null;
@@ -21,6 +22,7 @@ class Timer {
setupWithSeconds(seconds, autoStart = false) { setupWithSeconds(seconds, autoStart = false) {
// aux // aux
const now = this._getCurrentTime(); const now = this._getCurrentTime();
this.clock = now;
// populate targets // populate targets
this.duration = seconds * 1000; this.duration = seconds * 1000;
@@ -43,6 +45,7 @@ class Timer {
update() { update() {
// get current time // get current time
const now = this._getCurrentTime(); const now = this._getCurrentTime();
this.clock = now;
// check playstate // check playstate
switch (this.state) { switch (this.state) {
@@ -101,7 +104,9 @@ class Timer {
this.update(); this.update();
return { return {
clock: this.clock,
currentSeconds: Timer.toSeconds(this.current), currentSeconds: Timer.toSeconds(this.current),
durationSeconds: Timer.toSeconds(this.duration),
expectedFinish: this._getExpectedFinish(), expectedFinish: this._getExpectedFinish(),
startedAt: this._startedAt, startedAt: this._startedAt,
}; };