|
@@ -1,95 +1,86 @@
|
|
|
-import React, {useState, useEffect, useRef, Component} from 'react';
|
|
|
-import logo from './logo.svg'
|
|
|
+import React, {useState, useEffect, useRef, Component} from 'react'
|
|
|
import './App.scss'
|
|
|
-import {Provider, connect} from 'react-redux'
|
|
|
+import {Provider, connect} from 'react-redux'
|
|
|
import {Router, Route, Link, Redirect, Switch} from 'react-router-dom'
|
|
|
import createHistory from "history/createBrowserHistory"
|
|
|
+import {
|
|
|
+ store
|
|
|
+} from "./reducers"
|
|
|
+import {
|
|
|
+ actionFullChatList
|
|
|
+} from "./actions"
|
|
|
|
|
|
import {
|
|
|
Login,
|
|
|
Register,
|
|
|
Main,
|
|
|
+ ChatsPage,
|
|
|
+ CMsgPage
|
|
|
} from "./pages"
|
|
|
import {
|
|
|
- actionAddChat,
|
|
|
- actionUpdateChat,
|
|
|
- actionGetChatsByUser,
|
|
|
- actionGetAllChats,
|
|
|
+ CChatList
|
|
|
+} from "./components"
|
|
|
|
|
|
- actionFullChatList,
|
|
|
+import Grid from '@mui/material/Grid'
|
|
|
|
|
|
- actionGetMsgsByChat,
|
|
|
- actionMsgsCount,
|
|
|
|
|
|
-} from "./actions"
|
|
|
-import {store} from "./reducers"
|
|
|
|
|
|
-const Page404 = () => (
|
|
|
- <h1>Тут ведутся работы</h1>
|
|
|
+const PageNoChat = () => (
|
|
|
+ <h1>Выбирай чат</h1>
|
|
|
)
|
|
|
|
|
|
+const AuthSwitch = ({auth={}, getFirstChats}) => {
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ const userId = auth.payload?.sub?.id
|
|
|
+ if (userId) {
|
|
|
+ getFirstChats(userId, 0, 20)
|
|
|
+ }
|
|
|
+ })
|
|
|
|
|
|
-// const RRoute = ({ action, component:Component, ...routeProps}) => {
|
|
|
-// const WrapperComponent = (componentProps) => {
|
|
|
-// action(componentProps.match)
|
|
|
-// return <Component {...componentProps} />
|
|
|
-// }
|
|
|
-// return <Route {...routeProps} component={WrapperComponent} />
|
|
|
-// }
|
|
|
-// const CRRoute = connect(null, {action: match => ({type: 'ROUTE', match})})(RRoute)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-const AuthSwitch = ({token}) => {
|
|
|
return (
|
|
|
<>
|
|
|
- {token ?
|
|
|
- <>
|
|
|
- <Switch>
|
|
|
- <Route path="/main" component={Main} exact/>
|
|
|
- <Route path="*" component={Main} />
|
|
|
- </Switch>
|
|
|
+ {auth.token ?
|
|
|
+ <>
|
|
|
+ <Main>
|
|
|
+
|
|
|
+ <Grid item xs={12} sm={4}>
|
|
|
+ <ChatsPage>
|
|
|
+ <Switch>
|
|
|
+ <Route path="/find" component={PageNoChat} />
|
|
|
+ <Route path="*" component={CChatList} />
|
|
|
+ </Switch>
|
|
|
+ </ChatsPage>
|
|
|
+ </Grid>
|
|
|
+
|
|
|
+ <Grid item xs={12} sm={8}>
|
|
|
+ <Switch>
|
|
|
+ <Route path="/main" component={PageNoChat} exact/>
|
|
|
+ <Route path="/main/:_id" component={CMsgPage} />
|
|
|
+ <Route path="*" component={PageNoChat} />
|
|
|
+ </Switch>
|
|
|
+ </Grid>
|
|
|
+
|
|
|
+ </Main>
|
|
|
</>
|
|
|
:
|
|
|
<>
|
|
|
- <Switch>
|
|
|
- <Route path="/reg" component={Register} />
|
|
|
- <Route path="/login" component={Login} />
|
|
|
- <Redirect from="/main" to="/login" exact/>
|
|
|
- <Route path="*" component={Login} />
|
|
|
- </Switch>
|
|
|
+ <Switch>
|
|
|
+ <Route path="/reg" component={Register} />
|
|
|
+ <Route path="/login" component={Login} />
|
|
|
+ <Route path="*" component={Login} />
|
|
|
+ </Switch>
|
|
|
</>
|
|
|
}
|
|
|
</>
|
|
|
)
|
|
|
}
|
|
|
-const CAuthSwitch = connect(state => ({token: state.auth.token || null}))(AuthSwitch)
|
|
|
+const CAuthSwitch = connect(state => ({auth: state.auth }),
|
|
|
+ {getFirstChats: actionFullChatList} )(AuthSwitch)
|
|
|
|
|
|
const history = createHistory()
|
|
|
|
|
|
function App() {
|
|
|
- // "61d76d947b27dd2bab607273" bu
|
|
|
- // "617ad9262b5f0a03e6fd4037" tst
|
|
|
- let memb = [
|
|
|
- {_id: "61d76d947b27dd2bab607273"},
|
|
|
- {_id: "617ad9262b5f0a03e6fd4037"},
|
|
|
- ]
|
|
|
- // "61dae9437b27dd2bab6072b6" ЗАЛУПА228
|
|
|
-
|
|
|
- // store.dispatch(actionAddChat('Титул'))
|
|
|
- // store.dispatch(actionUpdateChat("61dae9437b27dd2bab6072b6", 'ЗАЛУПА228', memb))
|
|
|
- // store.dispatch(actionGetChatsByUser("61d76d947b27dd2bab607273"))
|
|
|
- // store.dispatch(actionFullChatList("61d76d947b27dd2bab607273", 0))
|
|
|
-
|
|
|
- // store.dispatch(actionGetMsgsByChat("61dae9437b27dd2bab6072b6"))
|
|
|
- // store.dispatch(actionMsgsCount("61dae9437b27dd2bab6072b6"))
|
|
|
-
|
|
|
-
|
|
|
|
|
|
return (
|
|
|
<Router history={history}>
|
|
@@ -101,7 +92,20 @@ function App() {
|
|
|
</div>
|
|
|
</Provider>
|
|
|
</Router>
|
|
|
- );
|
|
|
+ )
|
|
|
}
|
|
|
+export default App
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// const RRoute = ({ action, component:Component, ...routeProps}) => {
|
|
|
+// const WrapperComponent = (componentProps) => {
|
|
|
+// action(componentProps.match)
|
|
|
+// return <Component {...componentProps} />
|
|
|
+// }
|
|
|
+// return <Route {...routeProps} component={WrapperComponent} />
|
|
|
+// }
|
|
|
+// const CRRoute = connect(null, {action: match => ({type: 'ROUTE', match})})(RRoute)
|
|
|
+
|
|
|
|
|
|
-export default App;
|