App.js 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import './App.css';
  2. import { BrowserRouter as Router, Route, Link, Switch, Redirect } from 'react-router-dom';
  3. import createHistory from "history/createBrowserHistory";
  4. import React, { useState } from 'react';
  5. import { Provider, connect } from 'react-redux';
  6. import store from './reducers';
  7. import { actionFullLogin, actionFullRegister, actionUploadFile, actionGetFile, actionFullAddChat, actionFullEditMSG, actionFullGetChats, actionAddMSG } from './actions';
  8. import { MyDropzone } from './components/dropzone';
  9. import { LoginForm } from './components/loginForm';
  10. import { RegistrationForm } from './components/registrationForm';
  11. import { ConnectChatOnline, ConnectMain } from './pages/main';
  12. //for tests
  13. // let msgARR = [{ "_id": "615e0b5fdd6e923e41f3348e", "text": "hi111", "createdAt": "1633553247000", "owner": { "login": "test1111", "_id": "61460c90ae7d905e54d32d11", "nick": null } },
  14. // { "_id": "615e0c88dd6e923e41f3348f", "text": "hi111", "createdAt": "1633553544000", "owner": { "login": "test1111", "_id": "61460c90ae7d905e54d32d11", "nick": null } },
  15. // { "_id": "615e0e02dd6e923e41f33490", "text": "hi111", "createdAt": "1633553922000", "owner": { "login": "test1111", "_id": "61460c90ae7d905e54d32d11", "nick": null } },
  16. // { "_id": "615e102cdd6e923e41f33492", "text": "hi", "createdAt": "1633554476000", "owner": { "login": "test1111", "_id": "61460c90ae7d905e54d32d11", "nick": null } },
  17. // { "_id": "615e113bdd6e923e41f33493", "text": "hi111", "createdAt": "1633554747000", "owner": { "login": "test1111", "_id": "61460c90ae7d905e54d32d11", "nick": null } },
  18. // { "_id": "615e12cddd6e923e41f33495", "text": "hi111", "createdAt": "1633555149000", "owner": { "login": "test1111", "_id": "61460c90ae7d905e54d32d11", "nick": null } },
  19. // { "_id": "615e146bdd6e923e41f33497", "text": "hi111", "createdAt": "1633555563000", "owner": { "login": "test1111", "_id": "61460c90ae7d905e54d32d11", "nick": null } }]
  20. // let chatsASS = {
  21. // 1: {
  22. // title: "первый",
  23. // lastModified: "токошо",
  24. // avatar: {
  25. // url: "/опа"
  26. // },
  27. // messages: [{}, {}, { text: "привет" }]
  28. // },
  29. // 2: {
  30. // title: "второй"
  31. // },
  32. // 3: {
  33. // title: "третий"
  34. // }
  35. // }
  36. const Preloading = ({ promiseName, promiseState, children }) => {
  37. return (
  38. <>
  39. {(promiseState[promiseName] && promiseState[promiseName].status === "RESOLVED") ? children : null}
  40. </>
  41. )
  42. }
  43. const CPreloading = connect(state => ({ promiseState: state.promise }))
  44. // const PrivateRoute = ({ component, roles, auth, fallback = "/login", ...originalProps }) => {
  45. // const PageWrapper = (pageProps) => {
  46. // const OriginalPage = component
  47. // //сопоставить роли с аус
  48. // if (пересечение роли с аус(ацл из него) в наличии) {
  49. // return <OriginalPage {...pageProps} />
  50. // } else {
  51. // return <Redirect to={fallback} />
  52. // }
  53. // }
  54. // return (
  55. // <Route component={PageWrapper} {...originalProps} />
  56. // )
  57. // }
  58. // const MyUltraRoute = connect(сделать аус)(PrivateRoute)
  59. const ConnectLoginForm = connect(null, { onLogin: actionFullLogin })(LoginForm)
  60. const ConnectRegistrationForm = connect(null, { onRegistration: actionFullRegister })(RegistrationForm)
  61. const ConnectDropZone = connect(null, { onUpload: actionUploadFile })(MyDropzone)
  62. store.subscribe(() => console.log(store.getState()))
  63. // console.log(store.dispatch(actionGetFile("61534453dd6e923e41f3344c")))
  64. // store.dispatch(actionFullGetChats("61460c90ae7d905e54d32d11"))
  65. function App() {
  66. return (
  67. <Provider store={store}>
  68. <Router history={createHistory()}>
  69. <div className="App">
  70. <Switch>
  71. <Route path="/registration" component={ConnectRegistrationForm} exact />
  72. <Route path="/login" component={ConnectLoginForm} exact />
  73. <Route path="/:_id" component={ConnectMain} />
  74. <Redirect from="/login" to="/chat" />
  75. <Redirect from="/" to="/chat" />
  76. </Switch>
  77. </div >
  78. </Router>
  79. </Provider>
  80. );
  81. }
  82. export default App;