open livestream channel create redirect in new tab

so users can keep the stream going while they do sign up stuff
This commit is contained in:
Sean Yesmunt 2021-04-03 00:28:54 -04:00
parent bb56de1d4f
commit 650ce42dc0
2 changed files with 24 additions and 11 deletions

View file

@ -58,7 +58,10 @@ export function CommentCreate(props: Props) {
claimIsMine, claimIsMine,
} = props; } = props;
const buttonref: ElementRef<any> = React.useRef(); const buttonref: ElementRef<any> = React.useRef();
const { push } = useHistory(); const {
push,
location: { pathname },
} = useHistory();
const { claim_id: claimId } = claim; const { claim_id: claimId } = claim;
const [commentValue, setCommentValue] = React.useState(''); const [commentValue, setCommentValue] = React.useState('');
const [lastCommentTime, setLastCommentTime] = React.useState(); const [lastCommentTime, setLastCommentTime] = React.useState();
@ -101,9 +104,7 @@ export function CommentCreate(props: Props) {
: (lastCommentTime - Date.now()) / 1000 + COMMENT_SLOW_MODE_SECONDS; : (lastCommentTime - Date.now()) / 1000 + COMMENT_SLOW_MODE_SECONDS;
if (livestream && !claimIsMine && timeUntilCanComment > 0) { if (livestream && !claimIsMine && timeUntilCanComment > 0) {
toast( toast(__('Slowmode is on. You can comment again in %time% seconds.', { time: Math.ceil(timeUntilCanComment) }));
__('Slowmode is on. You can comment again in %time% seconds.', { time: Math.ceil(timeUntilCanComment) })
);
return; return;
} }
@ -128,7 +129,17 @@ export function CommentCreate(props: Props) {
if (!hasChannels) { if (!hasChannels) {
return ( return (
<div role="button" onClick={() => push(`/$/${PAGES.CHANNEL_NEW}`)}> <div
role="button"
onClick={() => {
const pathPlusRedirect = `/$/${PAGES.CHANNEL_NEW}?redirect=${pathname}`;
if (livestream) {
window.open(pathPlusRedirect);
} else {
push(pathPlusRedirect);
}
}}
>
<FormField <FormField
type="textarea" type="textarea"
name={'comment_signup_prompt'} name={'comment_signup_prompt'}

View file

@ -93,6 +93,8 @@ type PrivateRouteProps = Props & {
function PrivateRoute(props: PrivateRouteProps) { function PrivateRoute(props: PrivateRouteProps) {
const { component: Component, isAuthenticated, ...rest } = props; const { component: Component, isAuthenticated, ...rest } = props;
const urlSearchParams = new URLSearchParams(props.location.search);
const redirectUrl = urlSearchParams.get('redirect');
return ( return (
<Route <Route
{...rest} {...rest}
@ -100,7 +102,7 @@ function PrivateRoute(props: PrivateRouteProps) {
isAuthenticated || !IS_WEB ? ( isAuthenticated || !IS_WEB ? (
<Component {...props} /> <Component {...props} />
) : ( ) : (
<Redirect to={`/$/${PAGES.AUTH}?redirect=${props.location.pathname}`} /> <Redirect to={`/$/${PAGES.AUTH}?redirect=${redirectUrl || props.location.pathname}`} />
) )
} }
/> />
@ -122,7 +124,7 @@ function AppRouter(props: Props) {
setReferrer, setReferrer,
homepageData, homepageData,
} = props; } = props;
const { entries } = history; const { entries, listen, action: historyAction } = history;
const entryIndex = history.index; const entryIndex = history.index;
const urlParams = new URLSearchParams(search); const urlParams = new URLSearchParams(search);
const resetScroll = urlParams.get('reset_scroll'); 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" // For people arriving at settings page from deeplinks, know whether they can "go back"
useEffect(() => { useEffect(() => {
const unlisten = history.listen((location, action) => { const unlisten = listen((location, action) => {
if (action === 'PUSH') { if (action === 'PUSH') {
if (!hasNavigated && setHasNavigated) setHasNavigated(); if (!hasNavigated && setHasNavigated) setHasNavigated();
} }
}); });
return unlisten; return unlisten;
}, [hasNavigated, setHasNavigated]); }, [listen, hasNavigated, setHasNavigated]);
useEffect(() => { useEffect(() => {
if (!hasNavigated && hasUnclaimedRefereeReward && !isAuthenticated) { if (!hasNavigated && hasUnclaimedRefereeReward && !isAuthenticated) {
@ -179,7 +181,7 @@ function AppRouter(props: Props) {
useEffect(() => { useEffect(() => {
if (!hasLinkedCommentInUrl) { if (!hasLinkedCommentInUrl) {
if (hash && history.action === 'PUSH') { if (hash && historyAction === 'PUSH') {
const id = hash.replace('#', ''); const id = hash.replace('#', '');
const element = document.getElementById(id); const element = document.getElementById(id);
if (element) { if (element) {
@ -189,7 +191,7 @@ function AppRouter(props: Props) {
window.scrollTo(0, currentScroll); 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 // 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 // We have to redirect here because if we redirect on the server, it might get encoded again