From 6c2e25e5977d76da41b0df8d0bdcc7e060bfbae8 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Sat, 8 Oct 2022 15:05:52 -0700 Subject: [PATCH] Update the offline banner. Filed #2179 to discuss text --- web/components/ui/Content/Content.tsx | 21 +++--- .../OfflineBanner/OfflineBanner.module.scss | 22 ++++++- .../OfflineBanner/OfflineBanner.stories.tsx | 57 +++++++++++++--- .../ui/OfflineBanner/OfflineBanner.tsx | 66 ++++++++++++++----- web/pages/embed/video/index.tsx | 24 ++++--- 5 files changed, 147 insertions(+), 43 deletions(-) diff --git a/web/components/ui/Content/Content.tsx b/web/components/ui/Content/Content.tsx index 577b72de5..41905a10a 100644 --- a/web/components/ui/Content/Content.tsx +++ b/web/components/ui/Content/Content.tsx @@ -152,9 +152,14 @@ export const Content: FC = () => { externalActions, offlineMessage, chatDisabled, + federation, + notifications, } = clientConfig; const [showNotifyReminder, setShowNotifyReminder] = useState(false); const [showNotifyPopup, setShowNotifyPopup] = useState(false); + const { account: fediverseAccount } = federation; + const { browser: browserNotifications } = notifications; + const { enabled: browserNotificationsEnabled } = browserNotifications; const externalActionButtons = externalActions.map(action => ( @@ -195,13 +200,6 @@ export const Content: FC = () => { window.addEventListener('resize', checkIfMobile); }, []); - let offlineMessageBody = - !appState.appLoading && 'Please follow and ask to get notified when the stream is live.'; - if (offlineMessage && !appState.appLoading) { - offlineMessageBody = offlineMessage; - } - - const offlineTitle = !appState.appLoading && `${name} is currently offline`; const showChat = !chatDisabled && isChatAvailable && isChatVisible; return ( @@ -212,7 +210,14 @@ export const Content: FC = () => {
{online && } {!online && !appState.appLoading && ( - + setShowNotifyPopup(true)} + /> )} ; -const Template: ComponentStory = args => ; +const Template: ComponentStory = args => ( + + + +); -export const ExampleDefault = Template.bind({}); -ExampleDefault.args = { - name: 'Cool stream 42', - text: 'To get notifications when is back online you can follow or ask for notifications.', +export const ExampleDefaultWithNotifications = Template.bind({}); +ExampleDefaultWithNotifications.args = { + streamName: 'Cool stream 42', + notificationsEnabled: true, + lastLive: new Date(), }; -export const ExampleCustom = Template.bind({}); -ExampleCustom.args = { - name: 'Dull stream 31337', - text: 'This is some example offline text that a streamer can leave for a visitor of the page.', +export const ExampleDefaultWithDateAndFediverse = Template.bind({}); +ExampleDefaultWithDateAndFediverse.args = { + streamName: 'Dull stream 31337', + lastLive: new Date(), + notificationsEnabled: false, + fediverseAccount: 'streamer@coolstream.biz', +}; + +export const ExampleCustomWithDateAndNotifications = Template.bind({}); +ExampleCustomWithDateAndNotifications.args = { + streamName: 'Dull stream 31337', + customText: + 'This is some example offline text that a streamer can leave for a visitor of the page.', + lastLive: new Date(), + notificationsEnabled: true, +}; + +export const ExampleDefaultWithNotificationsAndFediverse = Template.bind({}); +ExampleDefaultWithNotificationsAndFediverse.args = { + streamName: 'Cool stream 42', + notificationsEnabled: true, + fediverseAccount: 'streamer@coolstream.biz', + lastLive: new Date(), +}; + +export const ExampleDefaultWithoutNotifications = Template.bind({}); +ExampleDefaultWithoutNotifications.args = { + streamName: 'Cool stream 42', + notificationsEnabled: false, + lastLive: new Date(), +}; + +export const ExampleCustomTextWithoutNotifications = Template.bind({}); +ExampleCustomTextWithoutNotifications.args = { + streamName: 'Dull stream 31337', + customText: + 'This is some example offline text that a streamer can leave for a visitor of the page.', }; diff --git a/web/components/ui/OfflineBanner/OfflineBanner.tsx b/web/components/ui/OfflineBanner/OfflineBanner.tsx index 43c93cfe0..9363b1b62 100644 --- a/web/components/ui/OfflineBanner/OfflineBanner.tsx +++ b/web/components/ui/OfflineBanner/OfflineBanner.tsx @@ -1,26 +1,58 @@ -import { Divider, Button } from 'antd'; -import { NotificationFilled } from '@ant-design/icons'; +import { Divider } from 'antd'; +import { ClockCircleOutlined } from '@ant-design/icons'; import { FC } from 'react'; +import formatDistanceToNow from 'date-fns/formatDistanceToNow'; import styles from './OfflineBanner.module.scss'; +import { FollowButton } from '../../action-buttons/FollowButton'; +import { NotifyButton } from '../../action-buttons/NotifyButton'; export type OfflineBannerProps = { - title: string; - text: string; + streamName: string; + customText?: string; + lastLive?: Date; + notificationsEnabled: boolean; + fediverseAccount?: string; + onNotifyClick?: () => void; }; -export const OfflineBanner: FC = ({ title, text }) => ( -
-
-
{title}
- -
{text}
+export const OfflineBanner: FC = ({ + streamName, + customText, + lastLive, + notificationsEnabled, + fediverseAccount, + onNotifyClick, +}) => { + let text; + if (customText) { + text = customText; + } else if (!customText && notificationsEnabled && fediverseAccount) { + text = `This stream is offline. You can be notified the next time ${streamName} goes live or follow ${fediverseAccount} on the Fediverse.`; + } else if (!customText && notificationsEnabled) { + text = `This stream is offline. Be notified the next time ${streamName} goes live.`; + } else { + text = `This stream is offline. Check back soon!`; + } -
- + return ( +
+
+
{streamName}
+ +
{text}
+ {lastLive && ( +
+ + {`Last live ${formatDistanceToNow(new Date(lastLive))} ago.`} +
+ )} + +
+ {fediverseAccount && } + + {notificationsEnabled && } +
-
-); + ); +}; diff --git a/web/pages/embed/video/index.tsx b/web/pages/embed/video/index.tsx index c94d1fb7c..0855cc601 100644 --- a/web/pages/embed/video/index.tsx +++ b/web/pages/embed/video/index.tsx @@ -18,7 +18,7 @@ export default function VideoEmbed() { const { name } = clientConfig; - // const { extraPageContent, version, socialHandles, name, title, tags } = clientConfig; + const { offlineMessage } = clientConfig; const { viewerCount, lastConnectTime, lastDisconnectTime } = status; const online = useRecoilValue(isOnlineSelector); return ( @@ -26,13 +26,21 @@ export default function VideoEmbed() {
{online && } - {!online && }{' '} - + {!online && ( + + )} + {online && ( + + )}
);