2021-10-26 12:13:37 +03:30
|
|
|
/*
|
|
|
|
|
* 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
|
2023-05-18 13:17:41 +02:00
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
2021-10-26 12:13:37 +03:30
|
|
|
|
2025-05-03 13:00:03 +02:00
|
|
|
import { useCallback, useRef, useState } from 'react';
|
2021-10-26 14:57:11 +03:30
|
|
|
import Tab from '@mui/material/Tab';
|
2024-09-30 05:39:29 +02:00
|
|
|
import { StringParam, useQueryParam } from 'use-query-params';
|
2026-01-10 19:45:02 +01:00
|
|
|
import { useLingui } from '@lingui/react/macro';
|
2025-08-16 15:58:27 +02:00
|
|
|
import { Sources } from '@/features/browse/sources/Sources.tsx';
|
|
|
|
|
import { Extensions } from '@/features/browse/extensions/Extensions.tsx';
|
2025-08-16 02:48:46 +02:00
|
|
|
import { TabPanel } from '@/base/components/tabs/TabPanel.tsx';
|
|
|
|
|
import { TabsWrapper } from '@/base/components/tabs/TabsWrapper.tsx';
|
|
|
|
|
import { TabsMenu } from '@/base/components/tabs/TabsMenu.tsx';
|
|
|
|
|
import { useResizeObserver } from '@/base/hooks/useResizeObserver.tsx';
|
2025-08-15 22:02:58 +02:00
|
|
|
import { useAppTitle } from '@/features/navigation-bar/hooks/useAppTitle.ts';
|
|
|
|
|
import { BrowseTab } from '@/features/browse/Browse.types.ts';
|
2025-07-23 01:37:47 +02:00
|
|
|
import { GROUPED_VIRTUOSO_Z_INDEX } from '@/lib/virtuoso/Virtuoso.constants.ts';
|
2025-08-16 02:48:46 +02:00
|
|
|
import { SearchParam } from '@/base/Base.types.ts';
|
2026-03-13 22:41:28 +01:00
|
|
|
import { Migration } from '@/features/migration/screens/Migration.tsx';
|
2024-09-30 05:39:29 +02:00
|
|
|
|
2023-10-28 00:32:02 +02:00
|
|
|
export function Browse() {
|
2026-01-10 19:45:02 +01:00
|
|
|
const { t } = useLingui();
|
|
|
|
|
useAppTitle(t`Browse`);
|
2024-09-30 05:39:29 +02:00
|
|
|
|
2024-07-11 17:22:52 +02:00
|
|
|
const tabsMenuRef = useRef<HTMLDivElement | null>(null);
|
|
|
|
|
const [tabsMenuHeight, setTabsMenuHeight] = useState(0);
|
|
|
|
|
useResizeObserver(
|
|
|
|
|
tabsMenuRef,
|
2024-07-17 22:08:31 +02:00
|
|
|
useCallback(() => setTabsMenuHeight(tabsMenuRef.current!.offsetHeight), [tabsMenuRef.current]),
|
2024-07-11 17:22:52 +02:00
|
|
|
);
|
|
|
|
|
|
2025-07-23 01:52:41 +02:00
|
|
|
const [tabSearchParam, setTabSearchParam] = useQueryParam(SearchParam.TAB, StringParam, {});
|
2025-07-23 01:13:14 +02:00
|
|
|
const tabName = (tabSearchParam as BrowseTab) ?? BrowseTab.SOURCES;
|
2021-10-26 14:57:11 +03:30
|
|
|
|
2024-09-30 05:39:29 +02:00
|
|
|
if (!tabSearchParam) {
|
|
|
|
|
setTabSearchParam(tabName, 'replaceIn');
|
|
|
|
|
}
|
2024-01-26 20:50:51 +01:00
|
|
|
|
2021-10-26 14:57:11 +03:30
|
|
|
return (
|
2024-01-02 23:32:49 +01:00
|
|
|
<TabsWrapper>
|
2024-07-29 17:22:49 +02:00
|
|
|
<TabsMenu
|
|
|
|
|
ref={tabsMenuRef}
|
2025-04-30 02:40:05 +02:00
|
|
|
sx={{ zIndex: GROUPED_VIRTUOSO_Z_INDEX }}
|
2024-07-29 17:22:49 +02:00
|
|
|
variant="fullWidth"
|
2024-09-30 05:39:29 +02:00
|
|
|
value={tabName}
|
|
|
|
|
onChange={(_, newTab) => setTabSearchParam(newTab, 'replaceIn')}
|
2024-07-29 17:22:49 +02:00
|
|
|
>
|
2026-01-10 19:45:02 +01:00
|
|
|
<Tab value={BrowseTab.SOURCES} sx={{ textTransform: 'none' }} label={t`Source`} />
|
|
|
|
|
<Tab value={BrowseTab.EXTENSIONS} sx={{ textTransform: 'none' }} label={t`Extension`} />
|
|
|
|
|
<Tab value={BrowseTab.MIGRATE} sx={{ textTransform: 'none' }} label={t`Migrate`} />
|
2024-01-02 23:32:49 +01:00
|
|
|
</TabsMenu>
|
2025-07-23 01:13:14 +02:00
|
|
|
<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} />
|
2021-10-26 14:57:11 +03:30
|
|
|
</TabPanel>
|
2025-07-23 01:12:13 +02:00
|
|
|
<TabPanel index={BrowseTab.EXTENSIONS} currentIndex={tabName}>
|
2024-07-11 17:22:52 +02:00
|
|
|
<Extensions tabsMenuHeight={tabsMenuHeight} />
|
2021-10-26 14:57:11 +03:30
|
|
|
</TabPanel>
|
2025-07-23 01:12:13 +02:00
|
|
|
<TabPanel index={BrowseTab.MIGRATE} currentIndex={tabName}>
|
2024-09-30 04:01:23 +02:00
|
|
|
<Migration tabsMenuHeight={tabsMenuHeight} />
|
2024-01-26 20:50:51 +01:00
|
|
|
</TabPanel>
|
2024-01-02 23:32:49 +01:00
|
|
|
</TabsWrapper>
|
2021-10-26 14:57:11 +03:30
|
|
|
);
|
2021-10-26 12:13:37 +03:30
|
|
|
}
|