Skip to content

Commit

Permalink
fix: useQueryParams
Browse files Browse the repository at this point in the history
  • Loading branch information
wiktoriasalamon committed Jul 17, 2024
1 parent 0dd2f4d commit e0e74a9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 39 deletions.
56 changes: 30 additions & 26 deletions frontend/src/components/pages/LadderDetails/LadderDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,42 @@ import { LadderDetails } from './modules/LadderDetails';
import NextAdapterApp from 'next-query-params/app';
import { QueryParamProvider } from 'use-query-params';

export const LadderDetailsPage: React.FC<LadderDetailsProps> = ({ data, ladderSlug }) => {
const LadderDetailsPage: React.FC<LadderDetailsProps> = ({ data, ladderSlug }) => {
const { currentBand, handleLadderChange, tabsProps } = useLadderDetails(data?.bands);

if (!currentBand || !data || !data.bands[currentBand]) {
return null;
}

return (
<QueryParamProvider adapter={NextAdapterApp}>
<div>
<Breadcrumbs
breadcrumbs={[
{ label: 'CPF Library', href: routes.library.index, current: false },
{ label: data.ladderName, href: `${routes.library.index}/${ladderSlug}`, current: true },
]}
/>
{data && (
<section className="grid grid-cols-10 py-16">
<div className="col-span-2 mx-auto">
<LadderTabs {...tabsProps} ladderOnClick={handleLadderChange} />
</div>
<div className="col-span-7">
<LadderDetails
band={currentBand}
ladder={data.bands[currentBand]}
ladderName={data.ladderName}
ladderSlug={ladderSlug}
/>
</div>
</section>
)}
</div>
</QueryParamProvider>
<div>
<Breadcrumbs
breadcrumbs={[
{ label: 'CPF Library', href: routes.library.index, current: false },
{ label: data.ladderName, href: `${routes.library.index}/${ladderSlug}`, current: true },
]}
/>
{data && (
<section className="grid grid-cols-10 py-16">
<div className="col-span-2 mx-auto">
<LadderTabs {...tabsProps} ladderOnClick={handleLadderChange} />
</div>
<div className="col-span-7">
<LadderDetails
band={currentBand}
ladder={data.bands[currentBand]}
ladderName={data.ladderName}
ladderSlug={ladderSlug}
/>
</div>
</section>
)}
</div>
);
};

export const LadderDetailsWrapper: React.FC<LadderDetailsProps> = (props) => (
<QueryParamProvider adapter={NextAdapterApp}>
<LadderDetailsPage {...props} />
</QueryParamProvider>
);
2 changes: 1 addition & 1 deletion frontend/src/components/pages/LadderDetails/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { LadderDetailsPage as LadderDetails } from './LadderDetails';
export { LadderDetailsWrapper as LadderDetails } from './LadderDetails';
26 changes: 15 additions & 11 deletions frontend/src/components/pages/MySpace/MySpace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@ import { LadderTab } from './modules/LadderTab';
import NextAdapterApp from 'next-query-params/app';
import { QueryParamProvider } from 'use-query-params';

export const MySpace: React.FC<MySpaceProps> = ({ data }) => {
const MySpace: React.FC<MySpaceProps> = ({ data }) => {
const { user, currentLevel, nextLevel, ladder } = data;
const { currentTab, setCurrentTab } = useMySpace();

return (
<QueryParamProvider adapter={NextAdapterApp}>
<div className="flex flex-col gap-8">
<Typography variant="body-l/semibold" as="h1">
My Space
</Typography>
<Header user={user} currentLevel={currentLevel} nextLevel={nextLevel} />
<Tabs tabs={mySpaceTabs} currentTab={currentTab} onTabChange={setCurrentTab} />
<div>{currentTab === 'ladder' && <LadderTab bands={ladder.bands} currentLevel={currentLevel.band} />}</div>
</div>
</QueryParamProvider>
<div className="flex flex-col gap-8">
<Typography variant="body-l/semibold" as="h1">
My Space
</Typography>
<Header user={user} currentLevel={currentLevel} nextLevel={nextLevel} />
<Tabs tabs={mySpaceTabs} currentTab={currentTab} onTabChange={setCurrentTab} />
<div>{currentTab === 'ladder' && <LadderTab bands={ladder.bands} currentLevel={currentLevel.band} />}</div>
</div>
);
};

export const MySpaceWrapper: React.FC<MySpaceProps> = (props) => (
<QueryParamProvider adapter={NextAdapterApp}>
<MySpace {...props} />
</QueryParamProvider>
);
2 changes: 1 addition & 1 deletion frontend/src/components/pages/MySpace/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { MySpace } from './MySpace';
export { MySpaceWrapper as MySpace } from './MySpace';

0 comments on commit e0e74a9

Please sign in to comment.