lbry-desktop/src/ui/component/app/view.jsx

71 lines
1.7 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
2019-06-11 20:10:58 +02:00
import React, { useEffect, useRef } from 'react';
2019-07-22 04:28:49 +02:00
import analytics from 'analytics';
import Router from 'component/router/index';
import ModalRouter from 'modal/modalRouter';
import ReactModal from 'react-modal';
2018-03-26 23:32:43 +02:00
import SideBar from 'component/sideBar';
import Header from 'component/header';
2019-01-23 16:38:40 +01:00
import { openContextMenu } from 'util/context-menu';
2019-06-11 20:10:58 +02:00
import useKonamiListener from 'util/enhanced-layout';
2019-03-05 05:46:57 +01:00
import Yrbl from 'component/yrbl';
2018-03-26 23:32:43 +02:00
2019-06-27 08:18:45 +02:00
export const MAIN_WRAPPER_CLASS = 'main-wrapper';
2018-03-26 23:32:43 +02:00
type Props = {
alertError: (string | {}) => void,
pageTitle: ?string,
2019-06-07 23:10:47 +02:00
language: string,
2018-10-19 17:27:14 +02:00
theme: string,
2019-07-22 04:28:49 +02:00
user: ?{ id: string },
2019-06-11 20:10:58 +02:00
fetchRewards: () => void,
fetchRewardedContent: () => void,
2019-06-27 08:18:45 +02:00
fetchTransactions: () => void,
2018-03-26 23:32:43 +02:00
};
2017-04-07 07:15:22 +02:00
2019-06-11 20:10:58 +02:00
function App(props: Props) {
2019-07-22 04:28:49 +02:00
const { theme, fetchRewards, fetchRewardedContent, fetchTransactions, user } = props;
2019-06-11 20:10:58 +02:00
const appRef = useRef();
const isEnhancedLayout = useKonamiListener();
2019-07-22 04:28:49 +02:00
const userId = user && user.id;
2017-07-16 18:29:46 +02:00
2019-06-11 20:10:58 +02:00
useEffect(() => {
ReactModal.setAppElement(appRef.current);
fetchRewardedContent();
2019-06-27 08:18:45 +02:00
// @if TARGET='app'
fetchRewards();
fetchTransactions();
// @endif
}, [fetchRewards, fetchRewardedContent, fetchTransactions]);
2018-10-18 18:45:24 +02:00
2019-06-11 20:10:58 +02:00
useEffect(() => {
2018-10-18 18:45:24 +02:00
// $FlowFixMe
2019-02-13 17:27:20 +01:00
document.documentElement.setAttribute('data-mode', theme);
2019-06-11 20:10:58 +02:00
}, [theme]);
2018-11-07 17:03:42 +01:00
2019-07-22 04:28:49 +02:00
useEffect(() => {
if (userId) {
analytics.setUser(userId);
}
}, [userId]);
2019-06-11 20:10:58 +02:00
return (
<div ref={appRef} onContextMenu={e => openContextMenu(e)}>
<Header />
2018-03-26 23:32:43 +02:00
2019-06-27 08:18:45 +02:00
<div className={MAIN_WRAPPER_CLASS}>
2019-06-11 20:10:58 +02:00
<div className="main-wrapper-inner">
<Router />
2019-06-11 20:10:58 +02:00
<SideBar />
</div>
2017-04-21 04:31:50 +02:00
</div>
2019-06-11 20:10:58 +02:00
<ModalRouter />
{isEnhancedLayout && <Yrbl className="yrbl--enhanced" />}
</div>
);
2017-05-04 05:44:08 +02:00
}
2017-04-07 07:15:22 +02:00
2017-06-06 06:21:55 +02:00
export default App;