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

70 lines
3.1 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/.
*/
2025-05-03 13:00:03 +02:00
import { useCallback, useRef, useState } from 'react';
import Tab from '@mui/material/Tab';
2023-02-14 16:47:38 +03:30
import { useTranslation } from 'react-i18next';
import { StringParam, useQueryParam } from 'use-query-params';
2024-10-05 21:22:12 +02:00
import { Sources } from '@/modules/source/screens/Sources.tsx';
2024-10-05 21:29:50 +02:00
import { Extensions } from '@/modules/extension/screens/Extensions.tsx';
2024-10-05 16:09:34 +02:00
import { TabPanel } from '@/modules/core/components/tabs/TabPanel.tsx';
import { TabsWrapper } from '@/modules/core/components/tabs/TabsWrapper.tsx';
import { TabsMenu } from '@/modules/core/components/tabs/TabsMenu.tsx';
2024-10-05 21:35:25 +02:00
import { Migration } from '@/modules/migration/screens/Migration.tsx';
2024-10-05 16:09:34 +02:00
import { useResizeObserver } from '@/modules/core/hooks/useResizeObserver.tsx';
import { GROUPED_VIRTUOSO_Z_INDEX } from '@/modules/core/AppRoute.constants.ts';
2025-05-03 13:00:03 +02:00
import { useAppTitle } from '@/modules/navigation-bar/hooks/useAppTitle.ts';
import { BrowseTab } from '@/modules/browse/Browse.types.ts';
2023-10-28 00:32:02 +02:00
export function Browse() {
2023-02-14 16:47:38 +03:30
const { t } = useTranslation();
2025-05-03 13:00:03 +02:00
useAppTitle(t('global.label.browse'));
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 [tabSearchParam, setTabSearchParam] = useQueryParam('tab', StringParam, {});
const tabName = (tabSearchParam as BrowseTab) ?? BrowseTab.SOURCES;
if (!tabSearchParam) {
setTabSearchParam(tabName, 'replaceIn');
}
return (
<TabsWrapper>
<TabsMenu
ref={tabsMenuRef}
sx={{ zIndex: GROUPED_VIRTUOSO_Z_INDEX }}
variant="fullWidth"
value={tabName}
onChange={(_, newTab) => setTabSearchParam(newTab, 'replaceIn')}
>
<Tab value={BrowseTab.SOURCES} sx={{ textTransform: 'none' }} label={t('source.title_other')} />
<Tab value={BrowseTab.EXTENSIONS} sx={{ textTransform: 'none' }} label={t('extension.title_other')} />
<Tab value={BrowseTab.MIGRATE} sx={{ textTransform: 'none' }} label={t('migrate.title')} />
</TabsMenu>
<TabPanel index={BrowseTab.SOURCE_DEPRECATED} currentIndex={tabName}>
<Sources tabsMenuHeight={tabsMenuHeight} />
</TabPanel>
<TabPanel index={BrowseTab.SOURCES} currentIndex={tabName}>
2025-06-23 00:36:32 +02:00
<Sources tabsMenuHeight={tabsMenuHeight} />
</TabPanel>
<TabPanel index={BrowseTab.EXTENSIONS} currentIndex={tabName}>
2024-07-11 17:22:52 +02:00
<Extensions tabsMenuHeight={tabsMenuHeight} />
</TabPanel>
<TabPanel index={BrowseTab.MIGRATE} currentIndex={tabName}>
2024-09-30 04:01:23 +02:00
<Migration tabsMenuHeight={tabsMenuHeight} />
</TabPanel>
</TabsWrapper>
);
}