2019-11-07 20:39:22 +01:00
|
|
|
// @flow
|
2019-12-02 18:30:08 +01:00
|
|
|
import React, { useEffect } from 'react';
|
2020-02-05 15:49:03 +01:00
|
|
|
import { Route, Redirect, Switch, withRouter } from 'react-router-dom';
|
2020-10-30 05:19:05 +01:00
|
|
|
|
2021-06-11 08:06:29 +02:00
|
|
|
import * as PAGES from 'constants/pages';
|
Add page titles (affects browser Tab, History, etc.)
## Issue
- While changing the "Back" behavior in the Settings Page PR, it was a pain to troubleshoot when the entire history list is listed as "odysee.com".
- If you have multiple tabs open, it's hard to know which is which for non-claim and non-channel pages.
## Approach
Initially, I thought of overriding the document's title through the `<Page>` component, since the titles are usually defined there. However, given that the router is already doing the overriding, I think it's best to do the same thing all in one place.
Downside: it might get missed when a new page is added.
## Unknown
- Not sure if are rules for titles. There seems to be a mix of sites -- some have specific titles per page, most just use the site title for each page.
- I think the `return` statement in the `useEffect` is unnecessary, since it'll just be setting to the same value now during the cleanup stage. (??)
2021-08-25 16:26:53 +02:00
|
|
|
import { PAGE_TITLE } from 'constants/pageTitles';
|
2021-12-08 16:14:03 +01:00
|
|
|
import { useIsLargeScreen } from 'effects/use-screensize';
|
2021-07-07 09:10:28 +02:00
|
|
|
import { lazyImport } from 'util/lazyImport';
|
2020-08-25 21:25:33 +02:00
|
|
|
import { LINKED_COMMENT_QUERY_PARAM } from 'constants/comment';
|
2021-10-17 10:36:14 +02:00
|
|
|
import { parseURI, isURIValid } from 'util/lbryURI';
|
2022-03-29 08:45:59 +02:00
|
|
|
import { SITE_TITLE } from 'config';
|
2021-06-01 05:04:26 +02:00
|
|
|
import LoadingBarOneOff from 'component/loadingBarOneOff';
|
2021-07-13 02:14:43 +02:00
|
|
|
import { GetLinksData } from 'util/buildHomepage';
|
2022-02-16 14:53:40 +01:00
|
|
|
import * as CS from 'constants/claim_search';
|
2022-03-22 19:03:39 +01:00
|
|
|
import { buildUnseenCountStr } from 'util/notifications';
|
2019-11-07 20:39:22 +01:00
|
|
|
|
2021-06-11 08:06:29 +02:00
|
|
|
import HomePage from 'page/home';
|
|
|
|
|
2021-07-07 09:10:28 +02:00
|
|
|
const Code2257Page = lazyImport(() => import('web/page/code2257' /* webpackChunkName: "code2257" */));
|
2021-10-08 21:22:03 +02:00
|
|
|
const PrivacyPolicyPage = lazyImport(() => import('web/page/privacypolicy' /* webpackChunkName: "privacypolicy" */));
|
|
|
|
const TOSPage = lazyImport(() => import('web/page/tos' /* webpackChunkName: "tos" */));
|
2022-03-15 20:07:31 +01:00
|
|
|
const FypPage = lazyImport(() => import('web/page/fyp' /* webpackChunkName: "fyp" */));
|
2021-10-08 21:22:03 +02:00
|
|
|
const YouTubeTOSPage = lazyImport(() => import('web/page/youtubetos' /* webpackChunkName: "youtubetos" */));
|
2021-06-11 08:06:29 +02:00
|
|
|
|
2021-10-26 08:15:08 +02:00
|
|
|
const SignInPage = lazyImport(() => import('page/signIn' /* webpackChunkName: "signIn" */));
|
2021-07-13 02:14:43 +02:00
|
|
|
const SignInWalletPasswordPage = lazyImport(() =>
|
2021-10-26 08:15:08 +02:00
|
|
|
import('page/signInWalletPassword' /* webpackChunkName: "signInWalletPassword" */)
|
2021-07-13 02:14:43 +02:00
|
|
|
);
|
2021-10-26 08:15:08 +02:00
|
|
|
const SignUpPage = lazyImport(() => import('page/signUp' /* webpackChunkName: "signUp" */));
|
|
|
|
const SignInVerifyPage = lazyImport(() => import('page/signInVerify' /* webpackChunkName: "signInVerify" */));
|
2021-06-11 08:06:29 +02:00
|
|
|
|
2021-10-26 08:15:08 +02:00
|
|
|
const BuyPage = lazyImport(() => import('page/buy' /* webpackChunkName: "buy" */));
|
|
|
|
const ReceivePage = lazyImport(() => import('page/receive' /* webpackChunkName: "receive" */));
|
|
|
|
const SendPage = lazyImport(() => import('page/send' /* webpackChunkName: "send" */));
|
|
|
|
const SwapPage = lazyImport(() => import('page/swap' /* webpackChunkName: "swap" */));
|
|
|
|
const WalletPage = lazyImport(() => import('page/wallet' /* webpackChunkName: "wallet" */));
|
2021-06-11 08:06:29 +02:00
|
|
|
|
2021-10-26 08:15:08 +02:00
|
|
|
const NotificationsPage = lazyImport(() => import('page/notifications' /* webpackChunkName: "notifications" */));
|
|
|
|
const CollectionPage = lazyImport(() => import('page/collection' /* webpackChunkName: "collection" */));
|
|
|
|
const ChannelNew = lazyImport(() => import('page/channelNew' /* webpackChunkName: "channelNew" */));
|
2021-07-13 02:14:43 +02:00
|
|
|
const ChannelsFollowingDiscoverPage = lazyImport(() =>
|
2021-10-26 08:15:08 +02:00
|
|
|
import('page/channelsFollowingDiscover' /* webpackChunkName: "channelsFollowingDiscover" */)
|
2021-07-13 02:14:43 +02:00
|
|
|
);
|
2021-10-26 08:15:08 +02:00
|
|
|
const ChannelsFollowingPage = lazyImport(() =>
|
|
|
|
import('page/channelsFollowing' /* webpackChunkName: "channelsFollowing" */)
|
|
|
|
);
|
2022-03-01 04:19:20 +01:00
|
|
|
const ChannelsFollowingManage = lazyImport(() =>
|
|
|
|
import('page/channelsFollowingManage' /* webpackChunkName: "channelsFollowing" */)
|
|
|
|
);
|
2021-10-26 08:15:08 +02:00
|
|
|
const ChannelsPage = lazyImport(() => import('page/channels' /* webpackChunkName: "channels" */));
|
2021-07-19 16:12:47 +02:00
|
|
|
const CheckoutPage = lazyImport(() => import('page/checkoutPage' /* webpackChunkName: "checkoutPage" */));
|
2021-10-26 08:15:08 +02:00
|
|
|
const CreatorDashboard = lazyImport(() => import('page/creatorDashboard' /* webpackChunkName: "creatorDashboard" */));
|
|
|
|
const DiscoverPage = lazyImport(() => import('page/discover' /* webpackChunkName: "discover" */));
|
|
|
|
const EmbedWrapperPage = lazyImport(() => import('page/embedWrapper' /* webpackChunkName: "embedWrapper" */));
|
2022-01-14 21:24:16 +01:00
|
|
|
const PopoutChatPage = lazyImport(() => import('page/popoutChatWrapper' /* webpackChunkName: "popoutChat" */));
|
2021-10-26 08:15:08 +02:00
|
|
|
const FileListPublished = lazyImport(() =>
|
|
|
|
import('page/fileListPublished' /* webpackChunkName: "fileListPublished" */)
|
|
|
|
);
|
2021-07-19 16:12:47 +02:00
|
|
|
const FourOhFourPage = lazyImport(() => import('page/fourOhFour' /* webpackChunkName: "fourOhFour" */));
|
2021-07-07 09:10:28 +02:00
|
|
|
const HelpPage = lazyImport(() => import('page/help' /* webpackChunkName: "help" */));
|
2021-10-26 08:15:08 +02:00
|
|
|
const InvitePage = lazyImport(() => import('page/invite' /* webpackChunkName: "invite" */));
|
|
|
|
const InvitedPage = lazyImport(() => import('page/invited' /* webpackChunkName: "invited" */));
|
|
|
|
const LibraryPage = lazyImport(() => import('page/library' /* webpackChunkName: "library" */));
|
|
|
|
const ListBlockedPage = lazyImport(() => import('page/listBlocked' /* webpackChunkName: "listBlocked" */));
|
|
|
|
const ListsPage = lazyImport(() => import('page/lists' /* webpackChunkName: "lists" */));
|
2021-11-06 02:00:27 +01:00
|
|
|
const PlaylistsPage = lazyImport(() => import('page/playlists' /* webpackChunkName: "lists" */));
|
2022-05-03 13:21:51 +02:00
|
|
|
const WatchHistoryPage = lazyImport(() => import('page/watchHistory' /* webpackChunkName: "history" */));
|
2021-10-26 08:15:08 +02:00
|
|
|
const LiveStreamSetupPage = lazyImport(() => import('page/livestreamSetup' /* webpackChunkName: "livestreamSetup" */));
|
|
|
|
const LivestreamCurrentPage = lazyImport(() =>
|
|
|
|
import('page/livestreamCurrent' /* webpackChunkName: "livestreamCurrent" */)
|
|
|
|
);
|
2022-03-09 19:05:37 +01:00
|
|
|
const OdyseeMembershipPage = lazyImport(() =>
|
|
|
|
import('page/odyseeMembership' /* webpackChunkName: "odyseeMembership" */)
|
|
|
|
);
|
2021-10-01 14:10:27 +02:00
|
|
|
const OwnComments = lazyImport(() => import('page/ownComments' /* webpackChunkName: "ownComments" */));
|
2021-10-26 08:15:08 +02:00
|
|
|
const PasswordResetPage = lazyImport(() => import('page/passwordReset' /* webpackChunkName: "passwordReset" */));
|
|
|
|
const PasswordSetPage = lazyImport(() => import('page/passwordSet' /* webpackChunkName: "passwordSet" */));
|
|
|
|
const PublishPage = lazyImport(() => import('page/publish' /* webpackChunkName: "publish" */));
|
|
|
|
const ReportContentPage = lazyImport(() => import('page/reportContent' /* webpackChunkName: "reportContent" */));
|
|
|
|
const ReportPage = lazyImport(() => import('page/report' /* webpackChunkName: "report" */));
|
2022-05-03 13:57:39 +02:00
|
|
|
const RepostNew = lazyImport(() => import('page/repost' /* webpackChunkName: "repost" */));
|
2021-10-26 08:15:08 +02:00
|
|
|
const RewardsPage = lazyImport(() => import('page/rewards' /* webpackChunkName: "rewards" */));
|
|
|
|
const RewardsVerifyPage = lazyImport(() => import('page/rewardsVerify' /* webpackChunkName: "rewardsVerify" */));
|
|
|
|
const SearchPage = lazyImport(() => import('page/search' /* webpackChunkName: "search" */));
|
|
|
|
const SettingsStripeCard = lazyImport(() =>
|
|
|
|
import('page/settingsStripeCard' /* webpackChunkName: "settingsStripeCard" */)
|
|
|
|
);
|
2021-08-08 10:26:43 +02:00
|
|
|
const SettingsStripeAccount = lazyImport(() =>
|
2021-10-26 08:15:08 +02:00
|
|
|
import('page/settingsStripeAccount' /* webpackChunkName: "settingsStripeAccount" */)
|
2021-08-08 10:26:43 +02:00
|
|
|
);
|
2021-10-26 08:15:08 +02:00
|
|
|
const SettingsCreatorPage = lazyImport(() => import('page/settingsCreator' /* webpackChunkName: "settingsCreator" */));
|
2021-07-13 02:14:43 +02:00
|
|
|
const SettingsNotificationsPage = lazyImport(() =>
|
2021-10-26 08:15:08 +02:00
|
|
|
import('page/settingsNotifications' /* webpackChunkName: "settingsNotifications" */)
|
2021-07-13 02:14:43 +02:00
|
|
|
);
|
2021-10-26 08:15:08 +02:00
|
|
|
const SettingsPage = lazyImport(() => import('page/settings' /* webpackChunkName: "settings" */));
|
|
|
|
const ShowPage = lazyImport(() => import('page/show' /* webpackChunkName: "show" */));
|
2021-07-13 02:14:43 +02:00
|
|
|
const TagsFollowingManagePage = lazyImport(() =>
|
2021-10-26 08:15:08 +02:00
|
|
|
import('page/tagsFollowingManage' /* webpackChunkName: "tagsFollowingManage" */)
|
2021-07-13 02:14:43 +02:00
|
|
|
);
|
2021-10-26 08:15:08 +02:00
|
|
|
const TagsFollowingPage = lazyImport(() => import('page/tagsFollowing' /* webpackChunkName: "tagsFollowing" */));
|
|
|
|
const TopPage = lazyImport(() => import('page/top' /* webpackChunkName: "top" */));
|
2021-08-23 08:18:27 +02:00
|
|
|
const UpdatePasswordPage = lazyImport(() => import('page/passwordUpdate' /* webpackChunkName: "passwordUpdate" */));
|
2021-10-26 08:15:08 +02:00
|
|
|
const YoutubeSyncPage = lazyImport(() => import('page/youtubeSync' /* webpackChunkName: "youtubeSync" */));
|
2019-11-07 20:39:22 +01:00
|
|
|
|
|
|
|
// Tell the browser we are handling scroll restoration
|
|
|
|
if ('scrollRestoration' in history) {
|
|
|
|
history.scrollRestoration = 'manual';
|
|
|
|
}
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
currentScroll: number,
|
|
|
|
isAuthenticated: boolean,
|
2020-11-25 18:09:58 +01:00
|
|
|
location: { pathname: string, search: string, hash: string },
|
2020-01-25 21:37:02 +01:00
|
|
|
history: {
|
2020-11-25 18:09:58 +01:00
|
|
|
action: string,
|
2020-01-25 21:37:02 +01:00
|
|
|
entries: { title: string }[],
|
|
|
|
goBack: () => void,
|
|
|
|
goForward: () => void,
|
|
|
|
index: number,
|
|
|
|
length: number,
|
|
|
|
location: { pathname: string },
|
2021-02-16 22:09:20 +01:00
|
|
|
push: (string) => void,
|
2020-01-25 21:37:02 +01:00
|
|
|
state: {},
|
|
|
|
replaceState: ({}, string, string) => void,
|
2021-02-16 22:09:20 +01:00
|
|
|
listen: (any) => () => void,
|
2020-01-25 21:37:02 +01:00
|
|
|
},
|
|
|
|
uri: string,
|
|
|
|
title: string,
|
2020-07-10 23:04:36 +02:00
|
|
|
hasNavigated: boolean,
|
|
|
|
setHasNavigated: () => void,
|
2021-10-17 10:36:14 +02:00
|
|
|
setReferrer: (?string) => void,
|
2020-10-07 02:59:38 +02:00
|
|
|
hasUnclaimedRefereeReward: boolean,
|
2020-11-10 17:07:00 +01:00
|
|
|
homepageData: any,
|
2022-02-15 18:36:33 +01:00
|
|
|
wildWestDisabled: boolean,
|
2022-03-22 19:03:39 +01:00
|
|
|
unseenCount: number,
|
2022-03-31 16:19:19 +02:00
|
|
|
hideTitleNotificationCount: boolean,
|
2022-05-04 15:59:10 +02:00
|
|
|
hasDefaultChannel: boolean,
|
2022-05-10 14:01:19 +02:00
|
|
|
doSetActiveChannel: (claimId: ?string, override?: boolean) => void,
|
2022-05-09 16:47:17 +02:00
|
|
|
embedLatestPath: ?boolean,
|
2019-11-07 20:39:22 +01:00
|
|
|
};
|
|
|
|
|
2020-10-30 05:19:05 +01:00
|
|
|
type PrivateRouteProps = Props & {
|
|
|
|
component: any,
|
|
|
|
isAuthenticated: boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
function PrivateRoute(props: PrivateRouteProps) {
|
|
|
|
const { component: Component, isAuthenticated, ...rest } = props;
|
2021-04-03 06:28:54 +02:00
|
|
|
const urlSearchParams = new URLSearchParams(props.location.search);
|
|
|
|
const redirectUrl = urlSearchParams.get('redirect');
|
2020-10-30 05:19:05 +01:00
|
|
|
return (
|
|
|
|
<Route
|
|
|
|
{...rest}
|
2021-02-16 22:09:20 +01:00
|
|
|
render={(props) =>
|
2020-10-30 05:19:05 +01:00
|
|
|
isAuthenticated || !IS_WEB ? (
|
|
|
|
<Component {...props} />
|
|
|
|
) : (
|
2021-04-03 06:28:54 +02:00
|
|
|
<Redirect to={`/$/${PAGES.AUTH}?redirect=${redirectUrl || props.location.pathname}`} />
|
2020-10-30 05:19:05 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-07 20:39:22 +01:00
|
|
|
function AppRouter(props: Props) {
|
2020-02-05 15:49:03 +01:00
|
|
|
const {
|
|
|
|
currentScroll,
|
2020-11-25 18:09:58 +01:00
|
|
|
location: { pathname, search, hash },
|
2020-02-05 15:49:03 +01:00
|
|
|
isAuthenticated,
|
2020-01-25 21:37:02 +01:00
|
|
|
history,
|
|
|
|
uri,
|
|
|
|
title,
|
2020-07-10 23:04:36 +02:00
|
|
|
hasNavigated,
|
|
|
|
setHasNavigated,
|
2020-10-07 02:59:38 +02:00
|
|
|
hasUnclaimedRefereeReward,
|
|
|
|
setReferrer,
|
2020-11-10 17:07:00 +01:00
|
|
|
homepageData,
|
2022-02-15 18:36:33 +01:00
|
|
|
wildWestDisabled,
|
2022-03-22 19:03:39 +01:00
|
|
|
unseenCount,
|
2022-03-31 16:19:19 +02:00
|
|
|
hideTitleNotificationCount,
|
2022-05-04 15:59:10 +02:00
|
|
|
hasDefaultChannel,
|
2022-05-10 14:01:19 +02:00
|
|
|
doSetActiveChannel,
|
2022-05-09 16:47:17 +02:00
|
|
|
embedLatestPath,
|
2020-02-05 15:49:03 +01:00
|
|
|
} = props;
|
2022-02-15 18:36:33 +01:00
|
|
|
|
2022-05-04 15:59:10 +02:00
|
|
|
const defaultChannelRef = React.useRef(hasDefaultChannel);
|
|
|
|
|
2021-04-03 06:28:54 +02:00
|
|
|
const { entries, listen, action: historyAction } = history;
|
2020-01-25 21:37:02 +01:00
|
|
|
const entryIndex = history.index;
|
2020-02-27 20:00:23 +01:00
|
|
|
const urlParams = new URLSearchParams(search);
|
|
|
|
const resetScroll = urlParams.get('reset_scroll');
|
2020-08-25 21:25:33 +02:00
|
|
|
const hasLinkedCommentInUrl = urlParams.get(LINKED_COMMENT_QUERY_PARAM);
|
2022-02-16 14:53:40 +01:00
|
|
|
const tagParams = urlParams.get(CS.TAGS_KEY);
|
2021-12-08 16:14:03 +01:00
|
|
|
const isLargeScreen = useIsLargeScreen();
|
2020-01-25 21:37:02 +01:00
|
|
|
|
2022-04-19 09:12:54 +02:00
|
|
|
const categoryPages = React.useMemo(() => {
|
2021-12-08 16:36:23 +01:00
|
|
|
const dynamicRoutes = GetLinksData(homepageData, isLargeScreen).filter(
|
2022-04-19 09:12:54 +02:00
|
|
|
(x: any) => x && x.route && (x.id !== 'WILD_WEST' || !wildWestDisabled)
|
2021-12-08 16:14:03 +01:00
|
|
|
);
|
2021-12-08 16:36:23 +01:00
|
|
|
|
|
|
|
return dynamicRoutes.map((dynamicRouteProps: RowDataItem) => (
|
|
|
|
<Route
|
|
|
|
key={dynamicRouteProps.route}
|
|
|
|
path={dynamicRouteProps.route}
|
2022-04-19 13:29:39 +02:00
|
|
|
component={(routerProps) => <DiscoverPage {...routerProps} dynamicRouteProps={dynamicRouteProps} />}
|
2021-12-08 16:36:23 +01:00
|
|
|
/>
|
|
|
|
));
|
2022-04-19 09:12:54 +02:00
|
|
|
}, [homepageData, isLargeScreen, wildWestDisabled]);
|
2020-11-10 17:07:00 +01:00
|
|
|
|
2020-07-30 21:14:22 +02:00
|
|
|
// For people arriving at settings page from deeplinks, know whether they can "go back"
|
2020-07-10 23:04:36 +02:00
|
|
|
useEffect(() => {
|
2021-04-03 06:28:54 +02:00
|
|
|
const unlisten = listen((location, action) => {
|
2020-07-10 23:04:36 +02:00
|
|
|
if (action === 'PUSH') {
|
|
|
|
if (!hasNavigated && setHasNavigated) setHasNavigated();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return unlisten;
|
2021-04-03 06:28:54 +02:00
|
|
|
}, [listen, hasNavigated, setHasNavigated]);
|
2020-07-10 23:04:36 +02:00
|
|
|
|
2020-10-07 02:59:38 +02:00
|
|
|
useEffect(() => {
|
2020-10-07 19:02:09 +02:00
|
|
|
if (!hasNavigated && hasUnclaimedRefereeReward && !isAuthenticated) {
|
2020-10-07 02:59:38 +02:00
|
|
|
const valid = isURIValid(uri);
|
|
|
|
if (valid) {
|
|
|
|
const { path } = parseURI(uri);
|
2020-10-07 19:02:09 +02:00
|
|
|
if (path !== 'undefined') setReferrer(path);
|
2020-10-07 02:59:38 +02:00
|
|
|
}
|
|
|
|
}
|
2020-10-07 19:02:09 +02:00
|
|
|
}, [hasNavigated, uri, hasUnclaimedRefereeReward, setReferrer, isAuthenticated]);
|
2020-10-07 02:59:38 +02:00
|
|
|
|
2020-01-25 21:37:02 +01:00
|
|
|
useEffect(() => {
|
Add page titles (affects browser Tab, History, etc.)
## Issue
- While changing the "Back" behavior in the Settings Page PR, it was a pain to troubleshoot when the entire history list is listed as "odysee.com".
- If you have multiple tabs open, it's hard to know which is which for non-claim and non-channel pages.
## Approach
Initially, I thought of overriding the document's title through the `<Page>` component, since the titles are usually defined there. However, given that the router is already doing the overriding, I think it's best to do the same thing all in one place.
Downside: it might get missed when a new page is added.
## Unknown
- Not sure if are rules for titles. There seems to be a mix of sites -- some have specific titles per page, most just use the site title for each page.
- I think the `return` statement in the `useEffect` is unnecessary, since it'll just be setting to the same value now during the cleanup stage. (??)
2021-08-25 16:26:53 +02:00
|
|
|
const getDefaultTitle = (pathname: string) => {
|
2022-04-29 09:57:23 +02:00
|
|
|
let title = '';
|
|
|
|
if (pathname.startsWith('/$/')) {
|
|
|
|
const name = pathname.substring(3);
|
|
|
|
if (window.CATEGORY_PAGE_TITLE && window.CATEGORY_PAGE_TITLE[name]) {
|
|
|
|
title = window.CATEGORY_PAGE_TITLE[name];
|
|
|
|
} else {
|
|
|
|
title = PAGE_TITLE[name];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return __(title) || SITE_TITLE || 'Odysee';
|
Add page titles (affects browser Tab, History, etc.)
## Issue
- While changing the "Back" behavior in the Settings Page PR, it was a pain to troubleshoot when the entire history list is listed as "odysee.com".
- If you have multiple tabs open, it's hard to know which is which for non-claim and non-channel pages.
## Approach
Initially, I thought of overriding the document's title through the `<Page>` component, since the titles are usually defined there. However, given that the router is already doing the overriding, I think it's best to do the same thing all in one place.
Downside: it might get missed when a new page is added.
## Unknown
- Not sure if are rules for titles. There seems to be a mix of sites -- some have specific titles per page, most just use the site title for each page.
- I think the `return` statement in the `useEffect` is unnecessary, since it'll just be setting to the same value now during the cleanup stage. (??)
2021-08-25 16:26:53 +02:00
|
|
|
};
|
|
|
|
|
2020-02-13 02:48:28 +01:00
|
|
|
if (uri) {
|
|
|
|
const { channelName, streamName } = parseURI(uri);
|
|
|
|
|
2021-04-05 04:53:13 +02:00
|
|
|
if (title) {
|
2020-02-13 02:48:28 +01:00
|
|
|
document.title = title;
|
2021-04-05 04:53:13 +02:00
|
|
|
} else if (streamName) {
|
2020-02-13 02:48:28 +01:00
|
|
|
document.title = streamName;
|
2021-04-05 04:53:13 +02:00
|
|
|
} else if (channelName) {
|
2020-02-13 02:48:28 +01:00
|
|
|
document.title = channelName;
|
|
|
|
} else {
|
Add page titles (affects browser Tab, History, etc.)
## Issue
- While changing the "Back" behavior in the Settings Page PR, it was a pain to troubleshoot when the entire history list is listed as "odysee.com".
- If you have multiple tabs open, it's hard to know which is which for non-claim and non-channel pages.
## Approach
Initially, I thought of overriding the document's title through the `<Page>` component, since the titles are usually defined there. However, given that the router is already doing the overriding, I think it's best to do the same thing all in one place.
Downside: it might get missed when a new page is added.
## Unknown
- Not sure if are rules for titles. There seems to be a mix of sites -- some have specific titles per page, most just use the site title for each page.
- I think the `return` statement in the `useEffect` is unnecessary, since it'll just be setting to the same value now during the cleanup stage. (??)
2021-08-25 16:26:53 +02:00
|
|
|
document.title = getDefaultTitle(pathname);
|
2020-02-13 02:48:28 +01:00
|
|
|
}
|
2020-01-25 21:37:02 +01:00
|
|
|
} else {
|
Add page titles (affects browser Tab, History, etc.)
## Issue
- While changing the "Back" behavior in the Settings Page PR, it was a pain to troubleshoot when the entire history list is listed as "odysee.com".
- If you have multiple tabs open, it's hard to know which is which for non-claim and non-channel pages.
## Approach
Initially, I thought of overriding the document's title through the `<Page>` component, since the titles are usually defined there. However, given that the router is already doing the overriding, I think it's best to do the same thing all in one place.
Downside: it might get missed when a new page is added.
## Unknown
- Not sure if are rules for titles. There seems to be a mix of sites -- some have specific titles per page, most just use the site title for each page.
- I think the `return` statement in the `useEffect` is unnecessary, since it'll just be setting to the same value now during the cleanup stage. (??)
2021-08-25 16:26:53 +02:00
|
|
|
document.title = getDefaultTitle(pathname);
|
2020-01-25 21:37:02 +01:00
|
|
|
}
|
|
|
|
|
2022-03-31 16:19:19 +02:00
|
|
|
if (unseenCount > 0 && !hideTitleNotificationCount) {
|
2022-03-22 19:03:39 +01:00
|
|
|
document.title = `(${buildUnseenCountStr(unseenCount)}) ${document.title}`;
|
|
|
|
}
|
2022-05-10 14:01:19 +02:00
|
|
|
}, [pathname, entries, entryIndex, title, uri, unseenCount, hideTitleNotificationCount]);
|
2019-11-07 20:39:22 +01:00
|
|
|
|
|
|
|
useEffect(() => {
|
2020-08-25 21:25:33 +02:00
|
|
|
if (!hasLinkedCommentInUrl) {
|
2021-04-03 06:28:54 +02:00
|
|
|
if (hash && historyAction === 'PUSH') {
|
2020-11-25 18:09:58 +01:00
|
|
|
const id = hash.replace('#', '');
|
|
|
|
const element = document.getElementById(id);
|
|
|
|
if (element) {
|
|
|
|
window.scrollTo(0, element.offsetTop);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
window.scrollTo(0, currentScroll);
|
|
|
|
}
|
2020-08-25 21:25:33 +02:00
|
|
|
}
|
2021-04-03 06:28:54 +02:00
|
|
|
}, [currentScroll, pathname, search, hash, resetScroll, hasLinkedCommentInUrl, historyAction]);
|
2019-11-07 20:39:22 +01:00
|
|
|
|
2022-05-04 15:59:10 +02:00
|
|
|
React.useEffect(() => {
|
|
|
|
defaultChannelRef.current = hasDefaultChannel;
|
|
|
|
}, [hasDefaultChannel]);
|
|
|
|
|
2022-05-10 14:01:19 +02:00
|
|
|
React.useEffect(() => {
|
|
|
|
// has a default channel selected, clear the current active channel
|
|
|
|
if (
|
|
|
|
defaultChannelRef.current &&
|
|
|
|
pathname !== `/$/${PAGES.UPLOAD}` &&
|
|
|
|
!pathname.includes(`/$/${PAGES.LIST}/`) &&
|
|
|
|
pathname !== `/$/${PAGES.CREATOR_DASHBOARD}` &&
|
|
|
|
pathname !== `/$/${PAGES.LIVESTREAM}`
|
|
|
|
) {
|
|
|
|
doSetActiveChannel(null, true);
|
|
|
|
}
|
|
|
|
// only on pathname change
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [pathname]);
|
|
|
|
|
2020-01-29 21:21:03 +01:00
|
|
|
// react-router doesn't decode pathanmes before doing the route matching check
|
|
|
|
// We have to redirect here because if we redirect on the server, it might get encoded again
|
|
|
|
// in the browser causing a redirect loop
|
2020-03-31 22:35:33 +02:00
|
|
|
const decodedUrl = decodeURIComponent(pathname) + search;
|
2020-03-30 22:47:07 +02:00
|
|
|
if (decodedUrl !== pathname + search) {
|
|
|
|
return <Redirect to={decodedUrl} />;
|
2020-01-29 21:21:03 +01:00
|
|
|
}
|
|
|
|
|
2019-11-07 20:39:22 +01:00
|
|
|
return (
|
2021-06-01 05:04:26 +02:00
|
|
|
<React.Suspense fallback={<LoadingBarOneOff />}>
|
2022-05-29 09:51:55 +02:00
|
|
|
{categoryPages.length && (
|
|
|
|
<Switch>
|
|
|
|
<Redirect
|
|
|
|
from={`/$/${PAGES.DEPRECATED__CHANNELS_FOLLOWING_MANAGE}`}
|
|
|
|
to={`/$/${PAGES.CHANNELS_FOLLOWING_DISCOVER}`}
|
|
|
|
/>
|
|
|
|
<Redirect from={`/$/${PAGES.DEPRECATED__CHANNELS_FOLLOWING}`} to={`/$/${PAGES.CHANNELS_FOLLOWING}`} />
|
|
|
|
<Redirect from={`/$/${PAGES.DEPRECATED__TAGS_FOLLOWING}`} to={`/$/${PAGES.TAGS_FOLLOWING}`} />
|
|
|
|
<Redirect from={`/$/${PAGES.DEPRECATED__TAGS_FOLLOWING_MANAGE}`} to={`/$/${PAGES.TAGS_FOLLOWING_MANAGE}`} />
|
|
|
|
<Redirect from={`/$/${PAGES.DEPRECATED__PUBLISH}`} to={`/$/${PAGES.UPLOAD}`} />
|
|
|
|
<Redirect from={`/$/${PAGES.DEPRECATED__PUBLISHED}`} to={`/$/${PAGES.UPLOADS}`} />
|
|
|
|
|
|
|
|
<Route path={`/`} exact component={HomePage} />
|
|
|
|
|
|
|
|
{(!wildWestDisabled || tagParams) && <Route path={`/$/${PAGES.DISCOVER}`} exact component={DiscoverPage} />}
|
|
|
|
{categoryPages}
|
|
|
|
|
|
|
|
<Route path={`/$/${PAGES.AUTH_SIGNIN}`} exact component={SignInPage} />
|
|
|
|
<Route path={`/$/${PAGES.AUTH_PASSWORD_RESET}`} exact component={PasswordResetPage} />
|
|
|
|
<Route path={`/$/${PAGES.AUTH_PASSWORD_SET}`} exact component={PasswordSetPage} />
|
|
|
|
<Route path={`/$/${PAGES.AUTH}`} exact component={SignUpPage} />
|
|
|
|
<Route path={`/$/${PAGES.AUTH}/*`} exact component={SignUpPage} />
|
|
|
|
|
|
|
|
<Route path={`/$/${PAGES.HELP}`} exact component={HelpPage} />
|
|
|
|
|
|
|
|
<Route path={`/$/${PAGES.CODE_2257}`} exact component={Code2257Page} />
|
|
|
|
<Route path={`/$/${PAGES.PRIVACY_POLICY}`} exact component={PrivacyPolicyPage} />
|
|
|
|
<Route path={`/$/${PAGES.TOS}`} exact component={TOSPage} />
|
|
|
|
<Route path={`/$/${PAGES.FYP}`} exact component={FypPage} />
|
|
|
|
<Route path={`/$/${PAGES.YOUTUBE_TOS}`} exact component={YouTubeTOSPage} />
|
|
|
|
|
|
|
|
<Route path={`/$/${PAGES.AUTH_VERIFY}`} exact component={SignInVerifyPage} />
|
|
|
|
<Route path={`/$/${PAGES.SEARCH}`} exact component={SearchPage} />
|
|
|
|
<Route path={`/$/${PAGES.TOP}`} exact component={TopPage} />
|
|
|
|
<Route path={`/$/${PAGES.SETTINGS}`} exact component={SettingsPage} />
|
|
|
|
<Route path={`/$/${PAGES.INVITE}/:referrer`} exact component={InvitedPage} />
|
|
|
|
<Route path={`/$/${PAGES.CHECKOUT}`} exact component={CheckoutPage} />
|
|
|
|
<Route path={`/$/${PAGES.REPORT_CONTENT}`} exact component={ReportContentPage} />
|
|
|
|
<Route {...props} path={`/$/${PAGES.LIST}/:collectionId`} component={CollectionPage} />
|
|
|
|
|
|
|
|
<PrivateRoute {...props} exact path={`/$/${PAGES.YOUTUBE_SYNC}`} component={YoutubeSyncPage} />
|
|
|
|
<PrivateRoute {...props} exact path={`/$/${PAGES.TAGS_FOLLOWING}`} component={TagsFollowingPage} />
|
|
|
|
<PrivateRoute
|
|
|
|
{...props}
|
|
|
|
exact
|
|
|
|
path={`/$/${PAGES.CHANNELS_FOLLOWING}`}
|
|
|
|
component={isAuthenticated || !IS_WEB ? ChannelsFollowingPage : DiscoverPage}
|
|
|
|
/>
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.SETTINGS_NOTIFICATIONS}`} component={SettingsNotificationsPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.SETTINGS_STRIPE_CARD}`} component={SettingsStripeCard} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.SETTINGS_STRIPE_ACCOUNT}`} component={SettingsStripeAccount} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.SETTINGS_UPDATE_PWD}`} component={UpdatePasswordPage} />
|
|
|
|
<PrivateRoute
|
|
|
|
{...props}
|
|
|
|
exact
|
|
|
|
path={`/$/${PAGES.CHANNELS_FOLLOWING_DISCOVER}`}
|
|
|
|
component={ChannelsFollowingDiscoverPage}
|
|
|
|
/>
|
|
|
|
<PrivateRoute
|
|
|
|
{...props}
|
|
|
|
exact
|
|
|
|
path={`/$/${PAGES.CHANNELS_FOLLOWING_MANAGE}`}
|
|
|
|
component={ChannelsFollowingManage}
|
|
|
|
/>
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.INVITE}`} component={InvitePage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.CHANNEL_NEW}`} component={ChannelNew} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.REPOST_NEW}`} component={RepostNew} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.UPLOADS}`} component={FileListPublished} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.CREATOR_DASHBOARD}`} component={CreatorDashboard} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.UPLOAD}`} component={PublishPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.REPORT}`} component={ReportPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.REWARDS}`} exact component={RewardsPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.REWARDS_VERIFY}`} component={RewardsVerifyPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.LIBRARY}`} component={LibraryPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.LISTS}`} component={ListsPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.PLAYLISTS}`} component={PlaylistsPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.WATCH_HISTORY}`} component={WatchHistoryPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.TAGS_FOLLOWING_MANAGE}`} component={TagsFollowingManagePage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.SETTINGS_BLOCKED_MUTED}`} component={ListBlockedPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.SETTINGS_CREATOR}`} component={SettingsCreatorPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.WALLET}`} exact component={WalletPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.CHANNELS}`} component={ChannelsPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.LIVESTREAM}`} component={LiveStreamSetupPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.LIVESTREAM_CURRENT}`} component={LivestreamCurrentPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.BUY}`} component={BuyPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.RECEIVE}`} component={ReceivePage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.SEND}`} component={SendPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.SWAP}`} component={SwapPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.NOTIFICATIONS}`} component={NotificationsPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.AUTH_WALLET_PASSWORD}`} component={SignInWalletPasswordPage} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.SETTINGS_OWN_COMMENTS}`} component={OwnComments} />
|
|
|
|
<PrivateRoute {...props} path={`/$/${PAGES.ODYSEE_MEMBERSHIP}`} component={OdyseeMembershipPage} />
|
|
|
|
|
|
|
|
<Route path={`/$/${PAGES.POPOUT}/:channelName/:streamName`} component={PopoutChatPage} />
|
|
|
|
|
|
|
|
<Route
|
|
|
|
path={`/$/${PAGES.EMBED}/:claimName`}
|
|
|
|
exact
|
|
|
|
component={embedLatestPath ? () => <EmbedWrapperPage uri={uri} /> : EmbedWrapperPage}
|
|
|
|
/>
|
|
|
|
<Route path={`/$/${PAGES.EMBED}/:claimName/:claimId`} exact component={EmbedWrapperPage} />
|
|
|
|
|
|
|
|
{/* Below need to go at the end to make sure we don't match any of our pages first */}
|
|
|
|
<Route
|
|
|
|
path={`/$/${PAGES.LATEST}/:channelName`}
|
|
|
|
exact
|
|
|
|
render={() => <ShowPage uri={uri} latestContentPath />}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path={`/$/${PAGES.LIVE_NOW}/:channelName`}
|
|
|
|
exact
|
|
|
|
render={() => <ShowPage uri={uri} liveContentPath />}
|
|
|
|
/>
|
|
|
|
<Route path="/:claimName" exact render={() => <ShowPage uri={uri} />} />
|
|
|
|
<Route path="/:claimName/:streamName" exact render={() => <ShowPage uri={uri} />} />
|
|
|
|
<Route path="/*" component={FourOhFourPage} />
|
|
|
|
</Switch>
|
|
|
|
)}
|
2021-06-11 08:06:29 +02:00
|
|
|
</React.Suspense>
|
2019-11-07 20:39:22 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-02-05 15:49:03 +01:00
|
|
|
export default withRouter(AppRouter);
|