2018-03-26 14:32:43 -07:00
|
|
|
// @flow
|
2019-10-22 13:57:32 -04:00
|
|
|
import * as PAGES from 'constants/pages';
|
2019-10-15 00:20:12 -04:00
|
|
|
import React, { useEffect, useRef, useState } from 'react';
|
2019-10-09 12:34:18 -04:00
|
|
|
import classnames from 'classnames';
|
2019-07-21 22:28:49 -04:00
|
|
|
import analytics from 'analytics';
|
2020-04-10 13:31:36 -04:00
|
|
|
import { buildURI, parseURI } from 'lbry-redux';
|
2017-12-21 18:08:54 -03:00
|
|
|
import Router from 'component/router/index';
|
|
|
|
import ModalRouter from 'modal/modalRouter';
|
|
|
|
import ReactModal from 'react-modal';
|
2019-01-23 10:38:40 -05:00
|
|
|
import { openContextMenu } from 'util/context-menu';
|
2019-06-11 14:10:58 -04:00
|
|
|
import useKonamiListener from 'util/enhanced-layout';
|
2019-03-04 23:46:57 -05:00
|
|
|
import Yrbl from 'component/yrbl';
|
2020-04-01 14:43:50 -04:00
|
|
|
import FileRenderFloating from 'component/fileRenderFloating';
|
2019-08-13 01:35:13 -04:00
|
|
|
import { withRouter } from 'react-router';
|
2019-09-27 14:56:15 -04:00
|
|
|
import usePrevious from 'effects/use-previous';
|
2019-12-06 16:12:48 -05:00
|
|
|
import Nag from 'component/common/nag';
|
2020-06-15 16:33:03 -04:00
|
|
|
import REWARDS from 'rewards';
|
2020-02-21 15:44:58 -05:00
|
|
|
import usePersistedState from 'effects/use-persisted-state';
|
2020-05-25 09:27:36 -05:00
|
|
|
import FileDrop from 'component/fileDrop';
|
2020-08-27 13:56:18 -04:00
|
|
|
import NagContinueFirstRun from 'component/nagContinueFirstRun';
|
2020-10-28 12:02:06 -04:00
|
|
|
import Spinner from 'component/spinner';
|
2020-11-18 17:15:18 -05:00
|
|
|
import SyncFatalError from 'component/syncFatalError';
|
2020-07-10 14:26:05 +08:00
|
|
|
// @if TARGET='app'
|
2020-07-14 03:16:38 +08:00
|
|
|
import useZoom from 'effects/use-zoom';
|
2020-12-18 00:00:52 +08:00
|
|
|
import useHistoryNav from 'effects/use-history-nav';
|
2020-07-10 14:26:05 +08:00
|
|
|
// @endif
|
2019-12-05 00:24:54 -05:00
|
|
|
// @if TARGET='web'
|
2020-05-07 14:44:11 -04:00
|
|
|
import OpenInAppLink from 'web/component/openInAppLink';
|
|
|
|
import YoutubeWelcome from 'web/component/youtubeReferralWelcome';
|
|
|
|
import NagDegradedPerformance from 'web/component/nag-degraded-performance';
|
|
|
|
import NagDataCollection from 'web/component/nag-data-collection';
|
2020-03-17 11:21:26 -04:00
|
|
|
import {
|
|
|
|
useDegradedPerformance,
|
|
|
|
STATUS_OK,
|
|
|
|
STATUS_DEGRADED,
|
2020-03-26 16:17:41 -04:00
|
|
|
STATUS_FAILING,
|
2020-03-17 11:21:26 -04:00
|
|
|
STATUS_DOWN,
|
2020-05-07 14:44:11 -04:00
|
|
|
} from 'web/effects/use-degraded-performance';
|
2020-04-25 16:20:00 -04:00
|
|
|
// @endif
|
2021-01-13 11:07:08 -05:00
|
|
|
import LANGUAGE_MIGRATIONS from 'constants/language-migrations';
|
2019-06-27 02:18:45 -04:00
|
|
|
export const MAIN_WRAPPER_CLASS = 'main-wrapper';
|
2020-11-23 13:47:36 -05:00
|
|
|
export const IS_MAC = navigator.userAgent.indexOf('Mac OS X') !== -1;
|
2019-06-27 02:18:45 -04:00
|
|
|
|
2020-02-27 22:43:39 -06:00
|
|
|
// button numbers pulled from https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
|
|
|
|
const MOUSE_BACK_BTN = 3;
|
|
|
|
const MOUSE_FORWARD_BTN = 4;
|
|
|
|
|
2018-03-26 14:32:43 -07:00
|
|
|
type Props = {
|
2019-06-07 17:10:47 -04:00
|
|
|
language: string,
|
2019-11-08 15:51:42 -05:00
|
|
|
languages: Array<string>,
|
2018-10-19 11:27:14 -04:00
|
|
|
theme: string,
|
2019-08-14 12:28:13 -04:00
|
|
|
user: ?{ id: string, has_verified_email: boolean, is_reward_approved: boolean },
|
2020-01-14 15:44:07 -05:00
|
|
|
location: { pathname: string, hash: string, search: string },
|
2020-02-27 22:43:39 -06:00
|
|
|
history: {
|
|
|
|
goBack: () => void,
|
|
|
|
goForward: () => void,
|
|
|
|
index: number,
|
|
|
|
length: number,
|
|
|
|
push: string => void,
|
|
|
|
},
|
2019-08-06 12:53:59 -04:00
|
|
|
fetchAccessToken: () => void,
|
2019-09-26 12:28:08 -04:00
|
|
|
fetchChannelListMine: () => void,
|
2019-10-01 00:53:33 -04:00
|
|
|
signIn: () => void,
|
2019-09-22 21:56:43 -04:00
|
|
|
requestDownloadUpgrade: () => void,
|
2019-09-26 12:07:11 -04:00
|
|
|
onSignedIn: () => void,
|
2019-11-08 15:51:42 -05:00
|
|
|
setLanguage: string => void,
|
2019-09-26 12:28:08 -04:00
|
|
|
isUpgradeAvailable: boolean,
|
|
|
|
autoUpdateDownloaded: boolean,
|
2020-09-04 11:02:30 -04:00
|
|
|
updatePreferences: () => Promise<any>,
|
2020-09-11 14:35:50 -04:00
|
|
|
getWalletSyncPref: () => Promise<any>,
|
2019-10-10 20:37:18 -04:00
|
|
|
uploadCount: number,
|
2019-10-17 11:27:41 -04:00
|
|
|
balance: ?number,
|
2019-10-22 13:57:32 -04:00
|
|
|
syncError: ?string,
|
2020-09-04 11:02:30 -04:00
|
|
|
syncEnabled: boolean,
|
2020-01-14 15:44:07 -05:00
|
|
|
rewards: Array<Reward>,
|
|
|
|
setReferrer: (string, boolean) => void,
|
2020-03-11 21:43:52 -04:00
|
|
|
isAuthenticated: boolean,
|
2020-07-23 10:22:57 -04:00
|
|
|
socketConnect: () => void,
|
2021-01-21 14:50:51 -05:00
|
|
|
syncLoop: (?boolean) => void,
|
2020-09-04 11:02:30 -04:00
|
|
|
syncEnabled: boolean,
|
2020-09-18 13:26:00 -04:00
|
|
|
currentModal: any,
|
2020-11-12 12:38:28 -05:00
|
|
|
syncFatalError: boolean,
|
2021-02-11 00:12:41 -05:00
|
|
|
activeChannelClaim: ?ChannelClaim,
|
2021-02-09 11:05:56 -05:00
|
|
|
myChannelUrls: ?Array<string>,
|
2021-02-11 00:12:41 -05:00
|
|
|
setActiveChannelIfNotSet: () => void,
|
2021-02-09 11:05:56 -05:00
|
|
|
setIncognito: boolean => void,
|
2018-03-26 14:32:43 -07:00
|
|
|
};
|
2017-04-07 12:15:22 +07:00
|
|
|
|
2019-06-11 14:10:58 -04:00
|
|
|
function App(props: Props) {
|
2019-09-22 21:56:43 -04:00
|
|
|
const {
|
|
|
|
theme,
|
|
|
|
user,
|
|
|
|
fetchAccessToken,
|
2019-09-26 12:07:11 -04:00
|
|
|
fetchChannelListMine,
|
2019-10-01 00:53:33 -04:00
|
|
|
signIn,
|
2019-09-26 12:28:08 -04:00
|
|
|
autoUpdateDownloaded,
|
|
|
|
isUpgradeAvailable,
|
|
|
|
requestDownloadUpgrade,
|
2019-10-10 20:37:18 -04:00
|
|
|
uploadCount,
|
2019-10-22 13:57:32 -04:00
|
|
|
history,
|
|
|
|
syncError,
|
2019-11-08 15:51:42 -05:00
|
|
|
language,
|
|
|
|
languages,
|
|
|
|
setLanguage,
|
2019-12-11 15:09:27 -05:00
|
|
|
updatePreferences,
|
2020-09-11 14:35:50 -04:00
|
|
|
getWalletSyncPref,
|
2020-01-14 15:44:07 -05:00
|
|
|
rewards,
|
|
|
|
setReferrer,
|
2020-03-11 21:43:52 -04:00
|
|
|
isAuthenticated,
|
2021-01-21 14:50:51 -05:00
|
|
|
syncLoop,
|
2020-09-18 13:26:00 -04:00
|
|
|
currentModal,
|
2020-11-12 12:38:28 -05:00
|
|
|
syncFatalError,
|
2021-02-09 11:05:56 -05:00
|
|
|
myChannelUrls,
|
2021-02-11 00:12:41 -05:00
|
|
|
activeChannelClaim,
|
2021-02-09 11:05:56 -05:00
|
|
|
setActiveChannelIfNotSet,
|
|
|
|
setIncognito,
|
2019-09-22 21:56:43 -04:00
|
|
|
} = props;
|
2019-10-16 13:18:12 -04:00
|
|
|
|
2019-06-11 14:10:58 -04:00
|
|
|
const appRef = useRef();
|
|
|
|
const isEnhancedLayout = useKonamiListener();
|
2019-10-15 00:20:12 -04:00
|
|
|
const [hasSignedIn, setHasSignedIn] = useState(false);
|
2020-09-04 11:02:30 -04:00
|
|
|
const [readyForSync, setReadyForSync] = useState(false);
|
|
|
|
const [readyForPrefs, setReadyForPrefs] = useState(false);
|
2020-09-11 14:35:50 -04:00
|
|
|
const hasVerifiedEmail = user && Boolean(user.has_verified_email);
|
2019-08-14 12:28:13 -04:00
|
|
|
const isRewardApproved = user && user.is_reward_approved;
|
|
|
|
const previousHasVerifiedEmail = usePrevious(hasVerifiedEmail);
|
|
|
|
const previousRewardApproved = usePrevious(isRewardApproved);
|
2020-02-21 15:44:58 -05:00
|
|
|
// @if TARGET='web'
|
|
|
|
const [showAnalyticsNag, setShowAnalyticsNag] = usePersistedState('analytics-nag', true);
|
2020-03-17 11:21:26 -04:00
|
|
|
const [lbryTvApiStatus, setLbryTvApiStatus] = useState(STATUS_OK);
|
2020-04-25 16:20:00 -04:00
|
|
|
// @endif
|
2020-01-14 15:44:07 -05:00
|
|
|
const { pathname, hash, search } = props.location;
|
2020-06-20 21:40:27 +08:00
|
|
|
const [upgradeNagClosed, setUpgradeNagClosed] = useState(false);
|
|
|
|
const showUpgradeButton =
|
|
|
|
(autoUpdateDownloaded || (process.platform === 'linux' && isUpgradeAvailable)) && !upgradeNagClosed;
|
2020-01-14 15:44:07 -05:00
|
|
|
// referral claiming
|
|
|
|
const referredRewardAvailable = rewards && rewards.some(reward => reward.reward_type === REWARDS.TYPE_REFEREE);
|
|
|
|
const urlParams = new URLSearchParams(search);
|
|
|
|
const rawReferrerParam = urlParams.get('r');
|
|
|
|
const sanitizedReferrerParam = rawReferrerParam && rawReferrerParam.replace(':', '#');
|
2020-03-17 11:21:26 -04:00
|
|
|
const shouldHideNag = pathname.startsWith(`/$/${PAGES.EMBED}`) || pathname.startsWith(`/$/${PAGES.AUTH_VERIFY}`);
|
2020-10-20 18:20:11 -04:00
|
|
|
const userId = user && user.id;
|
2020-11-23 13:47:36 -05:00
|
|
|
const useCustomScrollbar = !IS_MAC;
|
2021-02-09 11:05:56 -05:00
|
|
|
const hasMyChannels = myChannelUrls && myChannelUrls.length > 0;
|
|
|
|
const hasNoChannels = myChannelUrls && myChannelUrls.length === 0;
|
2021-01-06 13:13:56 -05:00
|
|
|
const shouldMigrateLanguage = LANGUAGE_MIGRATIONS[language];
|
2021-02-11 00:12:41 -05:00
|
|
|
const hasActiveChannelClaim = activeChannelClaim !== undefined;
|
2021-01-06 13:13:56 -05:00
|
|
|
|
2019-08-13 01:35:13 -04:00
|
|
|
let uri;
|
|
|
|
try {
|
2019-08-30 14:12:52 -04:00
|
|
|
const newpath = buildURI(parseURI(pathname.slice(1).replace(/:/g, '#')));
|
|
|
|
uri = newpath + hash;
|
2019-08-13 01:35:13 -04:00
|
|
|
} catch (e) {}
|
|
|
|
|
2020-02-21 15:44:58 -05:00
|
|
|
// @if TARGET='web'
|
|
|
|
function handleAnalyticsDismiss() {
|
|
|
|
setShowAnalyticsNag(false);
|
|
|
|
}
|
2021-01-21 14:50:51 -05:00
|
|
|
|
2020-02-21 15:44:58 -05:00
|
|
|
// @endif
|
2020-10-20 18:20:11 -04:00
|
|
|
useEffect(() => {
|
|
|
|
if (userId) {
|
|
|
|
analytics.setUser(userId);
|
|
|
|
}
|
|
|
|
}, [userId]);
|
2020-02-21 15:44:58 -05:00
|
|
|
|
2019-10-10 20:37:18 -04:00
|
|
|
useEffect(() => {
|
|
|
|
if (!uploadCount) return;
|
|
|
|
const handleBeforeUnload = event => {
|
|
|
|
event.preventDefault();
|
2019-12-03 13:47:03 -05:00
|
|
|
event.returnValue = 'magic'; // without setting this to something it doesn't work
|
2019-10-10 20:37:18 -04:00
|
|
|
};
|
|
|
|
window.addEventListener('beforeunload', handleBeforeUnload);
|
|
|
|
return () => window.removeEventListener('beforeunload', handleBeforeUnload);
|
|
|
|
}, [uploadCount]);
|
|
|
|
|
2020-02-27 22:43:39 -06:00
|
|
|
// allows user to navigate history using the forward and backward buttons on a mouse
|
|
|
|
useEffect(() => {
|
|
|
|
const handleForwardAndBackButtons = e => {
|
|
|
|
switch (e.button) {
|
|
|
|
case MOUSE_BACK_BTN:
|
|
|
|
history.index > 0 && history.goBack();
|
|
|
|
break;
|
|
|
|
case MOUSE_FORWARD_BTN:
|
|
|
|
history.index < history.length - 1 && history.goForward();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
window.addEventListener('mouseup', handleForwardAndBackButtons);
|
|
|
|
return () => window.removeEventListener('mouseup', handleForwardAndBackButtons);
|
|
|
|
});
|
|
|
|
|
2020-05-17 18:30:20 +07:00
|
|
|
// allows user to pause miniplayer using the spacebar without the page scrolling down
|
|
|
|
useEffect(() => {
|
|
|
|
const handleKeyPress = e => {
|
|
|
|
if (e.key === ' ' && e.target === document.body) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
window.addEventListener('keydown', handleKeyPress);
|
|
|
|
return () => window.removeEventListener('keydown', handleKeyPress);
|
2020-05-19 19:49:15 +07:00
|
|
|
}, []);
|
2020-05-17 18:30:20 +07:00
|
|
|
|
2020-07-10 14:26:05 +08:00
|
|
|
// Enable ctrl +/- zooming on Desktop.
|
|
|
|
// @if TARGET='app'
|
2020-07-14 03:16:38 +08:00
|
|
|
useZoom();
|
2020-07-10 14:26:05 +08:00
|
|
|
// @endif
|
|
|
|
|
2020-12-18 00:00:52 +08:00
|
|
|
// Enable 'Alt + Left/Right' for history navigation on Desktop.
|
|
|
|
// @if TARGET='app'
|
|
|
|
useHistoryNav(history);
|
|
|
|
// @endif
|
|
|
|
|
2020-01-14 15:44:07 -05:00
|
|
|
useEffect(() => {
|
|
|
|
if (referredRewardAvailable && sanitizedReferrerParam && isRewardApproved) {
|
|
|
|
setReferrer(sanitizedReferrerParam, true);
|
|
|
|
} else if (referredRewardAvailable && sanitizedReferrerParam) {
|
|
|
|
setReferrer(sanitizedReferrerParam, false);
|
|
|
|
}
|
2020-03-09 19:46:37 -04:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2020-01-14 15:44:07 -05:00
|
|
|
}, [sanitizedReferrerParam, isRewardApproved, referredRewardAvailable]);
|
|
|
|
|
2019-06-11 14:10:58 -04:00
|
|
|
useEffect(() => {
|
2020-03-27 12:49:41 -04:00
|
|
|
const { current: wrapperElement } = appRef;
|
2020-02-06 13:49:05 -05:00
|
|
|
if (wrapperElement) {
|
|
|
|
ReactModal.setAppElement(wrapperElement);
|
|
|
|
}
|
2020-07-23 10:22:57 -04:00
|
|
|
|
2019-08-06 12:53:59 -04:00
|
|
|
fetchAccessToken();
|
2019-06-27 02:18:45 -04:00
|
|
|
|
|
|
|
// @if TARGET='app'
|
2020-07-23 10:22:57 -04:00
|
|
|
fetchChannelListMine(); // This is fetched after a user is signed in on web
|
2019-06-27 02:18:45 -04:00
|
|
|
// @endif
|
2020-04-10 13:31:36 -04:00
|
|
|
}, [appRef, fetchAccessToken, fetchChannelListMine]);
|
2018-10-18 11:45:24 -05:00
|
|
|
|
2019-06-11 14:10:58 -04:00
|
|
|
useEffect(() => {
|
2018-10-18 11:45:24 -05:00
|
|
|
// $FlowFixMe
|
2019-11-22 16:13:00 -05:00
|
|
|
document.documentElement.setAttribute('theme', theme);
|
2019-06-11 14:10:58 -04:00
|
|
|
}, [theme]);
|
2018-11-07 11:03:42 -05:00
|
|
|
|
2019-11-08 15:51:42 -05:00
|
|
|
useEffect(() => {
|
2021-02-11 00:12:41 -05:00
|
|
|
if (hasMyChannels && !hasActiveChannelClaim) {
|
2021-02-09 11:05:56 -05:00
|
|
|
setActiveChannelIfNotSet();
|
|
|
|
} else if (hasNoChannels) {
|
|
|
|
setIncognito(true);
|
|
|
|
}
|
2021-02-11 00:12:41 -05:00
|
|
|
}, [hasMyChannels, hasNoChannels, hasActiveChannelClaim, setActiveChannelIfNotSet, setIncognito]);
|
2021-02-09 11:05:56 -05:00
|
|
|
|
|
|
|
useEffect(() => {
|
2019-11-08 15:51:42 -05:00
|
|
|
if (!languages.includes(language)) {
|
|
|
|
setLanguage(language);
|
|
|
|
}
|
2020-03-09 19:46:37 -04:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2019-11-08 15:51:42 -05:00
|
|
|
}, [language, languages]);
|
|
|
|
|
2021-01-06 13:13:56 -05:00
|
|
|
useEffect(() => {
|
|
|
|
if (shouldMigrateLanguage) {
|
|
|
|
setLanguage(shouldMigrateLanguage);
|
|
|
|
}
|
2021-01-08 11:28:52 -05:00
|
|
|
}, [shouldMigrateLanguage, setLanguage]);
|
2021-01-06 13:13:56 -05:00
|
|
|
|
2019-08-14 12:28:13 -04:00
|
|
|
useEffect(() => {
|
2019-08-14 23:09:34 -04:00
|
|
|
// Check that previousHasVerifiedEmail was not undefined instead of just not truthy
|
|
|
|
// This ensures we don't fire the emailVerified event on the initial user fetch
|
2019-09-26 12:07:11 -04:00
|
|
|
if (previousHasVerifiedEmail === false && hasVerifiedEmail) {
|
2019-08-14 12:28:13 -04:00
|
|
|
analytics.emailVerifiedEvent();
|
|
|
|
}
|
2019-10-01 00:53:33 -04:00
|
|
|
}, [previousHasVerifiedEmail, hasVerifiedEmail, signIn]);
|
2019-08-14 12:28:13 -04:00
|
|
|
|
|
|
|
useEffect(() => {
|
2019-09-26 12:07:11 -04:00
|
|
|
if (previousRewardApproved === false && isRewardApproved) {
|
2019-08-14 12:28:13 -04:00
|
|
|
analytics.rewardEligibleEvent();
|
|
|
|
}
|
|
|
|
}, [previousRewardApproved, isRewardApproved]);
|
2019-07-21 22:28:49 -04:00
|
|
|
|
2020-09-04 11:02:30 -04:00
|
|
|
// @if TARGET='app'
|
2019-08-06 12:00:31 -04:00
|
|
|
useEffect(() => {
|
2020-09-11 14:35:50 -04:00
|
|
|
if (updatePreferences && getWalletSyncPref && readyForPrefs) {
|
|
|
|
getWalletSyncPref()
|
|
|
|
.then(() => updatePreferences())
|
|
|
|
.then(() => {
|
|
|
|
setReadyForSync(true);
|
|
|
|
});
|
2019-08-06 12:00:31 -04:00
|
|
|
}
|
2020-09-11 14:35:50 -04:00
|
|
|
}, [updatePreferences, getWalletSyncPref, setReadyForSync, readyForPrefs, hasVerifiedEmail]);
|
2020-09-04 11:02:30 -04:00
|
|
|
// @endif
|
2019-10-15 17:23:51 -04:00
|
|
|
|
2020-09-04 11:02:30 -04:00
|
|
|
// ready for sync syncs, however after signin when hasVerifiedEmail, that syncs too.
|
2019-12-21 13:43:42 -05:00
|
|
|
useEffect(() => {
|
2020-09-09 13:37:55 -04:00
|
|
|
// signInSyncPref is cleared after sharedState loop.
|
2021-01-21 14:50:51 -05:00
|
|
|
const syncLoopWithoutInterval = () => syncLoop(true);
|
2020-09-11 14:35:50 -04:00
|
|
|
if (readyForSync && hasVerifiedEmail) {
|
|
|
|
// In case we are syncing.
|
2021-01-21 14:50:51 -05:00
|
|
|
syncLoop();
|
|
|
|
// @if TARGET='web'
|
|
|
|
window.addEventListener('focus', syncLoopWithoutInterval);
|
|
|
|
// @endif
|
2020-09-04 11:02:30 -04:00
|
|
|
}
|
2021-01-21 14:50:51 -05:00
|
|
|
// @if TARGET='web'
|
|
|
|
return () => {
|
|
|
|
window.removeEventListener('focus', syncLoopWithoutInterval);
|
|
|
|
};
|
|
|
|
// @endif
|
|
|
|
}, [readyForSync, hasVerifiedEmail, syncLoop]);
|
2019-12-21 13:43:42 -05:00
|
|
|
|
2020-09-11 14:35:50 -04:00
|
|
|
// We know someone is logging in or not when we get their user object
|
2020-09-04 11:02:30 -04:00
|
|
|
// We'll use this to determine when it's time to pull preferences
|
|
|
|
// This will no longer work if desktop users no longer get a user object from lbryinc
|
2019-10-15 17:23:51 -04:00
|
|
|
useEffect(() => {
|
2020-09-04 11:02:30 -04:00
|
|
|
if (user) {
|
|
|
|
setReadyForPrefs(true);
|
2019-10-15 17:23:51 -04:00
|
|
|
}
|
2020-09-04 11:02:30 -04:00
|
|
|
}, [user, setReadyForPrefs]);
|
2019-12-11 15:09:27 -05:00
|
|
|
|
2019-10-22 13:57:32 -04:00
|
|
|
useEffect(() => {
|
2020-09-18 13:26:00 -04:00
|
|
|
if (syncError && isAuthenticated && !pathname.includes(PAGES.AUTH_WALLET_PASSWORD) && !currentModal) {
|
2020-09-18 11:16:49 -04:00
|
|
|
history.push(`/$/${PAGES.AUTH_WALLET_PASSWORD}?redirect=${pathname}`);
|
2019-10-22 16:43:51 -04:00
|
|
|
}
|
2020-03-09 19:46:37 -04:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2020-03-11 21:43:52 -04:00
|
|
|
}, [syncError, pathname, isAuthenticated]);
|
2019-10-22 13:57:32 -04:00
|
|
|
|
2020-09-04 11:02:30 -04:00
|
|
|
// Keep this at the end to ensure initial setup effects are run first
|
|
|
|
useEffect(() => {
|
|
|
|
if (!hasSignedIn && hasVerifiedEmail) {
|
|
|
|
signIn();
|
|
|
|
setHasSignedIn(true);
|
|
|
|
if (IS_WEB) setReadyForSync(true);
|
|
|
|
}
|
|
|
|
}, [hasVerifiedEmail, signIn, hasSignedIn]);
|
|
|
|
|
2020-03-12 13:47:40 -04:00
|
|
|
// @if TARGET='web'
|
2020-12-10 17:31:20 -05:00
|
|
|
useDegradedPerformance(setLbryTvApiStatus, user);
|
2020-03-12 13:47:40 -04:00
|
|
|
// @endif
|
|
|
|
|
2019-11-14 10:25:01 -05:00
|
|
|
// @if TARGET='web'
|
|
|
|
// Require an internal-api user on lbry.tv
|
|
|
|
// This also prevents the site from loading in the un-authed state while we wait for internal-apis to return for the first time
|
|
|
|
// It's not needed on desktop since there is no un-authed state
|
2020-01-14 15:01:37 -05:00
|
|
|
if (!user) {
|
2020-10-28 12:02:06 -04:00
|
|
|
return (
|
|
|
|
<div className="main--empty">
|
|
|
|
<Spinner delayed />
|
|
|
|
</div>
|
|
|
|
);
|
2019-12-05 11:30:48 -05:00
|
|
|
}
|
2019-11-14 10:25:01 -05:00
|
|
|
// @endif
|
2019-08-06 12:00:31 -04:00
|
|
|
|
2020-11-12 12:38:28 -05:00
|
|
|
if (syncFatalError) {
|
|
|
|
return <SyncFatalError />;
|
|
|
|
}
|
|
|
|
|
2019-06-11 14:10:58 -04:00
|
|
|
return (
|
2019-10-09 12:34:18 -04:00
|
|
|
<div
|
2019-10-15 12:21:49 -04:00
|
|
|
className={classnames(MAIN_WRAPPER_CLASS, {
|
|
|
|
// @if TARGET='app'
|
|
|
|
[`${MAIN_WRAPPER_CLASS}--mac`]: IS_MAC,
|
|
|
|
// @endif
|
2020-11-19 22:00:31 +08:00
|
|
|
[`${MAIN_WRAPPER_CLASS}--scrollbar`]: useCustomScrollbar,
|
2019-10-15 12:21:49 -04:00
|
|
|
})}
|
2019-10-09 12:34:18 -04:00
|
|
|
ref={appRef}
|
2019-11-01 16:44:26 -04:00
|
|
|
onContextMenu={IS_WEB ? undefined : e => openContextMenu(e)}
|
2019-10-09 12:34:18 -04:00
|
|
|
>
|
2020-03-17 11:21:26 -04:00
|
|
|
{IS_WEB && lbryTvApiStatus === STATUS_DOWN ? (
|
|
|
|
<Yrbl
|
|
|
|
className="main--empty"
|
|
|
|
title={__('lbry.tv is currently down')}
|
2020-03-17 16:13:35 -04:00
|
|
|
subtitle={__('My wheel broke, but the good news is that someone from LBRY is working on it.')}
|
2020-03-12 13:47:40 -04:00
|
|
|
/>
|
2020-03-17 11:21:26 -04:00
|
|
|
) : (
|
2020-02-21 16:05:20 -05:00
|
|
|
<React.Fragment>
|
2020-03-17 11:21:26 -04:00
|
|
|
<Router />
|
|
|
|
<ModalRouter />
|
2020-05-25 09:27:36 -05:00
|
|
|
<FileDrop />
|
2020-04-13 19:48:11 -04:00
|
|
|
<FileRenderFloating />
|
2020-03-17 11:21:26 -04:00
|
|
|
{isEnhancedLayout && <Yrbl className="yrbl--enhanced" />}
|
|
|
|
|
|
|
|
{/* @if TARGET='app' */}
|
|
|
|
{showUpgradeButton && (
|
2020-02-21 16:05:20 -05:00
|
|
|
<Nag
|
2020-03-17 11:21:26 -04:00
|
|
|
message={__('An upgrade is available.')}
|
|
|
|
actionText={__('Install Now')}
|
|
|
|
onClick={requestDownloadUpgrade}
|
2020-06-20 21:40:27 +08:00
|
|
|
onClose={() => setUpgradeNagClosed(true)}
|
2020-02-21 16:05:20 -05:00
|
|
|
/>
|
|
|
|
)}
|
2020-03-17 11:21:26 -04:00
|
|
|
{/* @endif */}
|
|
|
|
|
|
|
|
{/* @if TARGET='web' */}
|
|
|
|
<YoutubeWelcome />
|
2020-03-27 09:57:11 -04:00
|
|
|
{!shouldHideNag && <OpenInAppLink uri={uri} />}
|
2020-08-27 13:56:18 -04:00
|
|
|
{!shouldHideNag && <NagContinueFirstRun />}
|
2020-03-27 09:57:11 -04:00
|
|
|
{(lbryTvApiStatus === STATUS_DEGRADED || lbryTvApiStatus === STATUS_FAILING) && !shouldHideNag && (
|
2020-03-17 11:21:26 -04:00
|
|
|
<NagDegradedPerformance onClose={() => setLbryTvApiStatus(STATUS_OK)} />
|
|
|
|
)}
|
|
|
|
{lbryTvApiStatus === STATUS_OK && showAnalyticsNag && !shouldHideNag && (
|
|
|
|
<NagDataCollection onClose={handleAnalyticsDismiss} />
|
|
|
|
)}
|
|
|
|
{/* @endif */}
|
2020-02-21 16:05:20 -05:00
|
|
|
</React.Fragment>
|
2020-02-21 15:44:58 -05:00
|
|
|
)}
|
2019-06-11 14:10:58 -04:00
|
|
|
</div>
|
|
|
|
);
|
2017-05-03 23:44:08 -04:00
|
|
|
}
|
2017-04-07 12:15:22 +07:00
|
|
|
|
2019-08-13 01:35:13 -04:00
|
|
|
export default withRouter(App);
|