From c579e912cf4e3df719de953f2dfea6f9a0902b50 Mon Sep 17 00:00:00 2001
From: Mihail Hagiu <mihail.hagiu@thinslices.com>
Date: Tue, 9 Oct 2018 10:01:26 +0300
Subject: [PATCH] feat(publonsTable): work in progress

---
 .../src/contextualBoxes/ReviewerDetails.js     |  4 +---
 .../src/components/ManuscriptLayout.js         |  2 +-
 .../src/components/ManuscriptPage.js           | 18 +++++++++++++++++-
 .../components-faraday/src/redux/reviewers.js  |  2 +-
 4 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/packages/component-faraday-ui/src/contextualBoxes/ReviewerDetails.js b/packages/component-faraday-ui/src/contextualBoxes/ReviewerDetails.js
index aae2c213f..d37e18d64 100644
--- a/packages/component-faraday-ui/src/contextualBoxes/ReviewerDetails.js
+++ b/packages/component-faraday-ui/src/contextualBoxes/ReviewerDetails.js
@@ -93,9 +93,7 @@ const ReviewerDetails = ({
                   {publons.length === 0 && (
                     <Text align="center">No suggestions yet.</Text>
                   )}
-                  {console.log('------------------------', publons) || (
-                    <PublonsTable reviewers={publons} />
-                  )}
+                  <PublonsTable reviewers={publons} />
                 </Fragment>
               )}
               {selectedTab === 2 && (
diff --git a/packages/component-manuscript/src/components/ManuscriptLayout.js b/packages/component-manuscript/src/components/ManuscriptLayout.js
index f2bc74eb3..d74185097 100644
--- a/packages/component-manuscript/src/components/ManuscriptLayout.js
+++ b/packages/component-manuscript/src/components/ManuscriptLayout.js
@@ -177,13 +177,13 @@ const ManuscriptLayout = ({
             currentUser={currentUser}
             fragment={fragment}
             getSignedUrl={getSignedUrl}
-            publons={publonReviewers}
             invitations={invitationsWithReviewers}
             journal={journal}
             onInvitePublonReviewer={onInvitePublonReviewer}
             onInviteReviewer={onInviteReviewer}
             onResendReviewerInvite={onResendReviewerInvite}
             onRevokeReviewerInvite={onRevokeReviewerInvite}
+            publons={publonReviewers}
             reviewerReports={reviewerReports}
           />
         )}
diff --git a/packages/component-manuscript/src/components/ManuscriptPage.js b/packages/component-manuscript/src/components/ManuscriptPage.js
index 93ec5ed2e..b92e0b9b8 100644
--- a/packages/component-manuscript/src/components/ManuscriptPage.js
+++ b/packages/component-manuscript/src/components/ManuscriptPage.js
@@ -73,6 +73,7 @@ export default compose(
   setDisplayName('ManuscriptPage'),
   withJournal,
   withRouter,
+  withState('publonReviewers', 'setPub', []),
   withState('editorInChief', 'setEiC', 'N/A'),
   ConnectPage(({ match }) => [
     actions.getCollection({ id: match.params.project }),
@@ -168,7 +169,7 @@ export default compose(
         state,
         get(fragment, 'id', ''),
       ),
-      publonReviewers: getPublonReviewers(get(fragment, 'id', ''))(state),
+      publonReviewers: getPublonReviewers(get(fragment, 'id', '')),
     }),
   ),
   ConnectPage(({ currentUser }) => {
@@ -202,6 +203,9 @@ export default compose(
         setEiC(`${firstName} ${lastName}`)
       }
     },
+    setPublons: ({ setPub }) => publons => {
+      if (publons) setPub(publons)
+    },
     assignHE: ({
       assignHandlingEditor,
       fetchUpdatedCollection,
@@ -415,6 +419,7 @@ export default compose(
   })),
   withProps(({ currentUser, submittedOwnRecommendation }) => ({
     getSignedUrl,
+    publonReviewers: [],
     shouldReview:
       get(currentUser, 'isReviewer', false) &&
       isUndefined(submittedOwnRecommendation),
@@ -425,13 +430,18 @@ export default compose(
         match,
         history,
         location,
+        setPublons,
         shouldReview,
         setEditorInChief,
         clearCustomError,
         hasManuscriptFailure,
         fetchUpdatedCollection,
         currentUser: { isInvitedHE, isInvitedToReview },
+        publonReviewers,
       } = this.props
+
+      // publonReviewers.then(publons => console.log('PUBLONS', publons))
+
       if (hasManuscriptFailure) {
         history.push('/not-found')
         clearCustomError()
@@ -451,6 +461,12 @@ export default compose(
         setEditorInChief(head(res.users)),
       )
 
+      apiGet(`/fragments/${fragmentId}/publons`).then(res => {
+        if (!publonReviewers) {
+          setPublons(res)
+        }
+      })
+
       if (isInvitedHE) {
         this.props.toggleHEResponse()
       }
diff --git a/packages/components-faraday/src/redux/reviewers.js b/packages/components-faraday/src/redux/reviewers.js
index 967de18d0..d17294f52 100644
--- a/packages/components-faraday/src/redux/reviewers.js
+++ b/packages/components-faraday/src/redux/reviewers.js
@@ -58,7 +58,7 @@ export const getCollectionReviewers = (collectionId, fragmentId) => dispatch =>
     `/collections/${collectionId}/fragments/${fragmentId}/invitations?role=reviewer`,
   )
 
-export const getPublonReviewers = fragmentId => dispatch =>
+export const getPublonReviewers = fragmentId =>
   apiGet(`/fragments/${fragmentId}/publons`)
 // #endregion
 
-- 
GitLab