/*
* 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/.
*/
import { Box, Container } from '@mui/material';
import CssBaseline from '@mui/material/CssBaseline';
import React, { useEffect, useLayoutEffect, useMemo } from 'react';
import { Navigate, Route, Routes, useLocation } from 'react-router-dom';
import { loadErrorMessages, loadDevMessages } from '@apollo/client/dev';
import { AppContext } from '@/components/context/AppContext';
import { Browse } from '@/screens/Browse';
import { DownloadQueue } from '@/screens/DownloadQueue';
import { Extensions } from '@/screens/Extensions';
import { Library } from '@/screens/Library';
import { Manga } from '@/screens/Manga';
import { Reader } from '@/screens/Reader';
import { SearchAll } from '@/screens/SearchAll';
import { Settings } from '@/screens/Settings';
import { About } from '@/screens/settings/About';
import { Backup } from '@/screens/settings/Backup';
import { Categories } from '@/screens/settings/Categories';
import { DefaultReaderSettings } from '@/screens/settings/DefaultReaderSettings';
import { SourceConfigure } from '@/screens/SourceConfigure';
import { SourceMangas } from '@/screens/SourceMangas';
import { Sources } from '@/screens/Sources';
import { Updates } from '@/screens/Updates';
import '@/i18n';
import { LibrarySettings } from '@/screens/settings/LibrarySettings';
import { DefaultNavBar } from '@/components/navbar/DefaultNavBar';
import { DownloadSettings } from '@/screens/settings/DownloadSettings.tsx';
import { ServerSettings } from '@/screens/settings/ServerSettings.tsx';
import { ServerUpdateChecker } from '@/components/settings/ServerUpdateChecker.tsx';
import { requestManager } from '@/lib/requests/RequestManager.ts';
import { BrowseSettings } from '@/screens/settings/BrowseSettings.tsx';
import { WebUISettings } from '@/screens/settings/WebUISettings.tsx';
import { Migrate } from '@/screens/Migrate.tsx';
import { useMetadataServerSettings } from '@/util/metadataServerSettings.ts';
import { getActiveDevice, setActiveDevice } from '@/util/device.ts';
import { DeviceSetting } from '@/components/settings/DeviceSetting.tsx';
if (process.env.NODE_ENV !== 'production') {
// Adds messages only in a dev environment
loadDevMessages();
loadErrorMessages();
}
const ScrollToTop = () => {
const { pathname } = useLocation();
useLayoutEffect(() => {
window.scrollTo(0, 0);
}, [pathname]);
return null;
};
/**
* 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 = () => {
requestManager.useDownloadSubscription();
requestManager.useUpdaterSubscription();
requestManager.useWebUIUpdateSubscription();
return null;
};
const ActiveDeviceListener = ({ children }: { children?: React.ReactNode }) => {
const {
settings: { devices, activeDevice },
} = useMetadataServerSettings();
useEffect(() => {
if (activeDevice === getActiveDevice()) {
return;
}
setActiveDevice(activeDevice);
}, [devices, activeDevice]);
const memorizedChildren = useMemo(() => children, [activeDevice]);
return {memorizedChildren};
};
export const App: React.FC = () => (
{/* General Routes */}
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
{/* Manga Routes */}
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
} />
);