Remove user menu when chat is not available

This commit is contained in:
Gabe Kangas
2022-05-26 11:08:37 -07:00
parent 715504eb69
commit b3407cbdea
4 changed files with 34 additions and 9 deletions

View File

@@ -1,18 +1,22 @@
import { Layout } from 'antd'; import { Layout } from 'antd';
import { useRecoilValue } from 'recoil'; import { useRecoilValue } from 'recoil';
import { ClientConfigStore, clientConfigStateAtom } from '../stores/ClientConfigStore'; import {
ClientConfigStore,
isChatAvailableSelector,
clientConfigStateAtom,
} from '../stores/ClientConfigStore';
import { Content, Header } from '../ui'; import { Content, Header } from '../ui';
import { ClientConfig } from '../../interfaces/client-config.model'; import { ClientConfig } from '../../interfaces/client-config.model';
function Main() { function Main() {
const clientConfig = useRecoilValue<ClientConfig>(clientConfigStateAtom); const clientConfig = useRecoilValue<ClientConfig>(clientConfigStateAtom);
const { name, title } = clientConfig; const { name, title } = clientConfig;
const isChatAvailable = useRecoilValue<boolean>(isChatAvailableSelector);
return ( return (
<> <>
<ClientConfigStore /> <ClientConfigStore />
<Layout> <Layout>
<Header name={title || name} /> <Header name={title || name} chatAvailable={isChatAvailable} />
<Content /> <Content />
</Layout> </Layout>
</> </>

View File

@@ -87,6 +87,15 @@ export const isChatVisibleSelector = selector({
}, },
}); });
export const isChatAvailableSelector = selector({
key: 'isChatAvailableSelector',
get: ({ get }) => {
const state: AppStateOptions = get(appStateAtom);
const accessToken: String = get(accessTokenAtom);
return accessToken && state.chatAvailable;
},
});
// We display in an "online/live" state as long as video is actively playing. // We display in an "online/live" state as long as video is actively playing.
// Even during the time where technically the server has said it's no longer // Even during the time where technically the server has said it's no longer
// live, however the last few seconds of video playback is still taking place. // live, however the last few seconds of video playback is still taking place.
@@ -182,7 +191,6 @@ export function ClientConfigStore() {
}; };
const resetAndReAuth = () => { const resetAndReAuth = () => {
console.log('!!!!! reauth!!');
setLocalStorage(ACCESS_TOKEN_KEY, ''); setLocalStorage(ACCESS_TOKEN_KEY, '');
setAccessToken(''); setAccessToken('');
handleUserRegistration(); handleUserRegistration();

View File

@@ -1,4 +1,4 @@
import { Layout } from 'antd'; import { Layout, Tag, Tooltip } from 'antd';
import { OwncastLogo, UserDropdown } from '../../common'; import { OwncastLogo, UserDropdown } from '../../common';
import s from './Header.module.scss'; import s from './Header.module.scss';
@@ -6,16 +6,22 @@ const { Header } = Layout;
interface Props { interface Props {
name: string; name: string;
chatAvailable: boolean;
} }
export default function HeaderComponent({ name = 'Your stream title' }: Props) { export default function HeaderComponent({ name = 'Your stream title', chatAvailable }: Props) {
return ( return (
<Header className={`${s.header}`}> <Header className={`${s.header}`}>
<div className={`${s.logo}`}> <div className={`${s.logo}`}>
<OwncastLogo variant="contrast" /> <OwncastLogo variant="contrast" />
<span>{name}</span> <span>{name}</span>
</div> </div>
<UserDropdown /> {chatAvailable && <UserDropdown />}
{!chatAvailable && (
<Tooltip title="Chat is available when the stream is live." placement="left">
<Tag color="processing">Chat offline</Tag>
</Tooltip>
)}
</Header> </Header>
); );
} }

View File

@@ -15,7 +15,14 @@ const Template: ComponentStory<typeof Header> = args => (
</RecoilRoot> </RecoilRoot>
); );
export const Example = Template.bind({}); export const ChatAvailable = Template.bind({});
Example.args = { ChatAvailable.args = {
name: 'Example Stream Name', name: 'Example Stream Name',
chatAvailable: true,
};
export const ChatNotAvailable = Template.bind({});
ChatNotAvailable.args = {
name: 'Example Stream Name',
chatAvailable: false,
}; };