This commit is contained in:
cv
2021-06-10 21:09:17 +02:00
5 changed files with 66 additions and 7 deletions
+1
View File
@@ -16,6 +16,7 @@
"react": "^17.0.1",
"react-beautiful-dnd": "^13.1.0",
"react-dom": "^17.0.1",
"react-fast-compare": "^3.2.0",
"react-icons": "^4.2.0",
"react-qr-code": "^1.1.1",
"react-query": "^3.13.5",
@@ -33,6 +33,7 @@ export default function LowerClean(props) {
// calculate transition times
useEffect(() => {});
// Format messages
const showLowerMessage = lower.text !== '' && lower.visible;
@@ -30,6 +30,10 @@ export default function LowerLines(props) {
return () => clearTimeout(timeout);
}, [options.fadeOut, options.transitionIn, defaults.transitionIn]);
useEffect(() => {
setShowLower(title.showNow);
}, [title.showNow]);
// Format messages
const showLowerMessage = lower.text !== '' && lower.visible;
@@ -1,8 +1,27 @@
import { useEffect, useState } from 'react';
import { memo, useEffect, useState } from 'react';
import LowerClean from './LowerClean';
import LowerLines from './LowerLines';
const isEqual = require('react-fast-compare');
export default function Lower(props) {
const areEqual = (prevProps, nextProps) => {
return (
isEqual(prevProps.title, nextProps.title) &&
isEqual(prevProps.lower && nextProps.lower)
);
};
const Lower = (props) => {
const { title } = props;
const [titles, setTitles] = useState({
titleNow: '',
titleNext: '',
subtitleNow: '',
subtitleNext: '',
presenterNow: '',
presenterNext: '',
showNow: false,
showNext: false,
});
const [preset, setPreset] = useState(1);
const [lowerOptions, setLowerOptions] = useState({});
@@ -11,6 +30,32 @@ export default function Lower(props) {
document.title = 'ontime - Lower Thirds';
}, []);
// reload if data changes
useEffect(() => {
// clear titles if necessary
// will trigger an animation out in the component
let timeout = null;
if (
title?.titleNow !== titles?.titleNow ||
title?.subtitleNow !== titles?.subtitleNow ||
title?.presenterNow !== titles?.presenterNow
) {
setTitles((t) => ({ ...t, showNow: false }));
const transitionTime = 2000;
timeout = setTimeout(() => {
setTitles(title);
}, transitionTime);
}
return () => {
if (timeout != null) {
clearTimeout(timeout);
}
};
}, [title.titleNow, title.subtitleNow, title.presenterNow]);
// TODO: sanitize data
// getting config from URL: preset, size, transition, bg, text, key
// eg. http://localhost:3000/lower?bg=ff2&text=f00&size=0.6&transition=5
@@ -77,10 +122,18 @@ export default function Lower(props) {
switch (preset) {
case 0:
return <LowerClean {...props} options={lowerOptions} />;
return (
<LowerClean lower={props.lower} title={titles} options={lowerOptions} />
);
case 1:
return <LowerLines {...props} options={lowerOptions} />;
return (
<LowerLines lower={props.lower} title={titles} options={lowerOptions} />
);
default:
return <LowerLines {...props} options={lowerOptions} />;
return (
<LowerLines lower={props.lower} title={titles} options={lowerOptions} />
);
}
}
};
export default memo(Lower, areEqual);
+1 -1
View File
@@ -10078,7 +10078,7 @@ react-error-overlay@^6.0.9:
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.9.tgz#3c743010c9359608c375ecd6bc76f35d93995b0a"
integrity sha512-nQTTcUu+ATDbrSD1BZHr5kgSD4oF8OFjxun8uAaL8RwPBacGBNPf/yAuVVdx17N8XNzRDMrZ9XcKZHCjPW+9ew==
react-fast-compare@3.2.0:
react-fast-compare@3.2.0, react-fast-compare@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.0.tgz#641a9da81b6a6320f270e89724fb45a0b39e43bb"
integrity sha512-rtGImPZ0YyLrscKI9xTpV8psd6I8VAtjKCzQDlzyDvqJA8XOW78TXYQwNRNd8g8JZnDu8q9Fu/1v4HPAVwVdHA==