Skip to content

Commit

Permalink
Front: Use TabRouter for Search
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthi-chaud committed Aug 10, 2024
1 parent c950206 commit a3cadd8
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 223 deletions.
157 changes: 0 additions & 157 deletions front/src/components/infinite/selectable-infinite-view.tsx

This file was deleted.

6 changes: 4 additions & 2 deletions front/src/components/tab-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const useTabRouter = <TabValue extends string>(
router: NextRouter,
) => string | string[] | undefined,
// This should persist the tab change in the router
onTabChange: (newTab: TabValue) => void,
urlOnTabChange: (newTab: TabValue) => string,
defaultTab: TabValue,
...otherTabs: TabValue[]
) => {
Expand Down Expand Up @@ -60,7 +60,9 @@ export const useTabRouter = <TabValue extends string>(
}
}, [router.asPath]);
useEffect(() => {
onTabChange(selectedTab);
router.push(urlOnTabChange(selectedTab), undefined, {
shallow: true,
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedTab]);

Expand Down
9 changes: 3 additions & 6 deletions front/src/pages/genres/[slugOrId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ const GenrePage: Page<GetPropsTypesFrom<typeof prepareSSR>> = ({ props }) => {
const genre = useQuery(API.getGenre, genreIdentifier);
const { selectedTab, selectTab } = useTabRouter(
(r) => r.query.t,
(newTab) =>
router.push(`/genres/${genreIdentifier}?t=${newTab}`, undefined, {
shallow: true,
}),
(newTab) => `/genres/${genreIdentifier}?t=${newTab}`,
"album",
"artist",
"song",
Expand All @@ -92,14 +89,14 @@ const GenrePage: Page<GetPropsTypesFrom<typeof prepareSSR>> = ({ props }) => {
<Tabs
value={selectedTab}
onChange={(__, tabName) => selectTab(tabName)}
variant="scrollable"
variant="fullWidth"
>
{tabs.map((value, index) => (
<Tab
key={index}
value={value}
sx={{ minWidth: "fit-content", flex: 1 }}
label={t(value)}
label={t(`${value}s`)}
/>
))}
</Tabs>
Expand Down
Loading

0 comments on commit a3cadd8

Please sign in to comment.