-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React, {Component} from 'react'; | ||
import './App.css'; | ||
import NavBar from './components/NavBar/NavBar'; | ||
import DialogsContainer from './components/Dialogs/DialogsContainer' | ||
import {Route, withRouter} from 'react-router-dom'; | ||
import UsersContainer from './components/Users/UsersContainer'; | ||
import HeaderContainer from './components/Header/HeaderContainer'; | ||
import Login from './components/Login/Login'; | ||
import {initializeApp} from './redux/app-reducer'; | ||
import {connect} from 'react-redux'; | ||
import Preloader from './components/common/Preloader'; | ||
import {compose} from 'redux'; | ||
import {withSuspense} from './hoc/withSuspense'; | ||
import {AppStateType} from "./redux/redux-store"; | ||
|
||
const ProfileContainer = React.lazy(() => import('./components/Profile/ProfileContainer')); | ||
|
||
type MapPropsType= ReturnType<typeof mapStateToProps> | ||
type DispatchPropsType= { | ||
initializeApp:()=>void | ||
} | ||
|
||
class App extends Component<MapPropsType & DispatchPropsType > { | ||
|
||
componentDidMount() { | ||
this.props.initializeApp() | ||
} | ||
|
||
render() { | ||
if (!this.props.initialized) { | ||
|
||
return <Preloader/> | ||
} | ||
return ( | ||
<div className='app-wrapper'> | ||
<HeaderContainer/> | ||
<NavBar/> | ||
<div className="app-wrapper-content"> | ||
|
||
<Route path='/dialogs' render={() => <DialogsContainer/>}/> | ||
|
||
<Route path='/profile/:userId?' render={withSuspense(ProfileContainer)}/> | ||
|
||
<Route path='/users' render={() => <UsersContainer/>}/> | ||
<Route path='/login' render={() => <Login/>}/> | ||
|
||
|
||
</div> | ||
|
||
</div> | ||
|
||
|
||
) | ||
} | ||
} | ||
|
||
const mapStateToProps=(state: AppStateType)=>({ | ||
initialized:state.app.initialized | ||
}) | ||
|
||
export default compose( | ||
withRouter, | ||
connect(mapStateToProps, {initializeApp}) | ||
)(App) | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import Dialogs from "./Dialogs" | ||
import { connect } from 'react-redux'; | ||
import { withAuthRedirect } from '../../hoc/withAuthRedirect'; | ||
import { compose } from 'redux'; | ||
import {actions} from "../../redux/dialogs-reducer"; | ||
import {AppStateType} from "../../redux/redux-store"; | ||
|
||
|
||
|
||
let mapStateToProps=(state: AppStateType)=>{ | ||
return{ | ||
dialogsPage: state.dialogsPage | ||
} | ||
} | ||
|
||
|
||
|
||
export default compose<React.ComponentType>( | ||
connect(mapStateToProps, {...actions}), | ||
withAuthRedirect | ||
)(Dialogs); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react'; | ||
import {Redirect} from 'react-router-dom'; | ||
import {connect} from 'react-redux'; | ||
import {AppStateType} from "../redux/redux-store"; | ||
|
||
|
||
let mapStateToPropsForRedirect=(state :AppStateType)=>({ | ||
isAuth: state.auth.isAuth | ||
}); | ||
|
||
export function withAuthRedirect<WCP>(WrappedComponent: React.ComponentType<WCP>){ | ||
|
||
function RedirectComponent(props: WCP) { | ||
|
||
if (!props.isAuth) return <Redirect to='/login'/> | ||
return <WrappedComponent {...props}/> | ||
} | ||
|
||
let ConnectedAuthRedirectComponent=connect(mapStateToPropsForRedirect)(RedirectComponent) | ||
return ConnectedAuthRedirectComponent; | ||
} |