1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/hooks/useCurrentTab.ts
2024-01-12 21:08:06 +03:00

25 lines
777 B
TypeScript

import { getDefaultTabIndex } from 'apps/experimental/components/tabs/tabRoutes';
import { useLocation, useSearchParams } from 'react-router-dom';
const useCurrentTab = () => {
const location = useLocation();
const [searchParams, setSearchParams] = useSearchParams();
const searchParamsTab = searchParams.get('tab');
const libraryId =
location.pathname === '/livetv.html' ?
'livetv' :
searchParams.get('topParentId');
const activeTab: number =
searchParamsTab !== null ?
parseInt(searchParamsTab, 10) :
getDefaultTabIndex(location.pathname, libraryId);
return {
searchParams,
setSearchParams,
libraryId,
activeTab
};
};
export default useCurrentTab;