mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Restore librarymenu.setTabs functionality
This commit is contained in:
parent
ea1d069e90
commit
91961de0ce
26 changed files with 124 additions and 209 deletions
|
@ -11,6 +11,7 @@ import ElevationScroll from 'components/ElevationScroll';
|
|||
import { DRAWER_WIDTH } from 'components/ResponsiveDrawer';
|
||||
import { useApi } from 'hooks/useApi';
|
||||
|
||||
import AppTabs from './components/AppTabs';
|
||||
import AppDrawer from './components/drawer/AppDrawer';
|
||||
|
||||
import './AppOverrides.scss';
|
||||
|
@ -55,7 +56,9 @@ const AppLayout: FC<AppLayoutProps> = ({
|
|||
isDrawerAvailable={!isMediumScreen && isDrawerAvailable}
|
||||
isDrawerOpen={isDrawerOpen}
|
||||
onDrawerButtonClick={onToggleDrawer}
|
||||
/>
|
||||
>
|
||||
<AppTabs isDrawerOpen={isDrawerOpen} />
|
||||
</AppToolbar>
|
||||
</AppBar>
|
||||
</ElevationScroll>
|
||||
|
||||
|
|
|
@ -16,7 +16,15 @@ $mui-bp-xl: 1536px;
|
|||
}
|
||||
|
||||
// Fix the padding of dashboard pages
|
||||
.content-primary.content-primary {
|
||||
padding-top: 3.25rem !important;
|
||||
.content-primary {
|
||||
padding-top: 3.25rem;
|
||||
}
|
||||
// Tabbed pages
|
||||
.withTabs .content-primary {
|
||||
padding-top: 6.5rem;
|
||||
|
||||
@media all and (min-width: $mui-bp-lg) {
|
||||
padding-top: 3.25rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
96
src/apps/dashboard/components/AppTabs.tsx
Normal file
96
src/apps/dashboard/components/AppTabs.tsx
Normal file
|
@ -0,0 +1,96 @@
|
|||
import { Theme } from '@mui/material/styles';
|
||||
import Tab from '@mui/material/Tab';
|
||||
import Tabs from '@mui/material/Tabs';
|
||||
import useMediaQuery from '@mui/material/useMediaQuery';
|
||||
import debounce from 'lodash-es/debounce';
|
||||
import isEqual from 'lodash-es/isEqual';
|
||||
import React, { FC, useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import { EventType } from 'types/eventType';
|
||||
import Events, { type Event } from 'utils/events';
|
||||
|
||||
interface AppTabsParams {
|
||||
isDrawerOpen: boolean
|
||||
}
|
||||
|
||||
interface TabDefinition {
|
||||
href: string
|
||||
name: string
|
||||
}
|
||||
|
||||
const handleResize = debounce(() => window.dispatchEvent(new Event('resize')), 100);
|
||||
|
||||
const AppTabs: FC<AppTabsParams> = ({
|
||||
isDrawerOpen
|
||||
}) => {
|
||||
const documentRef = useRef<Document>(document);
|
||||
const [ activeIndex, setActiveIndex ] = useState(0);
|
||||
const [ tabs, setTabs ] = useState<TabDefinition[]>();
|
||||
|
||||
const isBigScreen = useMediaQuery((theme: Theme) => theme.breakpoints.up('sm'));
|
||||
|
||||
const onTabsUpdate = useCallback((
|
||||
_e: Event,
|
||||
_newView?: string,
|
||||
newIndex: number | undefined = 0,
|
||||
newTabs?: TabDefinition[]
|
||||
) => {
|
||||
setActiveIndex(newIndex);
|
||||
|
||||
if (!isEqual(tabs, newTabs)) {
|
||||
setTabs(newTabs);
|
||||
}
|
||||
}, [ tabs ]);
|
||||
|
||||
useEffect(() => {
|
||||
const doc = documentRef.current;
|
||||
|
||||
if (doc) Events.on(doc, EventType.SET_TABS, onTabsUpdate);
|
||||
|
||||
return () => {
|
||||
if (doc) Events.off(doc, EventType.SET_TABS, onTabsUpdate);
|
||||
};
|
||||
}, [ onTabsUpdate ]);
|
||||
|
||||
// HACK: Force resizing to workaround upstream bug with tab resizing
|
||||
// https://github.com/mui/material-ui/issues/24011
|
||||
useEffect(() => {
|
||||
handleResize();
|
||||
}, [ isDrawerOpen ]);
|
||||
|
||||
if (!tabs?.length) return null;
|
||||
|
||||
return (
|
||||
<Tabs
|
||||
value={activeIndex}
|
||||
sx={{
|
||||
width: '100%',
|
||||
flexShrink: {
|
||||
xs: 0,
|
||||
lg: 'unset'
|
||||
},
|
||||
order: {
|
||||
xs: 100,
|
||||
lg: 'unset'
|
||||
}
|
||||
}}
|
||||
variant={isBigScreen ? 'standard' : 'scrollable'}
|
||||
centered={isBigScreen}
|
||||
>
|
||||
{
|
||||
tabs.map(({ href, name }, index) => (
|
||||
<Tab
|
||||
key={`tab-${name}`}
|
||||
label={name}
|
||||
data-tab-index={`${index}`}
|
||||
component={Link}
|
||||
to={href}
|
||||
/>
|
||||
))
|
||||
}
|
||||
</Tabs>
|
||||
);
|
||||
};
|
||||
|
||||
export default AppTabs;
|
Loading…
Add table
Add a link
Reference in a new issue