|
@@ -9,13 +9,14 @@ import {
|
|
authReducer,
|
|
authReducer,
|
|
localStoredReducer,
|
|
localStoredReducer,
|
|
playerReducer,
|
|
playerReducer,
|
|
|
|
+ routeReducer,
|
|
} from "./reducers/index";
|
|
} from "./reducers/index";
|
|
import { Sidebar } from "./components/Sidebar";
|
|
import { Sidebar } from "./components/Sidebar";
|
|
import "./App.scss";
|
|
import "./App.scss";
|
|
import createSagaMiddleware from "redux-saga";
|
|
import createSagaMiddleware from "redux-saga";
|
|
import { all, takeEvery, put, call, select } from "redux-saga/effects";
|
|
import { all, takeEvery, put, call, select } from "redux-saga/effects";
|
|
import * as actions from "./actions";
|
|
import * as actions from "./actions";
|
|
-import { CAudioController } from "./components/AudioController";
|
|
|
|
|
|
+import { gql } from "./helpers";
|
|
export const history = createBrowserHistory();
|
|
export const history = createBrowserHistory();
|
|
|
|
|
|
const sagaMiddleware = createSagaMiddleware();
|
|
const sagaMiddleware = createSagaMiddleware();
|
|
@@ -25,10 +26,33 @@ export const store = createStore(
|
|
promise: localStoredReducer(promiseReducer, "promise"),
|
|
promise: localStoredReducer(promiseReducer, "promise"),
|
|
auth: localStoredReducer(authReducer, "auth"),
|
|
auth: localStoredReducer(authReducer, "auth"),
|
|
player: localStoredReducer(playerReducer, "player"),
|
|
player: localStoredReducer(playerReducer, "player"),
|
|
|
|
+ route: localStoredReducer(routeReducer, "route"),
|
|
|
|
+ // изменить условия на страницах на отображения по роутам
|
|
}),
|
|
}),
|
|
applyMiddleware(sagaMiddleware)
|
|
applyMiddleware(sagaMiddleware)
|
|
);
|
|
);
|
|
|
|
|
|
|
|
+function* rootSaga() {
|
|
|
|
+ yield all([
|
|
|
|
+ promiseWatcher(),
|
|
|
|
+ aboutMeWatcher(),
|
|
|
|
+ routeWatcher(),
|
|
|
|
+ loginWatcher(),
|
|
|
|
+ registerWatcher(),
|
|
|
|
+ findTracksWatcher(),
|
|
|
|
+ setAvatarWatcher(),
|
|
|
|
+ setNicknameWatcher(),
|
|
|
|
+ setEmailWatcher(),
|
|
|
|
+ setNewPasswordWatcher(),
|
|
|
|
+ audioPlayWatcher(),
|
|
|
|
+ audioPauseWatcher(),
|
|
|
|
+ audioVolumeWatcher(),
|
|
|
|
+ audioLoadWatcher(),
|
|
|
|
+ ]);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+sagaMiddleware.run(rootSaga);
|
|
|
|
+
|
|
function* promiseWorker(action) {
|
|
function* promiseWorker(action) {
|
|
const { name, promise } = action;
|
|
const { name, promise } = action;
|
|
yield put(actions.actionPending(name));
|
|
yield put(actions.actionPending(name));
|
|
@@ -48,14 +72,38 @@ function* promiseWatcher() {
|
|
function* aboutMeWorker() {
|
|
function* aboutMeWorker() {
|
|
// let { id } = getState().auth.payload.sub;
|
|
// let { id } = getState().auth.payload.sub;
|
|
// await dispatch(actionFindUser(id));
|
|
// await dispatch(actionFindUser(id));
|
|
- let { id } = yield select().auth?.payload?.sub;
|
|
|
|
- yield call(promiseWatcher, actions.actionFindUser(id));
|
|
|
|
|
|
+ let { auth } = yield select();
|
|
|
|
+ if (auth) {
|
|
|
|
+ let { id } = auth?.payload?.sub;
|
|
|
|
+ yield call(promiseWatcher, actions.actionFindUser(id));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
function* aboutMeWatcher() {
|
|
function* aboutMeWatcher() {
|
|
yield takeEvery("ABOUT_ME", aboutMeWorker);
|
|
yield takeEvery("ABOUT_ME", aboutMeWorker);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+if (localStorage.authToken) {
|
|
|
|
+ store.dispatch(actions.actionAboutMe());
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const queries = {};
|
|
|
|
+
|
|
|
|
+function* routeWorker({ match }) {
|
|
|
|
+ console.log(match);
|
|
|
|
+ if (match.path in queries) {
|
|
|
|
+ const { name, query, variables } = queries[match.path](match);
|
|
|
|
+ yield call(
|
|
|
|
+ promiseWorker,
|
|
|
|
+ actions.actionPromise(name, gql(query, variables))
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function* routeWatcher() {
|
|
|
|
+ yield takeEvery("ROUTE", routeWorker);
|
|
|
|
+}
|
|
|
|
+
|
|
function* loginWorker({ login, password }) {
|
|
function* loginWorker({ login, password }) {
|
|
let token = yield call(promiseWorker, actions.actionLogin(login, password));
|
|
let token = yield call(promiseWorker, actions.actionLogin(login, password));
|
|
if (token) {
|
|
if (token) {
|
|
@@ -105,12 +153,14 @@ function* setAvatarWorker({ file }) {
|
|
// await dispatch(actionUserUpdate({ _id: id, avatar: { _id } }));
|
|
// await dispatch(actionUserUpdate({ _id: id, avatar: { _id } }));
|
|
// await dispatch(actionAboutMe());
|
|
// await dispatch(actionAboutMe());
|
|
// };
|
|
// };
|
|
- let { _id } = yield call(promiseWatcher, actions.actionSetAvatar(file));
|
|
|
|
|
|
+ let { _id } = yield call(promiseWatcher, actions.actionUploadFile(file)); //upload file
|
|
let { id } = yield select().auth.payload.sub;
|
|
let { id } = yield select().auth.payload.sub;
|
|
|
|
+ console.log("Set avatar");
|
|
yield call(
|
|
yield call(
|
|
promiseWatcher,
|
|
promiseWatcher,
|
|
actions.actionUserUpdate({ _id: id, avatar: { _id } })
|
|
actions.actionUserUpdate({ _id: id, avatar: { _id } })
|
|
);
|
|
);
|
|
|
|
+ yield put(actions.actionAboutMe());
|
|
}
|
|
}
|
|
|
|
|
|
function* setAvatarWatcher() {
|
|
function* setAvatarWatcher() {
|
|
@@ -153,9 +203,17 @@ function* setNewPasswordWatcher() {
|
|
yield takeEvery("SET_NEW_PASSWORD", setNewPasswordWorker);
|
|
yield takeEvery("SET_NEW_PASSWORD", setNewPasswordWorker);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+function* audioLoadWorker({ track, duration, playlist, playlistIndex }) {
|
|
|
|
+ yield put(actions.actionLoadAudio(track, duration, playlist, playlistIndex));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function* audioLoadWatcher() {
|
|
|
|
+ yield takeEvery("LOAD_TRACK", audioLoadWorker);
|
|
|
|
+}
|
|
|
|
+
|
|
function* audioPlayWorker({ isPlaying }) {
|
|
function* audioPlayWorker({ isPlaying }) {
|
|
|
|
+ console.log("Play track");
|
|
yield put(actions.actionPlayAudio(isPlaying));
|
|
yield put(actions.actionPlayAudio(isPlaying));
|
|
- yield put(actions.actionAboutMe());
|
|
|
|
}
|
|
}
|
|
|
|
|
|
function* audioPlayWatcher() {
|
|
function* audioPlayWatcher() {
|
|
@@ -164,7 +222,6 @@ function* audioPlayWatcher() {
|
|
|
|
|
|
function* audioPauseWorker({ isPaused }) {
|
|
function* audioPauseWorker({ isPaused }) {
|
|
yield put(actions.actionPauseAudio(isPaused));
|
|
yield put(actions.actionPauseAudio(isPaused));
|
|
- yield put(actions.actionAboutMe());
|
|
|
|
}
|
|
}
|
|
|
|
|
|
function* audioPauseWatcher() {
|
|
function* audioPauseWatcher() {
|
|
@@ -173,17 +230,12 @@ function* audioPauseWatcher() {
|
|
|
|
|
|
function* audioVolumeWorker({ volume }) {
|
|
function* audioVolumeWorker({ volume }) {
|
|
yield put(actions.actionVolumeAudio(volume));
|
|
yield put(actions.actionVolumeAudio(volume));
|
|
- yield put(actions.actionAboutMe());
|
|
|
|
}
|
|
}
|
|
|
|
|
|
function* audioVolumeWatcher() {
|
|
function* audioVolumeWatcher() {
|
|
yield takeEvery("VOLUME_TRACK", audioVolumeWorker);
|
|
yield takeEvery("VOLUME_TRACK", audioVolumeWorker);
|
|
}
|
|
}
|
|
|
|
|
|
-if (localStorage.authToken) {
|
|
|
|
- store.dispatch(actions.actionAboutMe());
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
if (
|
|
if (
|
|
localStorage.authToken &&
|
|
localStorage.authToken &&
|
|
(history.location.pathname === "/search" ||
|
|
(history.location.pathname === "/search" ||
|
|
@@ -194,25 +246,6 @@ if (
|
|
|
|
|
|
store.subscribe(() => console.log(store.getState()));
|
|
store.subscribe(() => console.log(store.getState()));
|
|
|
|
|
|
-function* rootSaga() {
|
|
|
|
- yield all([
|
|
|
|
- promiseWatcher(),
|
|
|
|
- loginWatcher(),
|
|
|
|
- registerWatcher(),
|
|
|
|
- aboutMeWatcher(),
|
|
|
|
- findTracksWatcher(),
|
|
|
|
- setAvatarWatcher(),
|
|
|
|
- setNicknameWatcher(),
|
|
|
|
- setEmailWatcher(),
|
|
|
|
- setNewPasswordWatcher(),
|
|
|
|
- audioPlayWatcher(),
|
|
|
|
- audioPauseWatcher(),
|
|
|
|
- audioVolumeWatcher(),
|
|
|
|
- ]);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-sagaMiddleware.run(rootSaga);
|
|
|
|
-
|
|
|
|
function App() {
|
|
function App() {
|
|
return (
|
|
return (
|
|
<Router history={history}>
|
|
<Router history={history}>
|
|
@@ -227,5 +260,4 @@ function App() {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
-// <CAudioController />
|
|
|
|
export default App;
|
|
export default App;
|