From 8ee9be5d883347403cc047fc543fa3b17c324680 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Sat, 10 Sep 2022 20:03:58 -0700 Subject: [PATCH] Support disabled chat. Closes #1979 --- web/components/layouts/Main.tsx | 3 +- web/components/stores/ClientConfigStore.tsx | 9 ++++-- web/components/ui/Content/Content.tsx | 31 +++++++++++++-------- web/components/ui/Header/Header.tsx | 11 ++++++-- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/web/components/layouts/Main.tsx b/web/components/layouts/Main.tsx index 579f5f3b7e..97716076b4 100644 --- a/web/components/layouts/Main.tsx +++ b/web/components/layouts/Main.tsx @@ -24,6 +24,7 @@ export const Main: FC = () => { const fatalError = useRecoilValue(fatalErrorStateAtom); const layoutRef = useRef(null); + const { chatDisabled } = clientConfig; useEffect(() => { setupNoLinkReferrer(layoutRef.current); @@ -98,7 +99,7 @@ export const Main: FC = () => { -
+
{fatalError && ( diff --git a/web/components/stores/ClientConfigStore.tsx b/web/components/stores/ClientConfigStore.tsx index 21821e8652..e8dcab8307 100644 --- a/web/components/stores/ClientConfigStore.tsx +++ b/web/components/stores/ClientConfigStore.tsx @@ -180,7 +180,7 @@ export const ClientConfigStore: FC = () => { const setChatUserId = useSetRecoilState(chatUserIdAtom); const setChatAuthenticated = useSetRecoilState(chatAuthenticatedAtom); const setIsChatModerator = useSetRecoilState(isChatModeratorAtom); - const setClientConfig = useSetRecoilState(clientConfigStateAtom); + const [clientConfig, setClientConfig] = useRecoilState(clientConfigStateAtom); const setServerStatus = useSetRecoilState(serverStatusState); const setClockSkew = useSetRecoilState(clockSkewAtom); const [chatMessages, setChatMessages] = useRecoilState(chatMessagesAtom); @@ -375,6 +375,12 @@ export const ClientConfigStore: FC = () => { } }, [hasLoadedStatus, hasLoadedConfig]); + useEffect(() => { + if (!clientConfig.chatDisabled && accessToken && hasLoadedConfig) { + startChat(); + } + }, [hasLoadedConfig, accessToken]); + useEffect(() => { updateClientConfig(); handleUserRegistration(); @@ -392,7 +398,6 @@ export const ClientConfigStore: FC = () => { } getChatHistory(); - startChat(); }, [accessToken]); useEffect(() => { diff --git a/web/components/ui/Content/Content.tsx b/web/components/ui/Content/Content.tsx index d3e531fb11..a923817274 100644 --- a/web/components/ui/Content/Content.tsx +++ b/web/components/ui/Content/Content.tsx @@ -9,6 +9,7 @@ import { chatMessagesAtom, chatDisplayNameAtom, chatUserIdAtom, + isChatAvailableSelector, isChatVisibleSelector, appStateAtom, isOnlineSelector, @@ -77,18 +78,21 @@ const MobileContent = ({ messages, chatDisplayName, chatUserId, + showChat, }) => (
- - {' '} - + {showChat && ( + + + + )} { const appState = useRecoilValue(appStateAtom); const clientConfig = useRecoilValue(clientConfigStateAtom); const isChatVisible = useRecoilValue(isChatVisibleSelector); + const isChatAvailable = useRecoilValue(isChatAvailableSelector); + const [isMobile, setIsMobile] = useRecoilState(isMobileAtom); const messages = useRecoilValue(chatMessagesAtom); const online = useRecoilValue(isOnlineSelector); @@ -127,6 +133,7 @@ export const Content: FC = () => { tags, externalActions, offlineMessage, + chatDisabled, } = clientConfig; const [showNotifyReminder, setShowNotifyReminder] = useState(false); const [showNotifyPopup, setShowNotifyPopup] = useState(false); @@ -177,6 +184,7 @@ export const Content: FC = () => { } const offlineTitle = !appState.appLoading && `${name} is currently offline`; + const showChat = !chatDisabled && isChatAvailable && isChatVisible; return (
@@ -230,6 +238,7 @@ export const Content: FC = () => { messages={messages} chatDisplayName={chatDisplayName} chatUserId={chatUserId} + showChat={showChat} /> ) : ( { /> )}
- {isChatVisible && !isMobile && } + {showChat && !isMobile && } - {(!isMobile || !isChatVisible) &&
} + {(!isMobile || !showChat) &&
}
); diff --git a/web/components/ui/Header/Header.tsx b/web/components/ui/Header/Header.tsx index 96e5f2bf18..43812fc25b 100644 --- a/web/components/ui/Header/Header.tsx +++ b/web/components/ui/Header/Header.tsx @@ -9,16 +9,21 @@ const { Header: AntHeader } = Layout; export type HeaderComponentProps = { name: string; chatAvailable: boolean; + chatDisabled: boolean; }; -export const Header: FC = ({ name = 'Your stream title', chatAvailable }) => ( +export const Header: FC = ({ + name = 'Your stream title', + chatAvailable, + chatDisabled, +}) => (
{name}
- {chatAvailable && } - {!chatAvailable && ( + {chatAvailable && !chatDisabled && } + {!chatAvailable && !chatDisabled && ( Chat offline