lbry-desktop/ui/component/claimPreviewReset/view.jsx

57 lines
1.7 KiB
React
Raw Normal View History

// @flow
import React from 'react';
import { SITE_HELP_EMAIL } from 'config';
import Button from 'component/button';
import { killStream } from '$web/src/livestreaming';
2021-11-09 19:02:34 +01:00
import watchLivestreamStatus from '$web/src/livestreaming/long-polling';
import 'scss/component/claim-preview-reset.scss';
type Props = {
channelId: string,
channelName: string,
claimIsMine: boolean,
doToast: ({ message: string, isError?: boolean }) => void,
};
const ClaimPreviewReset = (props: Props) => {
const { channelId, channelName, claimIsMine, doToast } = props;
2021-11-09 19:02:34 +01:00
const [isLivestreaming, setIsLivestreaming] = React.useState(false);
React.useEffect(() => {
if (!claimIsMine) return;
2021-11-09 19:02:34 +01:00
return watchLivestreamStatus(channelId, (state) => setIsLivestreaming(state));
}, [channelId, setIsLivestreaming, claimIsMine]);
2021-11-09 19:02:34 +01:00
if (!claimIsMine || !isLivestreaming) return null;
const handleClick = async () => {
try {
await killStream(channelId, channelName);
doToast({ message: __('Live stream successfully reset.'), isError: false });
} catch {
doToast({ message: __('There was an error resetting the live stream.'), isError: true });
}
};
return (
<p className={'claimPreviewReset'}>
<span className={'claimPreviewReset__hint'}>
{__(
"If you're having trouble starting a stream or if your stream shows that you're live but aren't, try a reset. If the problem persists, please reach out at %SITE_HELP_EMAIL%.",
{ SITE_HELP_EMAIL }
)}
</span>
<Button
button="primary"
label={__('Reset stream')}
className={'claimPreviewReset__button'}
onClick={handleClick}
/>
</p>
);
};
export default ClaimPreviewReset;