Advertisement
Guest User

FLow/React Bugs

a guest
Sep 18th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. 'use strict';
  2. // @flow
  3.  
  4. import {HashRouter, Route, Switch} from 'react-router-dom';
  5. import React from 'react';
  6. import {connect} from 'react-redux';
  7. import axios from 'axios';
  8. import Loader from './loader/Loader';
  9. import Sidebar from './sidebar/Sidebar';
  10. import Header from './header/Header';
  11. import * as appActions from '../actions/appActions';
  12.  
  13.  
  14.  
  15. type Props = {
  16. dispatch: Function,
  17. loadingTxt: string,
  18. errorTxt: string,
  19. loading: bool,
  20. error: bool
  21. };
  22.  
  23.  
  24. /**
  25. * App Component.
  26. */
  27. class App extends React.Component<Props> {
  28. constructor(props: Props) {
  29. super(props: Props);
  30.  
  31. this.data = {};
  32. }
  33.  
  34. componentDidMount() {
  35. axios.get(window.location.protocol + '//' + window.location.host + '/data/app.json')
  36. .then((response: object) => {
  37. this.data = response.data
  38. setTimeout(() => this.props.dispatch(appActions.appHasLoaded(): Function), 2000);
  39.  
  40. }).catch(() => {
  41. this.props.dispatch(appActions.appHasErrored(): Function);
  42. });
  43. }
  44.  
  45. render(): React.Element {
  46. if (this.props.error || this.props.loading) {
  47. return (
  48. <div className={this.props.error ? 'app-loader is--error' : 'app-loader'}>
  49. <Loader size="app" />
  50. <p className="app-loader__text">{this.props.error ? this.props.errorTxt : this.props.loadingTxt}</p>
  51. </div>
  52. )
  53.  
  54. } else {
  55. return (
  56. <div className="app-inner">
  57. <HashRouter>
  58. <Route>
  59. <Header {...this.data.header} />
  60. </Route>
  61. </HashRouter>
  62.  
  63. <div className="page">
  64. <HashRouter>
  65. <Switch>
  66. <Route path='/'>
  67. <Sidebar {...this.data.sidebar} />
  68. </Route>
  69. <Route>
  70. <p>Not Found</p>
  71. </Route>
  72. </Switch>
  73. </HashRouter>
  74. </div>
  75. </div>
  76. )
  77. }
  78. }
  79. };
  80.  
  81. const mapStateToProps = (state: object) => {
  82. return {
  83. loading: state.app.loading,
  84. error: state.app.error
  85. }
  86. }
  87.  
  88. export default connect(mapStateToProps)(App);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement