App.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { Main } from "./components/Main/Main";
  2. import { Header } from "./components/Main/Header";
  3. import { Router } from "react-router-dom";
  4. import { Provider } from "react-redux";
  5. import { createStore, combineReducers, applyMiddleware } from "redux";
  6. import { createBrowserHistory } from "history";
  7. import { Sidebar } from "./components/Main/Sidebar";
  8. import "./App.scss";
  9. import createSagaMiddleware from "redux-saga";
  10. import { all } from "redux-saga/effects";
  11. import {
  12. promiseReducer,
  13. authReducer,
  14. localStoredReducer,
  15. searchReducer,
  16. playerReducer,
  17. routeReducer,
  18. scrollTracksReducer,
  19. } from "./reducers/index";
  20. import { CAudioController } from "./components/Audio/AudioController";
  21. import {
  22. audioLoadWatcher,
  23. audioPlayWatcher,
  24. audioPauseWatcher,
  25. audioPrevTrackWatcher,
  26. audioNextTrackWatcher,
  27. audioSetDurationWatcher,
  28. audioSetVolumeWatcher,
  29. audioSetCurrentTimeWatcher,
  30. audioSetSeekTimeTrackWatcher,
  31. } from "./components/Audio/AudioHandler";
  32. import * as otherSaga from "./actions/sagas";
  33. import {
  34. actionFindUserPlaylists,
  35. actionAllTracks,
  36. actionFullClearTracks,
  37. actionAboutMe,
  38. } from "./actions/types";
  39. export const history = createBrowserHistory();
  40. const sagaMiddleware = createSagaMiddleware();
  41. export const store = createStore(
  42. combineReducers({
  43. promise: localStoredReducer(promiseReducer, "promise"),
  44. auth: localStoredReducer(authReducer, "auth"),
  45. player: localStoredReducer(playerReducer, "player"),
  46. route: localStoredReducer(routeReducer, "route"),
  47. loadedTracks: localStoredReducer(scrollTracksReducer, "loadedTracks"),
  48. search: searchReducer,
  49. }),
  50. applyMiddleware(sagaMiddleware)
  51. );
  52. function* rootSaga() {
  53. yield all([
  54. audioLoadWatcher(),
  55. audioSetDurationWatcher(),
  56. audioPlayWatcher(),
  57. audioPauseWatcher(),
  58. audioPrevTrackWatcher(),
  59. audioNextTrackWatcher(),
  60. audioSetCurrentTimeWatcher(),
  61. audioSetSeekTimeTrackWatcher(),
  62. audioSetVolumeWatcher(),
  63. otherSaga.promiseWatcher(),
  64. otherSaga.aboutMeWatcher(),
  65. otherSaga.routeWatcher(),
  66. otherSaga.loginWatcher(),
  67. otherSaga.registerWatcher(),
  68. otherSaga.findTracksWatcher(),
  69. otherSaga.findUserTracksWatcher(),
  70. otherSaga.setAvatarWatcher(),
  71. otherSaga.setNicknameWatcher(),
  72. otherSaga.setEmailWatcher(),
  73. otherSaga.setNewPasswordWatcher(),
  74. otherSaga.searchWatcher(),
  75. otherSaga.findPlaylistByOwnerWatcher(),
  76. otherSaga.createPlaylistWatcher(),
  77. otherSaga.findPlaylistTracksWatcher(),
  78. otherSaga.loadTracksToPlaylistWatcher(),
  79. otherSaga.uploadTracksToPlaylistWatcher(),
  80. otherSaga.loadNewTracksWatcher(),
  81. otherSaga.addSkipTracksWatcher(),
  82. otherSaga.clearSkipTracksWatcher(),
  83. ]);
  84. }
  85. sagaMiddleware.run(rootSaga);
  86. if (localStorage.authToken) {
  87. store.dispatch(actionFindUserPlaylists());
  88. store.dispatch(actionFullClearTracks());
  89. store.dispatch(actionAllTracks());
  90. store.dispatch(actionAboutMe());
  91. }
  92. export const { ...states } = store.getState();
  93. console.log(states);
  94. store.subscribe(() => console.log(store.getState()));
  95. function App() {
  96. return (
  97. <Router history={history}>
  98. <Provider store={store}>
  99. <div className="App">
  100. <Header />
  101. <Sidebar />
  102. <Main />
  103. {states?.auth?.token ? <CAudioController /> : null}
  104. </div>
  105. </Provider>
  106. </Router>
  107. );
  108. }
  109. export default App;