Files
suwayomi-material-you-webui/src/screens/Browse.tsx

63 lines
2.3 KiB
TypeScript
Raw Normal View History

/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
2024-07-11 17:22:52 +02:00
import { useCallback, useContext, useEffect, useRef, useState } from 'react';
import Tab from '@mui/material/Tab';
2023-02-14 16:47:38 +03:30
import { useTranslation } from 'react-i18next';
2023-10-28 00:32:02 +02:00
import { Sources } from '@/screens/Sources';
import { Extensions } from '@/screens/Extensions';
import { TabPanel } from '@/components/tabs/TabPanel.tsx';
import { TabsWrapper } from '@/components/tabs/TabsWrapper.tsx';
import { TabsMenu } from '@/components/tabs/TabsMenu.tsx';
import { Migration } from '@/screens/Migration.tsx';
import { NavBarContext } from '@/components/context/NavbarContext.tsx';
2024-07-11 17:22:52 +02:00
import { useResizeObserver } from '@/util/useResizeObserver.tsx';
2023-10-28 00:32:02 +02:00
export function Browse() {
2023-02-14 16:47:38 +03:30
const { t } = useTranslation();
const { setTitle } = useContext(NavBarContext);
2023-02-14 16:47:38 +03:30
2024-07-11 17:22:52 +02:00
const tabsMenuRef = useRef<HTMLDivElement | null>(null);
const [tabsMenuHeight, setTabsMenuHeight] = useState(0);
useResizeObserver(
tabsMenuRef,
useCallback(() => setTabsMenuHeight(tabsMenuRef.current!.offsetHeight), [tabsMenuRef.current]),
2024-07-11 17:22:52 +02:00
);
const [tabNum, setTabNum] = useState<number>(0);
useEffect(() => {
setTitle(t('global.label.browse'));
}, [t]);
return (
<TabsWrapper>
<TabsMenu
ref={tabsMenuRef}
variant="fullWidth"
value={tabNum}
tabsCount={2}
onChange={(e, newTab) => setTabNum(newTab)}
>
2024-07-01 19:51:27 +02:00
<Tab sx={{ textTransform: 'none' }} label={t('source.title_one')} />
<Tab sx={{ textTransform: 'none' }} label={t('extension.title_other')} />
<Tab sx={{ textTransform: 'none' }} label={t('migrate.title')} />
</TabsMenu>
<TabPanel index={0} currentIndex={tabNum}>
<Sources />
</TabPanel>
<TabPanel index={1} currentIndex={tabNum}>
2024-07-11 17:22:52 +02:00
<Extensions tabsMenuHeight={tabsMenuHeight} />
</TabPanel>
<TabPanel index={2} currentIndex={tabNum}>
<Migration />
</TabPanel>
</TabsWrapper>
);
}