blob: 626ec6a4dcd20b4c6261ceec9d6854df7d571cd3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
import React, { FunctionComponent, useMemo } from "react";
import { Redirect, Route, Switch, useHistory } from "react-router-dom";
import { useDidMount } from "rooks";
import { useIsRadarrEnabled, useIsSonarrEnabled } from "../@redux/hooks/site";
import BlacklistRouter from "../Blacklist/Router";
import DisplayItemRouter from "../DisplayItem/Router";
import HistoryRouter from "../History/Router";
import SettingRouter from "../Settings/Router";
import EmptyPage, { RouterEmptyPath } from "../special-pages/404";
import SystemRouter from "../System/Router";
import { ScrollToTop } from "../utilities";
import WantedRouter from "../Wanted/Router";
const Router: FunctionComponent<{ className?: string }> = ({ className }) => {
const sonarr = useIsSonarrEnabled();
const radarr = useIsRadarrEnabled();
const redirectPath = useMemo(() => {
if (sonarr) {
return "/series";
} else if (radarr) {
return "/movies";
} else {
return "/settings";
}
}, [sonarr, radarr]);
const history = useHistory();
useDidMount(() => {
history.listen(() => {
// This is a hack to make sure ScrollToTop will be triggered in the next frame (When everything are loaded)
setTimeout(ScrollToTop);
});
});
return (
<div className={className}>
<Switch>
<Route exact path="/">
<Redirect exact to={redirectPath}></Redirect>
</Route>
<Route path={["/series", "/movies"]}>
<DisplayItemRouter></DisplayItemRouter>
</Route>
<Route path="/wanted">
<WantedRouter></WantedRouter>
</Route>
<Route path="/history">
<HistoryRouter></HistoryRouter>
</Route>
<Route path="/blacklist">
<BlacklistRouter></BlacklistRouter>
</Route>
<Route path="/settings">
<SettingRouter></SettingRouter>
</Route>
<Route path="/system">
<SystemRouter></SystemRouter>
</Route>
<Route exact path={RouterEmptyPath}>
<EmptyPage></EmptyPage>
</Route>
<Route path="*">
<Redirect to={RouterEmptyPath}></Redirect>
</Route>
</Switch>
</div>
);
};
export default Router;
|