|
|
@ -1,7 +1,13 @@ |
|
|
|
import { lazy, useEffect, useState } from "react"; |
|
|
|
import { ReactElement, lazy, useEffect } from "react"; |
|
|
|
import { Redirect, Route, Switch, useLocation } from "react-router-dom"; |
|
|
|
import { |
|
|
|
|
|
|
|
Redirect, |
|
|
|
|
|
|
|
Route, |
|
|
|
|
|
|
|
Switch, |
|
|
|
|
|
|
|
useHistory, |
|
|
|
|
|
|
|
useLocation, |
|
|
|
|
|
|
|
} from "react-router-dom"; |
|
|
|
|
|
|
|
|
|
|
|
import { convertLegacyUrl } from "@/backend/metadata/getmeta"; |
|
|
|
import { convertLegacyUrl, isLegacyUrl } from "@/backend/metadata/getmeta"; |
|
|
|
import { MWMediaType } from "@/backend/metadata/types/mw"; |
|
|
|
import { MWMediaType } from "@/backend/metadata/types/mw"; |
|
|
|
import { BannerContextProvider } from "@/hooks/useBanner"; |
|
|
|
import { BannerContextProvider } from "@/hooks/useBanner"; |
|
|
|
import { Layout } from "@/setup/Layout"; |
|
|
|
import { Layout } from "@/setup/Layout"; |
|
|
@ -13,28 +19,22 @@ import { NotFoundPage } from "@/views/notfound/NotFoundView"; |
|
|
|
import { V2MigrationView } from "@/views/other/v2Migration"; |
|
|
|
import { V2MigrationView } from "@/views/other/v2Migration"; |
|
|
|
import { SearchView } from "@/views/search/SearchView"; |
|
|
|
import { SearchView } from "@/views/search/SearchView"; |
|
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line react/function-component-definition, react/prop-types
|
|
|
|
function LegacyUrlView({ children }: { children: ReactElement }) { |
|
|
|
const LegacyUrlView: React.FC = ({ children }) => { |
|
|
|
|
|
|
|
const location = useLocation(); |
|
|
|
const location = useLocation(); |
|
|
|
const [redirectUrl, setRedirectUrl] = useState<string | null>(null); |
|
|
|
const { replace } = useHistory(); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
// Call the conversion function and set the redirect URL if necessary
|
|
|
|
const url = location.pathname; |
|
|
|
|
|
|
|
if (!isLegacyUrl(url)) return; |
|
|
|
convertLegacyUrl(location.pathname).then((convertedUrl) => { |
|
|
|
convertLegacyUrl(location.pathname).then((convertedUrl) => { |
|
|
|
if (convertedUrl) { |
|
|
|
replace(convertedUrl ?? "/"); |
|
|
|
setRedirectUrl(convertedUrl); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}, [location.pathname]); |
|
|
|
}, [location.pathname, replace]); |
|
|
|
|
|
|
|
|
|
|
|
if (redirectUrl) { |
|
|
|
if (isLegacyUrl(location.pathname)) return null; |
|
|
|
return <Redirect to={redirectUrl} />; |
|
|
|
return children; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
|
|
|
|
|
|
return <>{children}</>; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function App() { |
|
|
|
function App() { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<SettingsProvider> |
|
|
|
<SettingsProvider> |
|
|
@ -42,25 +42,24 @@ function App() { |
|
|
|
<BookmarkContextProvider> |
|
|
|
<BookmarkContextProvider> |
|
|
|
<BannerContextProvider> |
|
|
|
<BannerContextProvider> |
|
|
|
<Layout> |
|
|
|
<Layout> |
|
|
|
<LegacyUrlView> |
|
|
|
|
|
|
|
<Switch> |
|
|
|
<Switch> |
|
|
|
{/* functional routes */} |
|
|
|
{/* functional routes */} |
|
|
|
<Route |
|
|
|
<Route exact path="/v2-migration" component={V2MigrationView} /> |
|
|
|
exact |
|
|
|
|
|
|
|
path="/v2-migration" |
|
|
|
|
|
|
|
component={V2MigrationView} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
<Route exact path="/"> |
|
|
|
<Route exact path="/"> |
|
|
|
<Redirect to={`/search/${MWMediaType.MOVIE}`} /> |
|
|
|
<Redirect to={`/search/${MWMediaType.MOVIE}`} /> |
|
|
|
</Route> |
|
|
|
</Route> |
|
|
|
|
|
|
|
|
|
|
|
{/* pages */} |
|
|
|
{/* pages */} |
|
|
|
<Route exact path="/media/:media" component={MediaView} /> |
|
|
|
<Route exact path="/media/:media"> |
|
|
|
<Route |
|
|
|
<LegacyUrlView> |
|
|
|
exact |
|
|
|
<MediaView /> |
|
|
|
path="/media/:media/:season/:episode" |
|
|
|
</LegacyUrlView> |
|
|
|
component={MediaView} |
|
|
|
</Route> |
|
|
|
/> |
|
|
|
<Route exact path="/media/:media/:season/:episode"> |
|
|
|
|
|
|
|
<LegacyUrlView> |
|
|
|
|
|
|
|
<MediaView /> |
|
|
|
|
|
|
|
</LegacyUrlView> |
|
|
|
|
|
|
|
</Route> |
|
|
|
<Route |
|
|
|
<Route |
|
|
|
exact |
|
|
|
exact |
|
|
|
path="/search/:type/:query?" |
|
|
|
path="/search/:type/:query?" |
|
|
@ -111,7 +110,6 @@ function App() { |
|
|
|
) : null} |
|
|
|
) : null} |
|
|
|
<Route path="*" component={NotFoundPage} /> |
|
|
|
<Route path="*" component={NotFoundPage} /> |
|
|
|
</Switch> |
|
|
|
</Switch> |
|
|
|
</LegacyUrlView> |
|
|
|
|
|
|
|
</Layout> |
|
|
|
</Layout> |
|
|
|
</BannerContextProvider> |
|
|
|
</BannerContextProvider> |
|
|
|
</BookmarkContextProvider> |
|
|
|
</BookmarkContextProvider> |
|
|
|