Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing go back button on squads page #2906

Merged
merged 4 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/shared/src/components/MainLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { MarketingCtaVariant } from './cards/MarketingCta/common';
import { useLazyModal } from '../hooks/useLazyModal';
import { LazyModal } from './modals/common/types';
import { useMobileUxExperiment } from '../hooks/useMobileUxExperiment';
import { GoBackHeaderMobile } from './post/GoBackHeaderMobile';

export interface MainLayoutProps
extends Omit<MainLayoutHeaderProps, 'onMobileSidebarToggle'>,
Expand All @@ -57,6 +58,7 @@ export interface MainLayoutProps
enableSearch?: () => void;
onNavTabClick?: (tab: string) => void;
onShowDndClick?: () => unknown;
canGoBack?: string;
}

const feeds = Object.values(SharedFeedPage);
Expand All @@ -76,6 +78,7 @@ function MainLayoutComponent({
onNavTabClick,
enableSearch,
onShowDndClick,
canGoBack,
}: MainLayoutProps): ReactElement {
const router = useRouter();
const { trackEvent } = useContext(AnalyticsContext);
Expand Down Expand Up @@ -205,6 +208,7 @@ function MainLayoutComponent({

return (
<div className="antialiased">
{canGoBack && <GoBackHeaderMobile />}
{customBanner}
{isBannerAvailable && <PromotionalBanner />}
<InAppNotificationElement />
Expand Down
17 changes: 11 additions & 6 deletions packages/shared/src/components/post/BasePostContent.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import dynamic from 'next/dynamic';
import React, { ReactElement } from 'react';
import classNames from 'classnames';
import PostNavigation from './PostNavigation';
import PostEngagements from './PostEngagements';
import { BasePostContentProps } from './common';
import { PostContentHeaderMobile } from './PostContentHeaderMobile';
import { GoBackHeaderMobile } from './GoBackHeaderMobile';
import { PostHeaderActions } from './PostHeaderActions';

const ShareModal = dynamic(
() => import(/* webpackChunkName: "shareModal" */ '../modals/ShareModal'),
Expand Down Expand Up @@ -37,11 +39,14 @@ export function BasePostContent({
return (
<>
{isPostPage ? (
<PostContentHeaderMobile
post={post}
className={className.header}
onReadArticle={navigationProps.onReadArticle}
/>
<GoBackHeaderMobile className={classNames(className.header, '-mx-4')}>
<PostHeaderActions
post={post}
className="ml-auto"
contextMenuId="post-page-header-actions"
onReadArticle={navigationProps.onReadArticle}
/>
</GoBackHeaderMobile>
) : (
<PostNavigation {...navigationProps} className={className.navigation} />
)}
Expand Down
53 changes: 53 additions & 0 deletions packages/shared/src/components/post/GoBackHeaderMobile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React, { PropsWithChildren, ReactElement } from 'react';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just a renamed file.

import { useRouter } from 'next/router';
import classNames from 'classnames';
import { Button, ButtonSize, ButtonVariant } from '../buttons/Button';
import { ArrowIcon } from '../icons';
import { WithClassNameProps } from '../utilities';
import { isDevelopment } from '../../lib/constants';

const checkSameSite = () => {
const referrer = globalThis?.document?.referrer;
const origin = globalThis?.window?.location.origin;

if (!referrer) {
return true; // empty referrer means you are from the same site
}

return (
referrer === origin || origin === referrer.substring(0, referrer.length - 1) // remove trailing slash
);
};

export function GoBackHeaderMobile({
children,
className,
}: PropsWithChildren<WithClassNameProps>): ReactElement {
const router = useRouter();
const canGoBack =
!!globalThis?.history?.length && (checkSameSite() || isDevelopment);

if (!canGoBack && !children) {
return null;
}

return (
<span
className={classNames(
'flex flex-row items-center border-b border-border-subtlest-tertiary px-4 py-2 tablet:hidden',
className,
)}
>
{canGoBack && (
<Button
icon={<ArrowIcon className="-rotate-90" />}
size={ButtonSize.Small}
variant={ButtonVariant.Tertiary}
onClick={router.back}
className={!canGoBack && 'invisible'}
/>
)}
{children}
</span>
);
}
54 changes: 0 additions & 54 deletions packages/shared/src/components/post/PostContentHeaderMobile.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion packages/webapp/pages/squads/[handle]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ const SquadPage = ({
};

SquadPage.getLayout = getLayout;
SquadPage.layoutProps = mainFeedLayoutProps;
SquadPage.layoutProps = { ...mainFeedLayoutProps, canGoBack: true };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did only the squad page and dev card need this addition?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Based from their feedback.


export default SquadPage;

Expand Down