Skip to content

Commit a336545

Browse files
Modify TopNav behavior to allow for page back
1 parent 49576a8 commit a336545

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

apps/next/pages/account/rewards/activity.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Head from 'next/head'
33
import { userProtectedGetSSP } from 'utils/userProtected'
44
import type { NextPageWithLayout } from 'next-app/pages/_app'
55
import { HomeLayout } from 'app/features/home/layout.web'
6-
import { ButtonOption, TopNav } from 'app/components/TopNav'
6+
import { TopNav } from 'app/components/TopNav'
77
import { MobileButtonRowLayout } from 'app/components/MobileButtonRowLayout'
88

99
export const Page: NextPageWithLayout = () => {
@@ -21,9 +21,7 @@ export const getServerSideProps = userProtectedGetSSP()
2121

2222
Page.getLayout = (children) => (
2323
<MobileButtonRowLayout.ActivityRewards>
24-
<HomeLayout
25-
TopNav={<TopNav header="Activity Rewards" showLogo button={ButtonOption.PROFILE} />}
26-
>
24+
<HomeLayout TopNav={<TopNav header="Activity Rewards" backToBasePath={false} />}>
2725
{children}
2826
</HomeLayout>
2927
</MobileButtonRowLayout.ActivityRewards>

apps/next/pages/account/rewards/index.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Head from 'next/head'
33
import { userProtectedGetSSP } from 'utils/userProtected'
44
import type { NextPageWithLayout } from 'next-app/pages/_app'
55
import { HomeLayout } from 'app/features/home/layout.web'
6-
import { ButtonOption, TopNav } from 'app/components/TopNav'
6+
import { TopNav } from 'app/components/TopNav'
77

88
export const Page: NextPageWithLayout = () => {
99
return (
@@ -18,9 +18,7 @@ export const Page: NextPageWithLayout = () => {
1818

1919
export const getServerSideProps = userProtectedGetSSP()
2020
Page.getLayout = (children) => (
21-
<HomeLayout TopNav={<TopNav header="Rewards" button={ButtonOption.PROFILE} />}>
22-
{children}
23-
</HomeLayout>
21+
<HomeLayout TopNav={<TopNav header="Rewards" />}>{children}</HomeLayout>
2422
)
2523

2624
export default Page

packages/app/components/TopNav.tsx

+15-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ interface TopNavProps {
5151
* @default false
5252
*/
5353
noSubroute?: boolean
54+
/**
55+
* Whether the back arrow navigates to the base path
56+
* @default true
57+
*/
58+
backToBasePath?: boolean
5459
}
5560

5661
export function AvatarMenuButton({ profile }: { profile?: Tables<'profiles'> | null }) {
@@ -91,6 +96,7 @@ export function TopNav({
9196
showReferral = false,
9297
button,
9398
noSubroute = false,
99+
backToBasePath = true,
94100
}: TopNavProps) {
95101
const [queryParams, setRootParams] = useRootScreenParams()
96102
const path = usePathname()
@@ -118,7 +124,11 @@ export function TopNav({
118124
setRootParams({ ...queryParams, token: undefined })
119125
return
120126
}
121-
const newPath = parts.length > 1 ? parts.slice(0, 1).join('/') : '/'
127+
const newPath =
128+
backToBasePath && parts.length > 1
129+
? parts.slice(0, 1).join('/')
130+
: parts.slice(0, parts.length - 1).join('/')
131+
122132
if (path.includes('/settings')) {
123133
push(`/${newPath}?nav=settings`)
124134
return
@@ -128,7 +138,10 @@ export function TopNav({
128138
}
129139
//@todo Refactor this so we can put back arrows on screens that need it
130140
const isSubRoute =
131-
(!noSubroute && parts.length > 1) || path.includes('/secret-shop') || path.includes('/deposit')
141+
(!noSubroute && parts.length > 1) ||
142+
path.includes('/secret-shop') ||
143+
path.includes('/deposit') ||
144+
path.includes('/leaderboard')
132145

133146
const renderButton = () => {
134147
switch (true) {

0 commit comments

Comments
 (0)