Skip to content

Commit 7b80f66

Browse files
committed
feat: store tab state in params
1 parent 2bbd098 commit 7b80f66

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

apps/web/src/views/settings/index.tsx

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,34 @@ export default function SettingsPage() {
428428
},
429429
];
430430

431+
const availableTabs = settingsTabs.filter((tab) => tab.condition);
432+
433+
useEffect(() => {
434+
const tabParam = router.query.tab as string;
435+
if (tabParam) {
436+
const tabIndex = availableTabs.findIndex((tab) => tab.key === tabParam);
437+
if (tabIndex !== -1) {
438+
setSelectedTabIndex(tabIndex);
439+
}
440+
}
441+
}, [router.query.tab, availableTabs]);
442+
443+
// Update URL when tab changes
444+
const handleTabChange = (index: number) => {
445+
const tabKey = availableTabs[index]?.key;
446+
if (tabKey) {
447+
void router.push(
448+
{
449+
pathname: router.pathname,
450+
query: { ...router.query, tab: tabKey },
451+
},
452+
undefined,
453+
{ shallow: true },
454+
);
455+
}
456+
setSelectedTabIndex(index);
457+
};
458+
431459
return (
432460
<>
433461
<div className="flex h-full w-full flex-col overflow-hidden">
@@ -445,14 +473,11 @@ export default function SettingsPage() {
445473

446474
<TabGroup
447475
selectedIndex={selectedTabIndex}
448-
onChange={setSelectedTabIndex}
476+
onChange={handleTabChange}
449477
>
450478
<div className="sm:hidden">
451479
{/* Mobile dropdown */}
452-
<Listbox
453-
value={selectedTabIndex}
454-
onChange={setSelectedTabIndex}
455-
>
480+
<Listbox value={selectedTabIndex} onChange={handleTabChange}>
456481
<div className="relative">
457482
<ListboxButton className="w-full appearance-none rounded-md bg-white py-2 pl-3 pr-8 text-left text-base text-gray-900 outline-1 -outline-offset-1 outline-gray-300 focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600 dark:bg-gray-900 dark:text-gray-100 dark:outline-white/10 dark:focus:outline-indigo-500">
458483
{settingsTabs.filter((tab) => tab.condition)[

0 commit comments

Comments
 (0)