|
@@ -6,18 +6,61 @@ import { connect } from 'react-redux'
|
|
|
import { View } from '../meta/Views'
|
|
import { View } from '../meta/Views'
|
|
|
import Landing from './landing/Landing'
|
|
import Landing from './landing/Landing'
|
|
|
import Login from './login/Login'
|
|
import Login from './login/Login'
|
|
|
|
|
+import Loader from './loader/Loader'
|
|
|
import Settings from './settings/Settings'
|
|
import Settings from './settings/Settings'
|
|
|
|
|
|
|
|
import './Application.css'
|
|
import './Application.css'
|
|
|
|
|
+import { StoreType } from '../redux/store'
|
|
|
|
|
+import { CSSTransition } from 'react-transition-group'
|
|
|
|
|
+import { setCurrentView } from '../redux/actions/viewActions'
|
|
|
|
|
+import { throttle } from 'lodash'
|
|
|
|
|
+import { readdir } from 'fs-extra'
|
|
|
|
|
+import { join } from 'path'
|
|
|
|
|
|
|
|
-type ApplicationProps = {
|
|
|
|
|
|
|
+declare const __static: string
|
|
|
|
|
+
|
|
|
|
|
+function setBackground(id: number) {
|
|
|
|
|
+ import(`../../../static/images/backgrounds/${id}.jpg`).then(mdl => {
|
|
|
|
|
+ document.body.style.backgroundImage = `url('${mdl.default}')`
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+interface ApplicationProps {
|
|
|
currentView: View
|
|
currentView: View
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-class Application extends React.Component<ApplicationProps> {
|
|
|
|
|
|
|
+interface ApplicationState {
|
|
|
|
|
+ loading: boolean
|
|
|
|
|
+ showMain: boolean
|
|
|
|
|
+ renderMain: boolean
|
|
|
|
|
+ workingView: View
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const mapState = (state: StoreType) => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ currentView: state.currentView
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+const mapDispatch = {
|
|
|
|
|
+ setView: (x: View) => setCurrentView(x)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+class Application extends React.Component<ApplicationProps & typeof mapDispatch, ApplicationState> {
|
|
|
|
|
+
|
|
|
|
|
+ private bkid!: number
|
|
|
|
|
+
|
|
|
|
|
+ constructor(props: ApplicationProps & typeof mapDispatch) {
|
|
|
|
|
+ super(props)
|
|
|
|
|
+ this.state = {
|
|
|
|
|
+ loading: true,
|
|
|
|
|
+ showMain: false,
|
|
|
|
|
+ renderMain: false,
|
|
|
|
|
+ workingView: props.currentView
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
getViewElement(): JSX.Element {
|
|
getViewElement(): JSX.Element {
|
|
|
- switch(this.props.currentView) {
|
|
|
|
|
|
|
+ switch(this.state.workingView) {
|
|
|
case View.WELCOME:
|
|
case View.WELCOME:
|
|
|
return <>
|
|
return <>
|
|
|
<Welcome />
|
|
<Welcome />
|
|
@@ -38,21 +81,86 @@ class Application extends React.Component<ApplicationProps> {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- render() {
|
|
|
|
|
|
|
+ private updateWorkingView = throttle(() => {
|
|
|
|
|
+ this.setState({
|
|
|
|
|
+ ...this.state,
|
|
|
|
|
+ workingView: this.props.currentView
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ }, 200)
|
|
|
|
|
+
|
|
|
|
|
+ private showMain = (): void => {
|
|
|
|
|
+ setBackground(this.bkid)
|
|
|
|
|
+ this.setState({
|
|
|
|
|
+ ...this.state,
|
|
|
|
|
+ showMain: true
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private initLoad = async (): Promise<void> => {
|
|
|
|
|
+ if(this.state.loading) {
|
|
|
|
|
+ const MIN_LOAD = 800
|
|
|
|
|
+ const start = Date.now()
|
|
|
|
|
+ this.bkid = Math.floor((Math.random() * (await readdir(join(__static, 'images', 'backgrounds'))).length))
|
|
|
|
|
+ const endLoad = () => {
|
|
|
|
|
+ this.setState({
|
|
|
|
|
+ ...this.state,
|
|
|
|
|
+ loading: false
|
|
|
|
|
+ })
|
|
|
|
|
+ // TODO temp
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ this.props.setView(View.WELCOME)
|
|
|
|
|
+ }, 5000)
|
|
|
|
|
+ }
|
|
|
|
|
+ const diff = Date.now() - start
|
|
|
|
|
+ if(diff < MIN_LOAD) {
|
|
|
|
|
+ setTimeout(endLoad, MIN_LOAD-diff)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ endLoad()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ render(): JSX.Element {
|
|
|
return (
|
|
return (
|
|
|
<>
|
|
<>
|
|
|
<Frame />
|
|
<Frame />
|
|
|
- <div className="appWrapper">
|
|
|
|
|
- {this.getViewElement()}
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ <CSSTransition
|
|
|
|
|
+ in={this.state.showMain}
|
|
|
|
|
+ appear={true}
|
|
|
|
|
+ timeout={500}
|
|
|
|
|
+ classNames="appWrapper"
|
|
|
|
|
+ unmountOnExit
|
|
|
|
|
+ >
|
|
|
|
|
+ <div className="appWrapper">
|
|
|
|
|
+ <CSSTransition
|
|
|
|
|
+ in={this.props.currentView == this.state.workingView}
|
|
|
|
|
+ appear={true}
|
|
|
|
|
+ timeout={500}
|
|
|
|
|
+ classNames="appWrapper"
|
|
|
|
|
+ unmountOnExit
|
|
|
|
|
+ onExited={this.updateWorkingView}
|
|
|
|
|
+ >
|
|
|
|
|
+ {this.getViewElement()}
|
|
|
|
|
+ </CSSTransition>
|
|
|
|
|
+
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </CSSTransition>
|
|
|
|
|
+ <CSSTransition
|
|
|
|
|
+ in={this.state.loading}
|
|
|
|
|
+ appear={true}
|
|
|
|
|
+ timeout={300}
|
|
|
|
|
+ classNames="loader"
|
|
|
|
|
+ unmountOnExit
|
|
|
|
|
+ onEnter={this.initLoad}
|
|
|
|
|
+ onExited={this.showMain}
|
|
|
|
|
+ >
|
|
|
|
|
+ <Loader />
|
|
|
|
|
+ </CSSTransition>
|
|
|
</>
|
|
</>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const connected = connect((state: any) => ({
|
|
|
|
|
- currentView: state.currentView
|
|
|
|
|
-}), undefined)(Application)
|
|
|
|
|
-
|
|
|
|
|
-export default hot(connected)
|
|
|
|
|
|
|
+export default hot(connect<unknown, typeof mapDispatch>(mapState, mapDispatch)(Application))
|