2023-05-02 05:45:27 +03:00
|
|
|
/* eslint-disable react/no-danger */
|
2022-10-25 08:23:01 +03:00
|
|
|
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
2022-10-09 01:05:52 +03:00
|
|
|
import { Divider } from 'antd';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { FC } from 'react';
|
2022-10-09 01:05:52 +03:00
|
|
|
import formatDistanceToNow from 'date-fns/formatDistanceToNow';
|
2023-01-16 09:31:36 +03:00
|
|
|
import dynamic from 'next/dynamic';
|
2023-02-09 05:50:58 +03:00
|
|
|
import classNames from 'classnames';
|
2022-09-07 10:00:28 +03:00
|
|
|
import styles from './OfflineBanner.module.scss';
|
2022-05-26 08:52:27 +03:00
|
|
|
|
2023-01-16 09:31:36 +03:00
|
|
|
// Lazy loaded components
|
|
|
|
|
|
|
|
const ClockCircleOutlined = dynamic(() => import('@ant-design/icons/ClockCircleOutlined'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
export type OfflineBannerProps = {
|
2022-10-09 01:05:52 +03:00
|
|
|
streamName: string;
|
|
|
|
customText?: string;
|
|
|
|
lastLive?: Date;
|
|
|
|
notificationsEnabled: boolean;
|
|
|
|
fediverseAccount?: string;
|
2023-01-29 06:26:12 +03:00
|
|
|
showsHeader?: boolean;
|
2022-10-09 01:05:52 +03:00
|
|
|
onNotifyClick?: () => void;
|
2022-10-25 08:23:01 +03:00
|
|
|
onFollowClick?: () => void;
|
2023-02-09 05:50:58 +03:00
|
|
|
className?: string;
|
2022-09-07 10:00:28 +03:00
|
|
|
};
|
2022-05-26 08:52:27 +03:00
|
|
|
|
2022-10-09 01:05:52 +03:00
|
|
|
export const OfflineBanner: FC<OfflineBannerProps> = ({
|
|
|
|
streamName,
|
|
|
|
customText,
|
|
|
|
lastLive,
|
|
|
|
notificationsEnabled,
|
|
|
|
fediverseAccount,
|
2023-01-29 06:26:12 +03:00
|
|
|
showsHeader = true,
|
2022-10-09 01:05:52 +03:00
|
|
|
onNotifyClick,
|
2022-10-25 08:23:01 +03:00
|
|
|
onFollowClick,
|
2023-02-09 05:50:58 +03:00
|
|
|
className,
|
2022-10-09 01:05:52 +03:00
|
|
|
}) => {
|
|
|
|
let text;
|
|
|
|
if (customText) {
|
|
|
|
text = customText;
|
|
|
|
} else if (!customText && notificationsEnabled && fediverseAccount) {
|
2022-10-25 08:23:01 +03:00
|
|
|
text = (
|
|
|
|
<span>
|
|
|
|
This stream is offline. You can{' '}
|
|
|
|
<span role="link" tabIndex={0} className={styles.actionLink} onClick={onNotifyClick}>
|
|
|
|
be notified
|
|
|
|
</span>{' '}
|
|
|
|
the next time {streamName} goes live or{' '}
|
|
|
|
<span role="link" tabIndex={0} className={styles.actionLink} onClick={onFollowClick}>
|
|
|
|
follow
|
|
|
|
</span>{' '}
|
|
|
|
{fediverseAccount} on the Fediverse.
|
|
|
|
</span>
|
|
|
|
);
|
2022-10-09 01:05:52 +03:00
|
|
|
} else if (!customText && notificationsEnabled) {
|
2022-10-25 08:23:01 +03:00
|
|
|
text = (
|
|
|
|
<span>
|
|
|
|
This stream is offline.{' '}
|
|
|
|
<span role="link" tabIndex={0} className={styles.actionLink} onClick={onNotifyClick}>
|
|
|
|
Be notified
|
|
|
|
</span>{' '}
|
|
|
|
the next time {streamName} goes live.
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
} else if (!customText && fediverseAccount) {
|
|
|
|
text = (
|
|
|
|
<span>
|
|
|
|
This stream is offline.{' '}
|
|
|
|
<span role="link" tabIndex={0} className={styles.actionLink} onClick={onFollowClick}>
|
|
|
|
Follow
|
|
|
|
</span>{' '}
|
|
|
|
{fediverseAccount} on the Fediverse to see the next time {streamName} goes live.
|
|
|
|
</span>
|
|
|
|
);
|
2022-10-09 01:05:52 +03:00
|
|
|
} else {
|
|
|
|
text = `This stream is offline. Check back soon!`;
|
|
|
|
}
|
2022-05-26 08:52:27 +03:00
|
|
|
|
2022-10-09 01:05:52 +03:00
|
|
|
return (
|
2023-02-09 05:50:58 +03:00
|
|
|
<div id="offline-banner" className={classNames(styles.outerContainer, className)}>
|
2022-10-09 01:05:52 +03:00
|
|
|
<div className={styles.innerContainer}>
|
2023-01-29 06:26:12 +03:00
|
|
|
{showsHeader && (
|
|
|
|
<>
|
|
|
|
<div className={styles.header}>{streamName}</div>
|
|
|
|
<Divider className={styles.separator} />
|
|
|
|
</>
|
|
|
|
)}
|
2023-05-02 05:45:27 +03:00
|
|
|
{customText ? (
|
|
|
|
<div className={styles.bodyText} dangerouslySetInnerHTML={{ __html: text }} />
|
|
|
|
) : (
|
|
|
|
<div className={styles.bodyText}>{text}</div>
|
|
|
|
)}
|
|
|
|
|
2022-10-09 01:05:52 +03:00
|
|
|
{lastLive && (
|
|
|
|
<div className={styles.lastLiveDate}>
|
|
|
|
<ClockCircleOutlined className={styles.clockIcon} />
|
|
|
|
{`Last live ${formatDistanceToNow(new Date(lastLive))} ago.`}
|
|
|
|
</div>
|
|
|
|
)}
|
2022-05-26 08:52:27 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-10-09 01:05:52 +03:00
|
|
|
);
|
|
|
|
};
|