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

[Rewards] Render home and explore view on a single page #27846

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,6 @@ export function App() {
return null
}

function renderMainView() {
switch (route) {
case routes.creators:
return <></>
case routes.explore:
return <ExploreView />
default:
return <HomeView />
}
}

function renderContent() {
if (loading) {
return (
Expand All @@ -213,7 +202,12 @@ export function App() {
return (
<>
<AppFrame>
{renderMainView()}
<div data-app-route={routes.home}>
<HomeView />
</div>
<div data-app-route={routes.explore}>
<ExploreView />
</div>
</AppFrame>
{renderModal()}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ export const style = scoped.css`
--leo-icon-color: ${color.icon.default};
}

main {
display: flex;
flex-direction: column;
gap: 32px;
}

&.panel-frame {
block-size: 100cqb;
display: flex;
Expand Down Expand Up @@ -54,6 +60,7 @@ export const style = scoped.css`
overflow: auto;
scrollbar-width: none;
padding: 0 16px 16px;
position: relative;
}

footer {
Expand Down Expand Up @@ -126,6 +133,7 @@ export const style = scoped.css`
padding: 16px;
overflow: hidden auto;
scrollbar-gutter: stable;
position: relative;
}

main {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,30 @@ function getCurrentNavRoute(route: string) {
return routes.home
}

function scrollRouteContentIntoView(route: string) {
const elem = document.querySelector(`[data-app-route="${route}"]`)
if (!(elem instanceof HTMLElement) || !elem.offsetParent) {
return
}
elem.offsetParent.scrollTo({
top: elem.offsetTop - 16,
left: 0,
behavior: 'smooth'
})
}

function NavList() {
const { getString } = useLocaleContext()
const current = getCurrentNavRoute(useRoute())
const router = React.useContext(RouterContext)

function onLinkClick(event: React.MouseEvent<HTMLAnchorElement>) {
event.preventDefault()
router.setRoute(event.currentTarget.getAttribute('href') ?? '')
const route = event.currentTarget.getAttribute('href')
if (route) {
router.setRoute(route)
scrollRouteContentIntoView(route)
}
}

function renderLink(route: string, icon: string, text: string) {
Expand Down Expand Up @@ -195,6 +211,11 @@ function PageFrame(props: Props) {

export function AppFrame(props: Props) {
const viewType = useBreakpoint()
const route = useRoute()

React.useEffect(() => {
scrollRouteContentIntoView(route)
}, [])

if (viewType === 'narrow') {
return <PanelFrame {...props} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export const style = scoped.css`
}
}

h3 {
padding: 8px;
}

h4 {
padding: 16px;
display: flex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import * as React from 'react'
import ProgressRing from '@brave/leo/react/progressRing'

import { useLocaleContext } from '../../lib/locale_strings'
import { useAppState } from '../../lib/app_model_context'
import { useBreakpoint } from '../../lib/breakpoint'
import { BatUtilityCard } from './bat_utility_card'
Expand All @@ -15,6 +16,7 @@ import { MerchStoreCard } from './merch_store_card'
import { style } from './explore_view.style'

export function ExploreView() {
const { getString } = useLocaleContext()
const viewType = useBreakpoint()
const [cards] = useAppState((state) => [state.cards])

Expand All @@ -31,6 +33,7 @@ export function ExploreView() {
if (viewType === 'double') {
return (
<div {...style}>
<h3>{getString('navigationExploreLabel')}</h3>
<div className='columns'>
<div>
<MerchStoreCard />
Expand All @@ -46,6 +49,7 @@ export function ExploreView() {

return (
<div {...style}>
<h3>{getString('navigationExploreLabel')}</h3>
<MerchStoreCard />
<BatUtilityCard />
<CommunityCard />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Router {
}

export const RouterContext = React.createContext<Router>(new Router({
get: () => location.pathname.toLocaleLowerCase().replace(/\/$/, ''),
get: () => location.pathname.toLocaleLowerCase().replace(/\/$/, '') || '/',
set: (route) => history.pushState(null, '', route),
replace: (route) => history.replaceState(null, '', route)
}))
Expand Down
Loading