2023-06-21 18:16:41 +02:00
|
|
|
import { lazy, useEffect, useState } from "react";
|
|
|
|
import { Redirect, Route, Switch, useLocation } from "react-router-dom";
|
2023-01-07 21:36:18 +01:00
|
|
|
|
2023-06-13 14:06:37 +02:00
|
|
|
import { convertLegacyUrl } from "@/backend/metadata/getmeta";
|
2023-06-21 13:38:48 +02:00
|
|
|
import { MWMediaType } from "@/backend/metadata/types/mw";
|
2023-02-24 21:45:14 +01:00
|
|
|
import { BannerContextProvider } from "@/hooks/useBanner";
|
|
|
|
import { Layout } from "@/setup/Layout";
|
2023-04-24 17:41:54 +02:00
|
|
|
import { BookmarkContextProvider } from "@/state/bookmark";
|
|
|
|
import { SettingsProvider } from "@/state/settings";
|
|
|
|
import { WatchedContextProvider } from "@/state/watched";
|
|
|
|
import { MediaView } from "@/views/media/MediaView";
|
|
|
|
import { NotFoundPage } from "@/views/notfound/NotFoundView";
|
|
|
|
import { V2MigrationView } from "@/views/other/v2Migration";
|
|
|
|
import { SearchView } from "@/views/search/SearchView";
|
2023-02-24 19:23:00 +01:00
|
|
|
|
2023-06-21 18:16:41 +02:00
|
|
|
// eslint-disable-next-line react/function-component-definition, react/prop-types
|
|
|
|
const LegacyUrlView: React.FC = ({ children }) => {
|
2023-06-13 14:06:37 +02:00
|
|
|
const location = useLocation();
|
2023-06-21 18:16:41 +02:00
|
|
|
const [redirectUrl, setRedirectUrl] = useState<string | null>(null);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
// Call the conversion function and set the redirect URL if necessary
|
|
|
|
convertLegacyUrl(location.pathname).then((convertedUrl) => {
|
|
|
|
if (convertedUrl) {
|
|
|
|
setRedirectUrl(convertedUrl);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, [location.pathname]);
|
|
|
|
|
|
|
|
if (redirectUrl) {
|
|
|
|
return <Redirect to={redirectUrl} />;
|
|
|
|
}
|
2023-06-13 14:06:37 +02:00
|
|
|
|
2023-06-21 18:16:41 +02:00
|
|
|
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
|
|
return <>{children}</>;
|
|
|
|
};
|
|
|
|
|
|
|
|
function App() {
|
2022-02-06 20:56:48 +01:00
|
|
|
return (
|
2023-03-09 18:08:13 +01:00
|
|
|
<SettingsProvider>
|
|
|
|
<WatchedContextProvider>
|
|
|
|
<BookmarkContextProvider>
|
|
|
|
<BannerContextProvider>
|
|
|
|
<Layout>
|
2023-06-21 18:16:41 +02:00
|
|
|
<LegacyUrlView>
|
|
|
|
<Switch>
|
|
|
|
{/* functional routes */}
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path="/v2-migration"
|
|
|
|
component={V2MigrationView}
|
|
|
|
/>
|
|
|
|
<Route exact path="/">
|
|
|
|
<Redirect to={`/search/${MWMediaType.MOVIE}`} />
|
|
|
|
</Route>
|
2023-02-22 19:02:23 +01:00
|
|
|
|
2023-06-21 18:16:41 +02:00
|
|
|
{/* pages */}
|
|
|
|
<Route exact path="/media/:media" component={MediaView} />
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path="/media/:media/:season/:episode"
|
|
|
|
component={MediaView}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path="/search/:type/:query?"
|
|
|
|
component={SearchView}
|
|
|
|
/>
|
2023-02-22 19:02:23 +01:00
|
|
|
|
2023-06-21 18:16:41 +02:00
|
|
|
{/* other */}
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path="/dev"
|
|
|
|
component={lazy(
|
|
|
|
() => import("@/views/developer/DeveloperView")
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path="/dev/video"
|
|
|
|
component={lazy(
|
|
|
|
() => import("@/views/developer/VideoTesterView")
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
{/* developer routes that can abuse workers are disabled in production */}
|
|
|
|
{process.env.NODE_ENV === "development" ? (
|
|
|
|
<>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path="/dev/test"
|
|
|
|
component={lazy(
|
|
|
|
() => import("@/views/developer/TestView")
|
|
|
|
)}
|
|
|
|
/>
|
2023-04-25 17:35:09 +02:00
|
|
|
|
2023-06-21 18:16:41 +02:00
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path="/dev/providers"
|
|
|
|
component={lazy(
|
|
|
|
() => import("@/views/developer/ProviderTesterView")
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path="/dev/embeds"
|
|
|
|
component={lazy(
|
|
|
|
() => import("@/views/developer/EmbedTesterView")
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
) : null}
|
|
|
|
<Route path="*" component={NotFoundPage} />
|
|
|
|
</Switch>
|
|
|
|
</LegacyUrlView>
|
2023-03-09 18:08:13 +01:00
|
|
|
</Layout>
|
|
|
|
</BannerContextProvider>
|
|
|
|
</BookmarkContextProvider>
|
|
|
|
</WatchedContextProvider>
|
|
|
|
</SettingsProvider>
|
2022-02-06 20:56:48 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|