1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-12 08:54:00 +02:00
joplin/ElectronClient/app/gui/Root.jsx

80 lines
1.6 KiB
React
Raw Normal View History

const React = require('react');
const { render } = require('react-dom');
const { createStore } = require('redux');
2017-11-04 18:40:34 +02:00
const { connect, Provider } = require('react-redux');
const { MainScreen } = require('./MainScreen.min.js');
const { OneDriveAuthScreen } = require('./OneDriveAuthScreen.min.js');
const { Navigator } = require('./Navigator.min.js');
const { app } = require('../app');
const { bridge } = require('electron').remote.require('./bridge');
async function initialize(dispatch) {
bridge().window().on('resize', function() {
store.dispatch({
type: 'WINDOW_CONTENT_SIZE_SET',
size: bridge().windowContentSize(),
});
});
store.dispatch({
type: 'WINDOW_CONTENT_SIZE_SET',
size: bridge().windowContentSize(),
});
}
class RootComponent extends React.Component {
async componentDidMount() {
if (this.props.appState == 'starting') {
this.props.dispatch({
type: 'SET_APP_STATE',
state: 'initializing',
});
await initialize(this.props.dispatch);
this.props.dispatch({
type: 'SET_APP_STATE',
state: 'ready',
});
}
}
render() {
const navigatorStyle = {
width: this.props.size.width,
height: this.props.size.height,
};
const screens = {
Main: { screen: MainScreen },
OneDriveAuth: { screen: OneDriveAuthScreen },
};
return (
<Navigator style={navigatorStyle} screens={screens} />
);
}
}
2017-11-04 18:40:34 +02:00
const mapStateToProps = (state) => {
return {
size: state.windowContentSize,
appState: state.appState,
};
2017-11-04 18:40:34 +02:00
};
const Root = connect(mapStateToProps)(RootComponent);
2017-11-04 18:40:34 +02:00
const store = app().store();
render(
<Provider store={store}>
<Root />
</Provider>,
document.getElementById('react-root')
)