2019-11-07 20:39:22 +01:00
|
|
|
// @flow
|
|
|
|
import * as PAGES from 'constants/pages';
|
2019-12-02 18:30:08 +01:00
|
|
|
import React, { useEffect } from 'react';
|
2019-11-07 20:39:22 +01:00
|
|
|
import { Route, Redirect, Switch, withRouter } from 'react-router-dom';
|
|
|
|
import SettingsPage from 'page/settings';
|
|
|
|
import HelpPage from 'page/help';
|
|
|
|
import ReportPage from 'page/report';
|
|
|
|
import ShowPage from 'page/show';
|
|
|
|
import PublishPage from 'page/publish';
|
|
|
|
import DiscoverPage from 'page/discover';
|
2020-01-02 17:30:27 +01:00
|
|
|
// import HomePage from 'page/home';
|
2019-11-07 20:39:22 +01:00
|
|
|
import RewardsPage from 'page/rewards';
|
|
|
|
import FileListDownloaded from 'page/fileListDownloaded';
|
|
|
|
import FileListPublished from 'page/fileListPublished';
|
|
|
|
import TransactionHistoryPage from 'page/transactionHistory';
|
|
|
|
import InvitePage from 'page/invite';
|
|
|
|
import SearchPage from 'page/search';
|
|
|
|
import LibraryPage from 'page/library';
|
|
|
|
import WalletPage from 'page/wallet';
|
|
|
|
import TagsPage from 'page/tags';
|
2020-01-02 17:30:27 +01:00
|
|
|
import TagsFollowingPage from 'page/tagsFollowing';
|
|
|
|
import ChannelsFollowingPage from 'page/channelsFollowing';
|
|
|
|
import ChannelsFollowingManagePage from 'page/channelsFollowingManage';
|
2020-01-02 23:43:09 +01:00
|
|
|
import TagsFollowingManagePage from 'page/tagsFollowingManage';
|
2019-11-07 20:39:22 +01:00
|
|
|
import ListBlockedPage from 'page/listBlocked';
|
|
|
|
import FourOhFourPage from 'page/fourOhFour';
|
|
|
|
import SignInPage from 'page/signIn';
|
2019-11-14 01:33:36 +01:00
|
|
|
import SignInVerifyPage from 'page/signInVerify';
|
2019-11-07 20:39:22 +01:00
|
|
|
import ChannelsPage from 'page/channels';
|
|
|
|
|
|
|
|
// Tell the browser we are handling scroll restoration
|
|
|
|
if ('scrollRestoration' in history) {
|
|
|
|
history.scrollRestoration = 'manual';
|
|
|
|
}
|
|
|
|
|
|
|
|
type PrivateRouteProps = {
|
|
|
|
component: any,
|
|
|
|
isAuthenticated: boolean,
|
|
|
|
location: { pathname: string },
|
|
|
|
};
|
|
|
|
|
|
|
|
function PrivateRoute(props: PrivateRouteProps) {
|
|
|
|
const { component: Component, isAuthenticated, ...rest } = props;
|
|
|
|
return (
|
|
|
|
<Route
|
|
|
|
{...rest}
|
|
|
|
render={props =>
|
|
|
|
isAuthenticated || !IS_WEB ? (
|
|
|
|
<Component {...props} />
|
|
|
|
) : (
|
|
|
|
<Redirect to={`/$/${PAGES.AUTH}?redirect=${props.location.pathname}`} />
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
currentScroll: number,
|
|
|
|
location: { pathname: string, search: string },
|
|
|
|
isAuthenticated: boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
function AppRouter(props: Props) {
|
|
|
|
const {
|
|
|
|
currentScroll,
|
|
|
|
location: { pathname },
|
2020-01-02 22:26:43 +01:00
|
|
|
isAuthenticated,
|
2019-11-07 20:39:22 +01:00
|
|
|
} = props;
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
window.scrollTo(0, currentScroll);
|
|
|
|
}, [currentScroll, pathname]);
|
|
|
|
|
|
|
|
return (
|
2019-12-02 18:30:08 +01:00
|
|
|
<Switch>
|
2020-01-14 20:07:59 +01:00
|
|
|
<Route path={`/`} exact component={() => <Redirect to={`/$/${PAGES.CHANNELS_FOLLOWING}`} />} />
|
2019-12-02 18:30:08 +01:00
|
|
|
<Route path={`/$/${PAGES.DISCOVER}`} exact component={DiscoverPage} />
|
|
|
|
<Route path={`/$/${PAGES.AUTH}`} exact component={SignInPage} />
|
|
|
|
<Route path={`/$/${PAGES.TAGS}`} exact component={TagsPage} />
|
2020-01-02 17:30:27 +01:00
|
|
|
<Route path={`/$/${PAGES.TAGS_FOLLOWING}`} exact component={TagsFollowingPage} />
|
2020-01-02 22:26:43 +01:00
|
|
|
<Route
|
|
|
|
path={`/$/${PAGES.CHANNELS_FOLLOWING}`}
|
|
|
|
exact
|
|
|
|
component={isAuthenticated ? ChannelsFollowingPage : DiscoverPage}
|
|
|
|
/>
|
2020-01-02 17:30:27 +01:00
|
|
|
<Route path={`/$/${PAGES.CHANNELS_FOLLOWING_MANAGE}`} exact component={ChannelsFollowingManagePage} />
|
2019-12-02 18:30:08 +01:00
|
|
|
<Route path={`/$/${PAGES.HELP}`} exact component={HelpPage} />
|
|
|
|
<Route path={`/$/${PAGES.AUTH_VERIFY}`} exact component={SignInVerifyPage} />
|
|
|
|
<Route path={`/$/${PAGES.SEARCH}`} exact component={SearchPage} />
|
|
|
|
<Route path={`/$/${PAGES.SETTINGS}`} exact component={SettingsPage} />
|
2019-11-07 20:39:22 +01:00
|
|
|
|
2019-12-02 18:30:08 +01:00
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.INVITE}`} component={InvitePage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.DOWNLOADED}`} component={FileListDownloaded} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.PUBLISHED}`} component={FileListPublished} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.PUBLISH}`} component={PublishPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.REPORT}`} component={ReportPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.REWARDS}`} component={RewardsPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.TRANSACTIONS}`} component={TransactionHistoryPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.LIBRARY}`} component={LibraryPage} />
|
2020-01-02 23:43:09 +01:00
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.TAGS_FOLLOWING_MANAGE}`} component={TagsFollowingManagePage} />
|
2019-12-02 18:30:08 +01:00
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.BLOCKED}`} component={ListBlockedPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.WALLET}`} exact component={WalletPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.CHANNELS}`} component={ChannelsPage} />
|
2019-11-07 20:39:22 +01:00
|
|
|
|
2019-12-02 18:30:08 +01:00
|
|
|
{/* Below need to go at the end to make sure we don't match any of our pages first */}
|
|
|
|
<Route path="/:claimName" exact component={ShowPage} />
|
|
|
|
<Route path="/:claimName/:streamName" exact component={ShowPage} />
|
|
|
|
<Route path="/*" component={FourOhFourPage} />
|
|
|
|
</Switch>
|
2019-11-07 20:39:22 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withRouter(AppRouter);
|