2021-03-26 04:17:02 +04:30
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
2021-01-26 23:32:12 +03:30
|
|
|
* 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-01-26 23:32:12 +03:30
|
|
|
|
2021-09-09 17:51:22 +04:30
|
|
|
import CssBaseline from '@mui/material/CssBaseline';
|
2024-03-07 01:12:35 +01:00
|
|
|
import React, { useLayoutEffect } from 'react';
|
2023-12-10 15:58:21 +01:00
|
|
|
import { Navigate, Route, Routes, useLocation } from 'react-router-dom';
|
2023-08-27 21:39:47 +02:00
|
|
|
import { loadErrorMessages, loadDevMessages } from '@apollo/client/dev';
|
2024-04-29 16:35:08 +02:00
|
|
|
import { loadable } from 'react-lazily/loadable';
|
2024-07-11 17:22:52 +02:00
|
|
|
import Box from '@mui/material/Box';
|
2025-08-15 22:02:58 +02:00
|
|
|
import { AppContext } from '@/features/core/contexts/AppContext.tsx';
|
2023-06-05 01:42:39 +02:00
|
|
|
import '@/i18n';
|
2025-08-15 22:02:58 +02:00
|
|
|
import { DefaultNavBar } from '@/features/navigation-bar/components/DefaultNavBar.tsx';
|
2024-10-06 01:27:51 +02:00
|
|
|
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
2025-08-15 22:02:58 +02:00
|
|
|
import { WebUIUpdateChecker } from '@/features/app-updates/components/WebUIUpdateChecker.tsx';
|
|
|
|
|
import { ServerUpdateChecker } from '@/features/app-updates/components/ServerUpdateChecker.tsx';
|
|
|
|
|
import { lazyLoadFallback } from '@/features/core/utils/LazyLoad.tsx';
|
|
|
|
|
import { ErrorBoundary } from '@/features/core/components/feedback/ErrorBoundary.tsx';
|
|
|
|
|
import { useNavBarContext } from '@/features/navigation-bar/contexts/NavbarContext.tsx';
|
2025-04-21 23:00:28 +02:00
|
|
|
|
2025-08-15 22:02:58 +02:00
|
|
|
import { AppRoutes } from '@/features/core/AppRoute.constants.ts';
|
2025-04-21 23:00:28 +02:00
|
|
|
|
2025-08-15 22:02:58 +02:00
|
|
|
import { useMetadataServerSettings } from '@/features/settings/services/ServerSettingsMetadata.ts';
|
|
|
|
|
import { MediaQuery } from '@/features/core/utils/MediaQuery.tsx';
|
|
|
|
|
import { BrowseTab } from '@/features/browse/Browse.types.ts';
|
2024-04-29 16:35:08 +02:00
|
|
|
|
2025-08-15 22:02:58 +02:00
|
|
|
const { Browse } = loadable(() => import('@/features/browse/screens/Browse.tsx'), lazyLoadFallback);
|
|
|
|
|
const { DownloadQueue } = loadable(() => import('@/features/downloads/screens/DownloadQueue.tsx'), lazyLoadFallback);
|
|
|
|
|
const { Library } = loadable(() => import('@/features/library/screens/Library.tsx'), lazyLoadFallback);
|
|
|
|
|
const { Manga } = loadable(() => import('@/features/manga/screens/Manga.tsx'), lazyLoadFallback);
|
|
|
|
|
const { SearchAll } = loadable(() => import('@/features/global-search/screens/SearchAll.tsx'), lazyLoadFallback);
|
|
|
|
|
const { Settings } = loadable(() => import('@/features/settings/screens/Settings.tsx'), lazyLoadFallback);
|
|
|
|
|
const { About } = loadable(() => import('@/features/settings/screens/About.tsx'), lazyLoadFallback);
|
|
|
|
|
const { Backup } = loadable(() => import('@/features/backup/screens/Backup.tsx'), lazyLoadFallback);
|
2024-10-05 21:39:58 +02:00
|
|
|
const { CategorySettings } = loadable(
|
2025-08-15 22:02:58 +02:00
|
|
|
() => import('@/features/category/screens/CategorySettings.tsx'),
|
2024-10-05 21:39:58 +02:00
|
|
|
lazyLoadFallback,
|
|
|
|
|
);
|
2025-08-15 22:02:58 +02:00
|
|
|
const { SourceConfigure } = loadable(() => import('@/features/source/screens/SourceConfigure.tsx'), lazyLoadFallback);
|
|
|
|
|
const { SourceMangas } = loadable(() => import('@/features/source/screens/SourceMangas.tsx'), lazyLoadFallback);
|
|
|
|
|
const { ExtensionInfo } = loadable(() => import('@/features/extension/screens/ExtensionInfo.tsx'), lazyLoadFallback);
|
|
|
|
|
const { Updates } = loadable(() => import('@/features/updates/screens/Updates.tsx'), lazyLoadFallback);
|
|
|
|
|
const { History } = loadable(() => import('@/features/history/screens/History.tsx'), lazyLoadFallback);
|
|
|
|
|
const { LibrarySettings } = loadable(() => import('@/features/library/screens/LibrarySettings.tsx'), lazyLoadFallback);
|
2024-10-05 22:31:21 +02:00
|
|
|
const { DownloadSettings } = loadable(
|
2025-08-15 22:02:58 +02:00
|
|
|
() => import('@/features/downloads/screens/DownloadSettings.tsx'),
|
|
|
|
|
lazyLoadFallback,
|
|
|
|
|
);
|
|
|
|
|
const { ServerSettings } = loadable(() => import('@/features/settings/screens/ServerSettings.tsx'), lazyLoadFallback);
|
|
|
|
|
const { BrowseSettings } = loadable(() => import('@/features/browse/screens/BrowseSettings.tsx'), lazyLoadFallback);
|
|
|
|
|
const { WebUISettings } = loadable(() => import('@/features/settings/screens/WebUISettings.tsx'), lazyLoadFallback);
|
|
|
|
|
const { Migrate } = loadable(() => import('@/features/migration/screens/Migrate.tsx'), lazyLoadFallback);
|
|
|
|
|
const { DeviceSetting } = loadable(() => import('@/features/device/screens/DeviceSetting.tsx'), lazyLoadFallback);
|
|
|
|
|
const { TrackingSettings } = loadable(
|
|
|
|
|
() => import('@/features/tracker/screens/TrackingSettings.tsx'),
|
2024-10-05 22:31:21 +02:00
|
|
|
lazyLoadFallback,
|
|
|
|
|
);
|
2024-10-05 21:32:31 +02:00
|
|
|
const { TrackerOAuthLogin } = loadable(
|
2025-08-15 22:02:58 +02:00
|
|
|
() => import('@/features/tracker/screens/TrackerOAuthLogin.tsx'),
|
2024-10-05 21:32:31 +02:00
|
|
|
lazyLoadFallback,
|
|
|
|
|
);
|
2024-10-05 19:33:09 +02:00
|
|
|
const { LibraryDuplicates } = loadable(
|
2025-08-15 22:02:58 +02:00
|
|
|
() => import('@/features/library/screens/LibraryDuplicates.tsx'),
|
2024-10-05 19:33:09 +02:00
|
|
|
lazyLoadFallback,
|
|
|
|
|
);
|
2025-08-15 22:02:58 +02:00
|
|
|
const { Appearance } = loadable(() => import('@/features/settings/screens/Appearance.tsx'), lazyLoadFallback);
|
2024-12-11 13:43:53 +01:00
|
|
|
const { GlobalReaderSettings } = loadable(
|
2025-08-16 02:02:13 +02:00
|
|
|
() => import('@/features/reader/settings/screens/GlobalReaderSettings.tsx'),
|
2024-11-04 18:00:35 +01:00
|
|
|
lazyLoadFallback,
|
|
|
|
|
);
|
2025-08-15 22:02:58 +02:00
|
|
|
const { More } = loadable(() => import('@/features/settings/screens/More.tsx'), lazyLoadFallback);
|
|
|
|
|
const { Reader } = loadable(() => import('@/features/reader/screens/Reader.tsx'), lazyLoadFallback);
|
|
|
|
|
const { HistorySettings } = loadable(() => import('@/features/history/screens/HistorySettings.tsx'), lazyLoadFallback);
|
2021-09-09 17:51:22 +04:30
|
|
|
|
2023-12-23 15:15:03 +01:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
2023-08-27 21:39:47 +02:00
|
|
|
// Adds messages only in a dev environment
|
|
|
|
|
loadDevMessages();
|
|
|
|
|
loadErrorMessages();
|
|
|
|
|
}
|
2023-12-10 15:58:21 +01:00
|
|
|
|
|
|
|
|
const ScrollToTop = () => {
|
|
|
|
|
const { pathname } = useLocation();
|
|
|
|
|
|
|
|
|
|
useLayoutEffect(() => {
|
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
|
}, [pathname]);
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
2024-01-01 22:40:39 +01:00
|
|
|
/**
|
|
|
|
|
* Creates permanent subscriptions to always have the latest data.
|
|
|
|
|
*
|
|
|
|
|
* E.g. in case a view is open, which does not subscribe to the download updates, finished downloads are never received
|
|
|
|
|
* and thus, data of existing chapters/mangas in the cache get outdated
|
|
|
|
|
*/
|
|
|
|
|
const BackgroundSubscriptions = () => {
|
2025-01-12 14:09:10 +01:00
|
|
|
// load the full download status once on startup to fill the cache
|
|
|
|
|
requestManager.useGetDownloadStatus({ nextFetchPolicy: 'standby' });
|
2024-01-01 22:40:39 +01:00
|
|
|
requestManager.useDownloadSubscription();
|
|
|
|
|
requestManager.useUpdaterSubscription();
|
|
|
|
|
requestManager.useWebUIUpdateSubscription();
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-11 17:22:52 +02:00
|
|
|
const MainApp = () => {
|
2024-08-30 04:34:28 +02:00
|
|
|
const { navBarWidth, appBarHeight, bottomBarHeight } = useNavBarContext();
|
2025-04-05 15:23:39 +02:00
|
|
|
const isMobileWidth = MediaQuery.useIsMobileWidth();
|
2024-07-11 17:22:52 +02:00
|
|
|
|
2025-03-22 01:16:38 +01:00
|
|
|
const {
|
|
|
|
|
settings: { hideHistory },
|
|
|
|
|
} = useMetadataServerSettings();
|
|
|
|
|
|
2024-07-11 17:22:52 +02:00
|
|
|
return (
|
|
|
|
|
<Box
|
2024-03-07 01:12:35 +01:00
|
|
|
id="appMainContainer"
|
2024-07-11 17:22:52 +02:00
|
|
|
component="main"
|
2024-03-07 01:12:35 +01:00
|
|
|
sx={{
|
2024-08-30 04:34:28 +02:00
|
|
|
minHeight: `calc(100vh - ${appBarHeight + bottomBarHeight}px)`,
|
2024-07-29 17:22:49 +02:00
|
|
|
width: `calc(100vw - (100vw - 100%) - ${navBarWidth}px)`,
|
|
|
|
|
minWidth: `calc(100vw - (100vw - 100%) - ${navBarWidth}px)`,
|
2024-07-13 13:01:33 +02:00
|
|
|
maxWidth: `calc(100vw - (100vw - 100%) - ${navBarWidth}px)`,
|
2024-07-11 17:22:52 +02:00
|
|
|
position: 'relative',
|
2024-08-30 04:34:28 +02:00
|
|
|
mt: `${appBarHeight}px`,
|
2024-12-15 22:37:11 +01:00
|
|
|
pb: `calc(${bottomBarHeight}px + ${!bottomBarHeight ? 'env(safe-area-inset-bottom)' : '0px'})`,
|
2025-01-08 23:59:26 +01:00
|
|
|
pr: 'env(safe-area-inset-right)',
|
2024-03-07 01:12:35 +01:00
|
|
|
}}
|
|
|
|
|
>
|
2024-04-29 16:35:08 +02:00
|
|
|
<ErrorBoundary>
|
|
|
|
|
<Routes>
|
|
|
|
|
{/* General Routes */}
|
2025-05-18 01:04:16 +08:00
|
|
|
<Route path={AppRoutes.root.match} element={<Navigate to={AppRoutes.library.path()} replace />} />
|
2024-12-11 20:10:59 +01:00
|
|
|
<Route path={AppRoutes.matchAll.match} element={<Navigate to={AppRoutes.root.path} replace />} />
|
2025-04-05 15:23:39 +02:00
|
|
|
{isMobileWidth && <Route path={AppRoutes.more.match} element={<More />} />}
|
2025-04-05 15:34:58 +02:00
|
|
|
<Route path={AppRoutes.about.match} element={<About />} />
|
2024-12-11 20:10:59 +01:00
|
|
|
<Route path={AppRoutes.settings.match}>
|
2024-04-29 16:35:08 +02:00
|
|
|
<Route index element={<Settings />} />
|
2024-12-11 20:10:59 +01:00
|
|
|
<Route path={AppRoutes.settings.childRoutes.categories.match} element={<CategorySettings />} />
|
|
|
|
|
<Route path={AppRoutes.settings.childRoutes.reader.match} element={<GlobalReaderSettings />} />
|
|
|
|
|
<Route path={AppRoutes.settings.childRoutes.library.match}>
|
2024-05-04 15:41:21 +02:00
|
|
|
<Route index element={<LibrarySettings />} />
|
2024-12-11 20:10:59 +01:00
|
|
|
<Route
|
|
|
|
|
path={AppRoutes.settings.childRoutes.library.childRoutes.duplicates.match}
|
|
|
|
|
element={<LibraryDuplicates />}
|
|
|
|
|
/>
|
2024-05-04 15:41:21 +02:00
|
|
|
</Route>
|
2024-12-11 20:10:59 +01:00
|
|
|
<Route path={AppRoutes.settings.childRoutes.download.match} element={<DownloadSettings />} />
|
|
|
|
|
<Route path={AppRoutes.settings.childRoutes.backup.match} element={<Backup />} />
|
|
|
|
|
<Route path={AppRoutes.settings.childRoutes.server.match} element={<ServerSettings />} />
|
|
|
|
|
<Route path={AppRoutes.settings.childRoutes.webui.match} element={<WebUISettings />} />
|
|
|
|
|
<Route path={AppRoutes.settings.childRoutes.browse.match} element={<BrowseSettings />} />
|
2025-03-22 01:16:38 +01:00
|
|
|
<Route path={AppRoutes.settings.childRoutes.history.match} element={<HistorySettings />} />
|
2024-12-11 20:10:59 +01:00
|
|
|
<Route path={AppRoutes.settings.childRoutes.device.match} element={<DeviceSetting />} />
|
|
|
|
|
<Route path={AppRoutes.settings.childRoutes.tracking.match} element={<TrackingSettings />} />
|
|
|
|
|
<Route path={AppRoutes.settings.childRoutes.appearance.match} element={<Appearance />} />
|
2024-04-29 16:35:08 +02:00
|
|
|
</Route>
|
2021-03-18 21:46:24 +03:30
|
|
|
|
2024-04-29 16:35:08 +02:00
|
|
|
{/* Manga Routes */}
|
2021-01-23 01:20:16 +03:30
|
|
|
|
2024-12-11 20:10:59 +01:00
|
|
|
<Route path={AppRoutes.sources.match}>
|
2025-07-23 01:22:42 +02:00
|
|
|
{/* TODO: deprecated - "source" and "extension" page got merged into "browse" */}
|
|
|
|
|
<Route index element={<Navigate to={AppRoutes.browse.path(BrowseTab.SOURCES)} replace />} />
|
2024-12-11 20:10:59 +01:00
|
|
|
<Route path={AppRoutes.sources.childRoutes.browse.match} element={<SourceMangas />} />
|
|
|
|
|
<Route path={AppRoutes.sources.childRoutes.configure.match} element={<SourceConfigure />} />
|
|
|
|
|
<Route path={AppRoutes.sources.childRoutes.searchAll.match} element={<SearchAll />} />
|
2024-04-29 16:35:08 +02:00
|
|
|
</Route>
|
2025-06-22 23:12:54 +02:00
|
|
|
<Route path={AppRoutes.extension.match}>
|
2025-07-23 01:23:51 +02:00
|
|
|
<Route index element={<Navigate to={AppRoutes.browse.path(BrowseTab.EXTENSIONS)} replace />} />
|
2025-06-22 23:12:54 +02:00
|
|
|
<Route path={AppRoutes.extension.childRoutes.info.match} element={<ExtensionInfo />} />
|
|
|
|
|
</Route>
|
2024-12-11 20:10:59 +01:00
|
|
|
<Route path={AppRoutes.downloads.match} element={<DownloadQueue />} />
|
|
|
|
|
<Route path={AppRoutes.manga.match}>
|
|
|
|
|
<Route path={AppRoutes.manga.childRoutes.reader.match} element={null} />
|
2024-04-29 16:35:08 +02:00
|
|
|
<Route index element={<Manga />} />
|
|
|
|
|
</Route>
|
2024-12-11 20:10:59 +01:00
|
|
|
<Route path={AppRoutes.library.match} element={<Library />} />
|
|
|
|
|
<Route path={AppRoutes.updates.match} element={<Updates />} />
|
2025-03-22 01:16:38 +01:00
|
|
|
{!hideHistory && <Route path={AppRoutes.history.match} element={<History />} />}
|
2024-12-11 20:10:59 +01:00
|
|
|
<Route path={AppRoutes.browse.match} element={<Browse />} />
|
|
|
|
|
<Route path={AppRoutes.migrate.match}>
|
2024-04-29 16:35:08 +02:00
|
|
|
<Route index element={<Migrate />} />
|
2024-12-11 20:10:59 +01:00
|
|
|
<Route path={AppRoutes.migrate.childRoutes.search.match} element={<SearchAll />} />
|
2024-04-29 16:35:08 +02:00
|
|
|
</Route>
|
2024-12-11 20:10:59 +01:00
|
|
|
<Route path={AppRoutes.tracker.match} element={<TrackerOAuthLogin />} />
|
2024-04-29 16:35:08 +02:00
|
|
|
</Routes>
|
|
|
|
|
</ErrorBoundary>
|
2024-07-11 17:22:52 +02:00
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const ReaderApp = () => (
|
|
|
|
|
<ErrorBoundary>
|
|
|
|
|
<Routes>
|
2024-12-11 20:10:59 +01:00
|
|
|
<Route path={AppRoutes.matchAll.match} element={<Reader />} />
|
2024-07-11 17:22:52 +02:00
|
|
|
</Routes>
|
|
|
|
|
</ErrorBoundary>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const App: React.FC = () => (
|
|
|
|
|
<AppContext>
|
|
|
|
|
<ScrollToTop />
|
|
|
|
|
<ServerUpdateChecker />
|
|
|
|
|
<WebUIUpdateChecker />
|
|
|
|
|
<BackgroundSubscriptions />
|
|
|
|
|
<CssBaseline enableColorScheme />
|
|
|
|
|
<Box sx={{ display: 'flex' }}>
|
2024-12-15 22:37:11 +01:00
|
|
|
<Box sx={{ flexShrink: 0, position: 'relative', height: '100vh' }}>
|
2024-07-11 17:22:52 +02:00
|
|
|
<DefaultNavBar />
|
|
|
|
|
</Box>
|
2024-12-03 20:24:55 +01:00
|
|
|
<Routes>
|
2024-12-11 20:10:59 +01:00
|
|
|
<Route path={AppRoutes.matchAll.match} element={<MainApp />} />
|
|
|
|
|
<Route path={AppRoutes.reader.match} element={<ReaderApp />} />
|
2024-12-03 20:24:55 +01:00
|
|
|
</Routes>
|
2024-07-11 17:22:52 +02:00
|
|
|
</Box>
|
2022-11-26 13:51:56 +01:00
|
|
|
</AppContext>
|
|
|
|
|
);
|