瀏覽代碼

Delete clearFeedWatcher and clearExploreWatcher

LenDoc 1 年之前
父節點
當前提交
c7f99a5c2e

+ 2 - 2
src/redux/reducers/explore/exploreReducer.js

@@ -23,7 +23,7 @@ export const exploreReducer = (
           explorePosts: explorePosts ,
         }
       },
-      'CLEAR-EXPLORE-POSTS': () => ({
+      'CLEAR_EXPLORE_POSTS': () => ({
         ...state,
         explorePosts: [],
         explorePostsCount: 0,
@@ -43,7 +43,7 @@ export const exploreReducer = (
 
 // }
 export const actionClearExplorePosts = () =>
-  ({ type: 'CLEAR-EXPLORE-POSTS' })
+  ({ type: 'CLEAR_EXPLORE_POSTS' })
 
 export const actionExploreType = (newPosts,newPostsExploreCount) => 
   ({ type: 'ADD-EXPLORE-POSTS', newPosts, newPostsExploreCount })

+ 2 - 2
src/redux/reducers/feed/feedReducer.js

@@ -28,7 +28,7 @@ export const feedReducer = (
           postsFeed: postsFeed ,
         }
       },
-      'CLEAR-POSTS': () => ({
+      'CLEAR_POSTS': () => ({
 
         postsFeed: [],
         postsFeedCount: 0,
@@ -65,7 +65,7 @@ export const feedReducer = (
 // }
 
 export const actionClearFeedPosts = () =>
-  ({ type: 'CLEAR-POSTS' })
+  ({ type: 'CLEAR_POSTS' })
 
 //type
 export const actionAddLikePostInTape = (postId) =>

+ 1 - 3
src/redux/reducers/index.js

@@ -13,8 +13,7 @@ import {
   loginWatcher,
   fullPageAboutUserWatcher,
   feedWatcher,
-  clearFeedWatcher,
-  exploreWatcher
+  exploreWatcher,
 } from '../saga'
 import createSagaMiddleware from 'redux-saga' //функция по созданию middleware
 import {
@@ -45,7 +44,6 @@ function* rootSaga() {
     fullProfilePageWatcher(),
     loginWatcher(),
     fullPageAboutUserWatcher(),
-    clearFeedWatcher(),
     feedWatcher(),
     exploreWatcher()
   ])

+ 13 - 17
src/redux/saga/index.js

@@ -14,7 +14,7 @@ import {
   actionAllClearPromise,
   actionLogin,
   actionAuthLogin,
-  
+  actionClearPromise
   } from '../../actions'
 import { history } from '../../helpers'
   import{actionClearDataUserType} from '../reducers/profileUserPage/profileUserReducer'
@@ -29,8 +29,8 @@ import {
 } from '../reducers/feed/feedReducer'
 import { actionProfilePageDataTypeUser,actionCountPostsType } from '../reducers/profileUserPage/profileUserReducer'
 import { actionRemoveDataAboutMe } from '../reducers/profileData/profileReducer'
-import {actionExploreType} from '../reducers/explore/exploreReducer'
-import { all, put,take, fork, takeEvery, takeLatest, takeLeading, select,call } from 'redux-saga/effects'; //
+import {actionExploreType,actionClearExplorePosts} from '../reducers/explore/exploreReducer'
+import { all, put,take, fork, takeEvery, takeLatest, takeLeading, select,call, join } from 'redux-saga/effects'; //
 import {actionPending,actionFulfilled,actionRejected,actionExplorePosts,actionExplorePostsCount} from '../../actions'
 
 
@@ -126,9 +126,9 @@ function* feedWorker() {
   myFollowing = (yield select()).profileData.aboutMe?.following &&
     (yield select()).profileData.aboutMe?.following?.map(({ _id }) => _id)
   // console.log('myFollowing after if', myFollowing)
-  if (postsFeed.length !== (postsFeedCount ? postsFeedCount : 1)) {
+  if (postsFeed?.length !== (postsFeedCount ? postsFeedCount : 1)) {
     const newPosts = yield call(promiseWorker, 
-      actionPostsFeed([...(myFollowing || []), myId], postsFeed.length),
+      actionPostsFeed([...(myFollowing || []), myId], postsFeed?.length),
     )
     console.log('newPosts', newPosts)
     const newPostsFeedCount = yield call(promiseWorker, (
@@ -143,11 +143,6 @@ function* feedWorker() {
 export function* feedWatcher() {
   yield takeLeading("FEED_POSTS", feedWorker)
 }
-export function* clearFeedWatcher() {
-  yield takeLeading("CLEAR-POSTS",
-  yield put(actionClearFeedPosts()))
-}
-
 //explore 
 function* exploreWorker(){
   const {
@@ -155,26 +150,27 @@ function* exploreWorker(){
   } = yield select()
   console.log('explorePosts', explorePosts)
 
+
   if (explorePosts?.length !== (explorePostsCount ? explorePostsCount : 1)) {
     console.log('explorePosts', explorePosts)
 
-    const newPosts = yield call(promiseWorker, actionExplorePosts(explorePosts?.length))
+    const newPosts = yield fork(promiseWorker, actionExplorePosts(explorePosts?.length))
 
     console.log('newPosts', newPosts)
 
-    const newPostsExploreCount = yield call(promiseWorker,(actionExplorePostsCount()))
-    if (newPostsExploreCount && newPosts)
-      yield put(actionExploreType(newPosts, newPostsExploreCount))
-
-    // if (promise?.explorePosts?.status == 'PENDING')
-    //   await dispatch(actionClearExplorePosts())
+    const newPostsExploreCount = yield fork(promiseWorker, (actionExplorePostsCount()))
+    const [posts,exploreCount] = yield join([newPosts,newPostsExploreCount])
+    if (posts && exploreCount)
+      yield put(actionExploreType(posts, exploreCount))
   }
 }
 export function* exploreWatcher() {
   yield takeLeading("EXPLORE_POSTS", exploreWorker)
 }
+
 //feed
 
+
 export const actionAddFullLikeFeed = (postId) => async (dispatch, getState) => {
     await dispatch(actionAddLike(postId))
     const {