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,
} = props;
const buttonref: ElementRef<any> = 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 (
<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
type="textarea"
name={'comment_signup_prompt'}

View file

@ -93,6 +93,8 @@ type PrivateRouteProps = Props & {
function PrivateRoute(props: PrivateRouteProps) {
const { component: Component, isAuthenticated, ...rest } = props;
const urlSearchParams = new URLSearchParams(props.location.search);
const redirectUrl = urlSearchParams.get('redirect');
return (
<Route
{...rest}
@ -100,7 +102,7 @@ function PrivateRoute(props: PrivateRouteProps) {
isAuthenticated || !IS_WEB ? (
<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,
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