LenDoc пре 1 година
родитељ
комит
c526156a2a

+ 34 - 16
src/actions/index.js

@@ -415,7 +415,7 @@ export const actionAllFollowing = (_id) => async (dispatch) => {
 export const actionAddComment = (postId, text) => async (dispatch) => {
   await dispatch(
     actionPromise(
-      'addComment',
+      "addComment",
       gql(
         `mutation AddComment($comment:CommentInput){
           CommentUpsert(comment:$comment)
@@ -437,6 +437,24 @@ export const actionAddComment = (postId, text) => async (dispatch) => {
     ),
   )
 }
+
+export const actionGetCommentsOnePost = (postId) =>
+    actionPromise('commentsOnePost', gql(`query commentFindPost ($id:String!){
+        PostFindOne(query:$id){
+            comments {
+                _id text createdAt 
+                owner{
+                    _id nick login
+                    avatar{
+                        _id url
+                        }
+                    } 
+                    likes{_id}
+                }
+        }
+    }`, { id: JSON.stringify([{ _id: postId }]) }))
+
+
 export const actionAddSubComment = (commentId, comment) => async (dispatch) => {
   await dispatch(
     actionPromise(
@@ -470,21 +488,21 @@ export const actionAddSubComment = (commentId, comment) => async (dispatch) => {
 //   }
 // }
 
-export const actionAddFullComment = (postId, comment) => async (
-  dispatch,
-  getState,
-) => {
-  await dispatch(actionAddComment(postId, comment))
-  const {
-    promise: {
-      addComment: { status },
-    },
-  } = getState()
-  if (status === 'FULFILLED') {
-    await dispatch(actionOnePost(postId))
-  }
-  // await dispatch(actionOnePost(postId));
-}
+// export const actionAddFullComment = (postId, comment) => async (
+//   dispatch,
+//   getState,
+// ) => {
+//   await dispatch(actionAddComment(postId, comment))
+//   const {
+//     promise: {
+//       addComment: { status },
+//     },
+//   } = getState()
+//   if (status === 'FULFILLED') {
+//     await dispatch(actionOnePost(postId))
+//   }
+//   // await dispatch(actionOnePost(postId));
+// }
 
 export const actionAddSubFullComment = (postId, commentId, comment) => async (
   dispatch,

+ 2 - 2
src/components/Comment.js

@@ -220,7 +220,7 @@ export const Comments = ({
                 {comment?.answers && comment?.answers?.length ? (
                   <div style={{ marginLeft: '10px', display: 'inline-block' }}>
                     <SpoilerButton
-                      style={{ position: 'fixed' }}
+                      // style={{ position: 'fixed' }}
                       text={'More comments'}
                       onClick={() => findSubComment(commentId)}
                     >
@@ -247,7 +247,7 @@ export const CComments = connect(
     addSubComment: state.promise?.addSubComment,
   }),
   {
-    addComment: actionAddFullComment,
+    // addComment: actionAddFullComment,
     addCommentReply: actionAddSubFullComment,
     findSubComment: actionFindSubComment,
   },

+ 6 - 6
src/components/Post.js

@@ -95,14 +95,14 @@ export const PagePost = ({
           <h2> Text: {onePost?.text || ''} </h2>
           <Divider>Comments</Divider>
           <div className="Scroll">
-            <CComments
+            {/* <CComments
               postId={onePost?._id}
               comments={onePost?.comments || []}
-            />
+            /> */}
           </div>
           <div style={{ display: 'flex', margin: '40px 10px' }}>
-            <CLike likes={onePost?.likes} postId={onePost?._id} />
-            <AddComment addComment={addComment} postId={onePost?._id} />
+            {/* <CLike likes={onePost?.likes} postId={onePost?._id} />
+            <AddComment addComment={addComment} postId={onePost?._id} /> */}
           </div>
         </Col>
       </Row>
@@ -118,8 +118,8 @@ export const CPost = connect(
     addComment: state.promise?.addComment?.payload,
   }),
   {
-    addComment: actionAddFullCommentFeed,
-    addCommentReply: actionAddSubFullComment,
+    // addComment: actionAddFullCommentFeed,
+    // addCommentReply: actionAddSubFullComment,
     onPost: actionFullOnePost,
   },
 )(PagePost)

+ 8 - 8
src/pages/feedPosts/index.js

@@ -98,16 +98,16 @@ const MyPostFeed = ({
                     <h1  className='Title'> Text: {text || ''}</h1>
                     <Divider>Comments</Divider>
                     <div className="ScrollForFeed">
-                      {/* <CCommentsForFeed
+                      <CCommentsForFeed
                         postId={_id}
                         comments={comments || []}
-                      /> */}
+                      />
                       </div>
                       <center>
                       <div style={{ display: 'flex', padding: '20px', marginLeft:'100px' }}>
-                        {/* <CLikeForFeed likes={likes} postId={_id} />
+                        {/* <CLikeForFeed likes={likes} postId={_id} /> */}
 
-                        <AddComment addComment={addComment} postId={_id} /> */}
+                        <AddComment addComment={addComment} postId={_id} />
                       </div>
                        </center>
                     </div>
@@ -130,12 +130,12 @@ const MyPostFeed = ({
 const CCommentsForFeed = connect(
   (state) => ({
     addComment: state.promise?.addComment?.payload,
-    addSubComment: state.promise?.addSubComment,
+    // addSubComment: state.promise?.addSubComment,
   }),
   {
     addComment: actionAddFullCommentFeed,
-    addCommentReply: actionAddSubFullComment,
-    findSubComment: actionFindSubComment,
+    // addCommentReply: actionAddSubFullComment,
+    // findSubComment: actionFindSubComment,
   },
 )(Comments)
 
@@ -149,7 +149,7 @@ export const CPostForFeed = connect(
   {
     onPostsFeed: actionFullAllGetPosts,
     onClearFeed: actionClearFeedPosts,
-    // addComment: actionAddFullCommentFeed,
+    addComment: actionAddFullCommentFeed,
     // addCommentReply: actionAddSubFullComment,
     // addLike: actionAddFullLikeForFeed,
 

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

@@ -14,6 +14,8 @@ import {
   fullPageAboutUserWatcher,
   feedWatcher,
   exploreWatcher,
+onePostWatcher,
+  addCommentFeedWatcher
 } from '../saga'
 import createSagaMiddleware from 'redux-saga' //функция по созданию middleware
 import {
@@ -45,7 +47,10 @@ function* rootSaga() {
     loginWatcher(),
     fullPageAboutUserWatcher(),
     feedWatcher(),
-    exploreWatcher()
+    exploreWatcher(),
+
+    onePostWatcher()
+    // addCommentFeedWatcher()
   ])
 }
 sagaMiddleware.run(rootSaga)

+ 3 - 8
src/redux/reducers/post/postReducer.js

@@ -29,11 +29,6 @@ export const postReducer = (
   export const actionClearPostsOne = () => ({ type: 'CLEAR-POST-ONE' })
  
    //one post
-   export const actionFullOnePost = (_id) => async (dispatch) => {
-    const onePost = await dispatch(actionOnePost(_id))
-    if (onePost) {
-      await dispatch(actionOnePostType(onePost))
-      // await dispatch(actionClearDataUserType())
-    }
-  
-  }
+export const actionFullOnePost = (_id) => ({
+  type:"ONE_POST", _id
+})

+ 64 - 18
src/redux/saga/index.js

@@ -14,7 +14,9 @@ import {
   actionAllClearPromise,
   actionLogin,
   actionAuthLogin,
-  actionClearPromise
+  actionClearPromise,
+  actionGetCommentsOnePost,
+  // actionOnePost
   } from '../../actions'
 import { history } from '../../helpers'
   import{actionClearDataUserType} from '../reducers/profileUserPage/profileUserReducer'
@@ -32,7 +34,7 @@ import { actionRemoveDataAboutMe } from '../reducers/profileData/profileReducer'
 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'
-
+import {actionOnePostType,} from '../reducers/post/postReducer'
 
   //promise
  export function* promiseWorker(action){ //это типа actionPromise который thunk
@@ -169,7 +171,64 @@ export function* exploreWatcher() {
 }
 
 //feed
+function* addCommentFeedWorker({ postId, newResult }) {
+  yield call(promiseWorker,actionAddComment(postId, newResult))
+  console.log('ВВВВВВВВВВВВВВ')
+  const { comments } = yield call(promiseWorker, actionGetCommentsOnePost(postId))
+  console.log('commentsss', comments)
+  if (comments)
+    yield put(actionAddCommentPostInTape(postId, newResult))
+  }
+  // const {
+  //   promise: {
+  //     addComment
+  //   }
+  // } = yield select()
+  // if (addComment?.status === 'FULFILLED') {
+  //   console.log('УРААА')
+  //   const onePost = yield call(promiseWorker, actionOnePost(postId))
+  //   if (onePost)
+  //   yield call(promiseWorker,actionAddCommentPostInTape(postId, newResult))
+  // }
+    
+// }
+export function* addCommentFeedWatcher() {
+  yield takeLeading("ADD_COMMENT_FEED", addCommentFeedWorker)
+  
+}
+// export const actionAddFullCommentFeed = (postId, newResult) => async (
+//   dispatch,
+//   getState,
+// ) => {
+//   await dispatch(actionAddComment(postId, newResult))
+//   const {
+//     promise: {
+//       addComment: { status },
+//     },
+//   } = getState()
+//   if (status === 'FULFILLED') {
+//     const onePost = await dispatch(actionOnePost(postId))
+//     if (onePost) await dispatch(actionAddCommentPostInTape(postId, newResult))
+//   }
+//   // await dispatch(actionOnePost(postId));
+// }
 
+//one post
+function* onePostWorker({ _id }) {
+  
+  const onePost = yield call(promiseWorker,actionOnePost(_id))
+  if (onePost)
+  yield put(actionOnePostType(onePost))
+}
+export function* onePostWatcher(){
+yield takeLeading("ONE_POST",onePostWorker)
+}
+// => async (dispatch) => {
+//   const onePost = await dispatch(actionOnePost(_id))
+//   if (onePost) {
+//     await dispatch(actionOnePostType(onePost))
+//     // await dispatch(actionClearDataUserType())
+//   }
 
 export const actionAddFullLikeFeed = (postId) => async (dispatch, getState) => {
     await dispatch(actionAddLike(postId))
@@ -201,22 +260,9 @@ export const actionDeleteFullLikeFeed = (likeId, postId) => async (
   }
 
   //comment
-export const actionAddFullCommentFeed = (postId, newResult) => async (
-    dispatch,
-    getState,
-  ) => {
-    await dispatch(actionAddComment(postId, newResult))
-    const {
-      promise: {
-        addComment: { status },
-      },
-    } = getState()
-    if (status === 'FULFILLED') {
-      const onePost = await dispatch(actionOnePost(postId))
-      if (onePost) await dispatch(actionAddCommentPostInTape(postId, newResult))
-    }
-    // await dispatch(actionOnePost(postId));
-}
+export const actionAddFullCommentFeed = (postId, newResult) => ({
+  type:"ADD_COMMENT_FEED", postId, newResult
+})
 
 //clear user data after log out
 export const actionClearUserData = () => async (dispatch) => {