mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
refactor: extract reusable component
This commit is contained in:
parent
4882d9c8cc
commit
d370afd0b2
17 changed files with 437 additions and 216 deletions
20
src/hooks/useCurrentTab.ts
Normal file
20
src/hooks/useCurrentTab.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
import { getDefaultTabIndex } from 'apps/experimental/components/tabs/tabRoutes';
|
||||
import { useLocation, useSearchParams } from 'react-router-dom';
|
||||
|
||||
const useCurrentTab = () => {
|
||||
const location = useLocation();
|
||||
const [searchParams] = useSearchParams();
|
||||
const searchParamsParentId = searchParams.get('topParentId');
|
||||
const searchParamsTab = searchParams.get('tab');
|
||||
const currentTabIndex: number =
|
||||
searchParamsTab !== null ?
|
||||
parseInt(searchParamsTab, 10) :
|
||||
getDefaultTabIndex(location.pathname, searchParamsParentId);
|
||||
|
||||
return {
|
||||
searchParamsParentId,
|
||||
currentTabIndex
|
||||
};
|
||||
};
|
||||
|
||||
export default useCurrentTab;
|
Loading…
Add table
Add a link
Reference in a new issue