App.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import React, { useState, useEffect } from "react";
  2. import "./App.css";
  3. import "bootstrap/dist/css/bootstrap.min.css";
  4. import { store, socket } from "./reducers";
  5. import createHistory from "history/createBrowserHistory";
  6. import { Provider, connect } from "react-redux";
  7. import { Router, Route, Switch } from "react-router-dom";
  8. import { CLogin } from "./pages/LoginPage";
  9. import { CRegistration } from "./pages/RegPage";
  10. import Header from "./pages/Header";
  11. import { CProfilePage } from "./pages/ProfilePage";
  12. import { CNewChatPage } from "./pages/NewChatPage";
  13. import { CChangePass } from "./pages/ChangePassPage";
  14. import { ChangesDone } from "./pages/ChangesDonePage";
  15. import { ChangesDoneForChats } from "./pages/ChangeDoneForChat";
  16. import { AboutUs } from "./pages/AboutUs";
  17. import { Redirect } from "react-router-dom";
  18. import { CChatMsgs } from "./pages/ChatMsgsPage";
  19. import { CChatsAside } from "./pages/ChatsAside";
  20. import { Preloader } from "./helpers/preloaders";
  21. import { CChatEditing } from "./pages/ChatEditing";
  22. export const history = createHistory();
  23. const AuthSwitch = ({ token }) => {
  24. if (token) {
  25. console.log("подключение сокета");
  26. socket.emit("jwt", token);
  27. }
  28. return (
  29. <>
  30. <Switch>
  31. <Route path="/login" component={() => <></>} />
  32. <Route path="/registration" component={() => <></>} />
  33. <Header />
  34. </Switch>
  35. <Route path="/login" component={CLogin} />
  36. <Route path="/registration" component={CRegistration} />
  37. <Route path="/profile" component={CProfilePage} />
  38. <Route path="/newchat" component={CNewChatPage} />
  39. <Route path="/changepas" component={CChangePass} />
  40. <Route path="/changesdone" component={ChangesDone} />
  41. <Route path="/changesdonechats" component={ChangesDoneForChats} />
  42. <Route path="/chatediting/:_id" component={CChatEditing} />
  43. <Route path="/aboutus" component={AboutUs} />
  44. <div className="mainContainer">
  45. <Route path="/main" component={CChatsAside} />
  46. <Route path="/main/:_id" component={CChatMsgs} exact/>
  47. </div>
  48. <Redirect to={token === undefined ? "/login" : "/main"} />
  49. </>
  50. );
  51. };
  52. const CAuthSwitch = connect((state) => ({ token: state.auth?.token }))(
  53. AuthSwitch
  54. );
  55. function App() {
  56. return (
  57. <>
  58. <Router history={history}>
  59. <Provider store={store}>
  60. <div className="container">
  61. <CAuthSwitch />
  62. </div>
  63. </Provider>
  64. </Router>
  65. </>
  66. );
  67. }
  68. export default App;