diff --git a/ui/component/commentCreate/view.jsx b/ui/component/commentCreate/view.jsx index 53f20d0d8..2ffcab174 100644 --- a/ui/component/commentCreate/view.jsx +++ b/ui/component/commentCreate/view.jsx @@ -58,7 +58,10 @@ export function CommentCreate(props: Props) { claimIsMine, } = props; const buttonref: ElementRef = React.useRef(); - const { push } = useHistory(); + const { + push, + location: { pathname }, + } = useHistory(); const { claim_id: claimId } = claim; const [commentValue, setCommentValue] = React.useState(''); const [lastCommentTime, setLastCommentTime] = React.useState(); @@ -101,9 +104,7 @@ export function CommentCreate(props: Props) { : (lastCommentTime - Date.now()) / 1000 + COMMENT_SLOW_MODE_SECONDS; if (livestream && !claimIsMine && timeUntilCanComment > 0) { - toast( - __('Slowmode is on. You can comment again in %time% seconds.', { time: Math.ceil(timeUntilCanComment) }) - ); + toast(__('Slowmode is on. You can comment again in %time% seconds.', { time: Math.ceil(timeUntilCanComment) })); return; } @@ -128,7 +129,17 @@ export function CommentCreate(props: Props) { if (!hasChannels) { return ( -
push(`/$/${PAGES.CHANNEL_NEW}`)}> +
{ + const pathPlusRedirect = `/$/${PAGES.CHANNEL_NEW}?redirect=${pathname}`; + if (livestream) { + window.open(pathPlusRedirect); + } else { + push(pathPlusRedirect); + } + }} + > ) : ( - + ) } /> @@ -122,7 +124,7 @@ function AppRouter(props: Props) { setReferrer, homepageData, } = props; - const { entries } = history; + const { entries, listen, action: historyAction } = history; const entryIndex = history.index; const urlParams = new URLSearchParams(search); const resetScroll = urlParams.get('reset_scroll'); @@ -134,13 +136,13 @@ function AppRouter(props: Props) { // For people arriving at settings page from deeplinks, know whether they can "go back" useEffect(() => { - const unlisten = history.listen((location, action) => { + const unlisten = listen((location, action) => { if (action === 'PUSH') { if (!hasNavigated && setHasNavigated) setHasNavigated(); } }); return unlisten; - }, [hasNavigated, setHasNavigated]); + }, [listen, hasNavigated, setHasNavigated]); useEffect(() => { if (!hasNavigated && hasUnclaimedRefereeReward && !isAuthenticated) { @@ -179,7 +181,7 @@ function AppRouter(props: Props) { useEffect(() => { if (!hasLinkedCommentInUrl) { - if (hash && history.action === 'PUSH') { + if (hash && historyAction === 'PUSH') { const id = hash.replace('#', ''); const element = document.getElementById(id); if (element) { @@ -189,7 +191,7 @@ function AppRouter(props: Props) { window.scrollTo(0, currentScroll); } } - }, [currentScroll, pathname, search, hash, resetScroll, hasLinkedCommentInUrl]); + }, [currentScroll, pathname, search, hash, resetScroll, hasLinkedCommentInUrl, historyAction]); // react-router doesn't decode pathanmes before doing the route matching check // We have to redirect here because if we redirect on the server, it might get encoded again