mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* zetachain start * zeta chain cctx table * pagination * cctx page init * meta for new route * remove backlink * schema * continue * fix * navigation * filters to test * some fixes * add chain filter * add error message and revert options * address chain logo fix * cctx search * socket * fix conflict * fixes1 * fixes2 * fixes3 * fixes4 * fixes5 * tests * fixes6 * test fixes * revert options fix * stats and revert semi-fix * fix readme * cleanup * check for cctx in lifecycle * update config * fixes 8 * fixes 9 * update config * fixes10
27 lines
687 B
TypeScript
27 lines
687 B
TypeScript
import { useRouter } from 'next/router';
|
|
|
|
import type { TabItem } from '../AdaptiveTabs/types';
|
|
|
|
import { castToString } from '../../utils/guards';
|
|
|
|
export default function useActiveTabFromQuery(tabs: Array<TabItem>, defaultTabId?: string) {
|
|
const router = useRouter();
|
|
const tabFromQuery = castToString(router.query.tab);
|
|
|
|
if (!tabFromQuery) {
|
|
if (defaultTabId) {
|
|
return tabs.find((tab) => tab.id === defaultTabId);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
return tabs.find((tab) => {
|
|
if (Array.isArray(tab.id)) {
|
|
return tab.id.includes(tabFromQuery);
|
|
}
|
|
|
|
return tab.id === tabFromQuery || ('subTabs' in tab && tab.subTabs?.some((id) => id === tabFromQuery));
|
|
});
|
|
}
|