--- for fun

This commit is contained in:
infinite-persistence 2021-05-23 14:32:59 +08:00
parent 339fbb491f
commit 9299bdb781
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
2 changed files with 62 additions and 1 deletions

View file

@ -17,6 +17,7 @@ import usePrevious from 'effects/use-previous';
import Nag from 'component/common/nag';
import REWARDS from 'rewards';
import usePersistedState from 'effects/use-persisted-state';
import LoadingBar from 'react-top-loading-bar';
import FileDrop from 'component/fileDrop';
import NagContinueFirstRun from 'component/nagContinueFirstRun';
import Spinner from 'component/spinner';
@ -120,6 +121,7 @@ function App(props: Props) {
} = props;
const appRef = useRef();
const loadingBarRef = useRef();
const isEnhancedLayout = useKonamiListener();
const [hasSignedIn, setHasSignedIn] = useState(false);
const [readyForSync, setReadyForSync] = useState(false);
@ -381,7 +383,8 @@ function App(props: Props) {
/>
) : (
<React.Fragment>
<Router />
<Router loadingBar={loadingBarRef} />
{<LoadingBar ref={loadingBarRef} loaderSpeed={10} transitionTime={10} />}
<ModalRouter />
<FileDrop />
<FileRenderFloating />

View file

@ -89,6 +89,7 @@ type Props = {
setReferrer: (string) => void,
hasUnclaimedRefereeReward: boolean,
homepageData: any,
loadingBar?: any,
};
type PrivateRouteProps = Props & {
@ -128,6 +129,8 @@ function AppRouter(props: Props) {
hasUnclaimedRefereeReward,
setReferrer,
homepageData,
loadingBar,
location,
} = props;
const { entries, listen, action: historyAction } = history;
const entryIndex = history.index;
@ -139,6 +142,20 @@ function AppRouter(props: Props) {
(potentialRoute: any) => potentialRoute && potentialRoute.route
);
console.log('router:', props);
const isPathResolved = history.location.pathname === location.pathname;
useEffect(() => {
return () => {
if (history.action === 'POP' || history.action === 'PUSH') {
if (loadingBar && loadingBar.current) {
console.log('start');
loadingBar.current.staticStart();
}
}
};
}, [history.action, history.location]);
// For people arriving at settings page from deeplinks, know whether they can "go back"
useEffect(() => {
const unlisten = listen((location, action) => {
@ -198,6 +215,47 @@ function AppRouter(props: Props) {
}
}, [currentScroll, pathname, search, hash, resetScroll, hasLinkedCommentInUrl, historyAction]);
// useEffect(() => {
// if (loadingBar && loadingBar.current) {
// console.log('hasNavigated:', hasNavigated);
// if (hasNavigated) {
// loadingBar.current.continuousStart();
// } else {loadingBar.current.complete();
// }
// }
// }, [hasNavigated]);
// useEffect(() => {
// console.log('isPathResolved:', isPathResolved);
// if (loadingBar && loadingBar.current) {
// if (isPathResolved) {
// console.log(' stop');
// loadingBar.current.complete();
// } else {
// console.log(' start');
// loadingBar.current.continuousStart();
// }
// }
// }, [isPathResolved]);
// useEffect(() => {
// console.log('isPathResolved:', isPathResolved);
// if (loadingBar && loadingBar.current) {
// if (isPathResolved) {
// console.log(' stop');
// loadingBar.current.complete();
// }
// }
// }, [isPathResolved]);
useEffect(() => {
console.log('router done');
if (isPathResolved && loadingBar && loadingBar.current) {
console.log('stop');
loadingBar.current.complete();
}
});
// 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