index.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { promiseWorker } from "../promise";
  2. import { put, takeEvery, call, select } from 'redux-saga/effects';
  3. import { actionProfilePageDataType,actionUpdateAvatarType } from '../../../actions/types/myDataTypes'
  4. import { actionAboutMe, actionUserUpsert, actionAvatar, actionGetAvatar } from "../../../actions/query/aboutMeQuery";
  5. import {fullPageAboutUserWorker} from '../userProfile'
  6. export function* fullProfilePageWorker() {
  7. const { auth } = yield select()
  8. if (auth?.payload?.sub?.id) {
  9. const aboutMe = yield call(promiseWorker, actionAboutMe(auth?.payload?.sub.id))
  10. if (aboutMe) {
  11. yield put(actionProfilePageDataType(aboutMe))
  12. }
  13. }
  14. }
  15. export function* fullProfilePageWatcher() {
  16. yield takeEvery("FULLPROFILE_PAGE", fullProfilePageWorker)
  17. }
  18. function* userUpdateWorker({ user }) {
  19. const {myData:{aboutMe:{_id}}}= yield select()
  20. const userUpsert = yield call(promiseWorker, actionUserUpsert(user, _id))
  21. if (userUpsert) {
  22. yield call(fullPageAboutUserWorker, { _id })
  23. yield call(fullProfilePageWorker)
  24. }
  25. }
  26. export function* userUpdateWatcher() {
  27. yield takeEvery("USER_UPDATE", userUpdateWorker)
  28. }
  29. function* setAvatarWorker({ file }) {
  30. const {myData:{aboutMe:{_id}}}= yield select()
  31. const setAvatar = yield call(promiseWorker, actionAvatar(file, _id))
  32. console.log('setAvatar', setAvatar)
  33. const {avatar} =yield call(promiseWorker,actionGetAvatar(_id))
  34. if (setAvatar) {
  35. yield call(fullPageAboutUserWorker, { _id })
  36. yield put(actionUpdateAvatarType(avatar))
  37. // yield call(promiseWorker,actionClearPromiseForName("setAvatar"))
  38. // yield call(promiseWorker,actionClearPromiseForName("uploadFile"))
  39. }
  40. }
  41. export function* setAvatarWatcher() {
  42. yield takeEvery("SET_AVATAR", setAvatarWorker)
  43. }