ea9c7a4a27
* Refactor CommentBadge * Refactor livestreamComment component * Refactor and split livestreamComment CSS * Refactor livestreamComments component * Refactor and split livestreamComments CSS * Remove never used spinner * Refactor livestream Page * Refactor page component * Refactor livestreamLayout component * Break apart livestreamComments into separate sibling components - This helps separating LivestreamComments to deal with only the comments, and the LivestreamLayout to be used for its own Page as a Popout option, and also for a layered approach for mobile * Create Popout Chat Page, Add Popout Chat Menu Option * Add Hide Chat option * sockety improvements * Websocket changes Co-authored-by: Thomas Zarebczan <thomas.zarebczan@gmail.com>
56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
// @flow
|
|
import 'scss/component/_livestream-chat.scss';
|
|
|
|
import LivestreamComment from 'component/livestreamComment';
|
|
import React from 'react';
|
|
|
|
// 30 sec timestamp refresh timer
|
|
const UPDATE_TIMESTAMP_MS = 30 * 1000;
|
|
|
|
type Props = {
|
|
commentsToDisplay: Array<Comment>,
|
|
fetchingComments: boolean,
|
|
uri: string,
|
|
};
|
|
|
|
export default function LivestreamComments(props: Props) {
|
|
const { commentsToDisplay, fetchingComments, uri } = props;
|
|
|
|
const [forceUpdate, setForceUpdate] = React.useState(0);
|
|
|
|
const now = new Date();
|
|
const shouldRefreshTimestamp =
|
|
commentsToDisplay &&
|
|
commentsToDisplay.some((comment) => {
|
|
const { timestamp } = comment;
|
|
const timePosted = timestamp * 1000;
|
|
|
|
// 1000 * 60 seconds * 60 minutes === less than an hour old
|
|
return now - timePosted < 1000 * 60 * 60;
|
|
});
|
|
|
|
// Refresh timestamp on timer
|
|
React.useEffect(() => {
|
|
if (shouldRefreshTimestamp) {
|
|
const timer = setTimeout(() => {
|
|
setForceUpdate(Date.now());
|
|
}, UPDATE_TIMESTAMP_MS);
|
|
|
|
return () => clearTimeout(timer);
|
|
}
|
|
// forceUpdate will re-activate the timer or else it will only refresh once
|
|
}, [shouldRefreshTimestamp, forceUpdate]);
|
|
|
|
/* top to bottom comment display */
|
|
if (!fetchingComments && commentsToDisplay && commentsToDisplay.length > 0) {
|
|
return (
|
|
<div className="livestream__comments">
|
|
{commentsToDisplay.map((comment) => (
|
|
<LivestreamComment comment={comment} key={comment.comment_id} uri={uri} forceUpdate={forceUpdate} />
|
|
))}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return <div className="main--empty" style={{ flex: 1 }} />;
|
|
}
|