From b7ce3132655846e27d00b441d7a48f0c0ffeb265 Mon Sep 17 00:00:00 2001
From: Jure Triglav <juretriglav@gmail.com>
Date: Wed, 29 Jul 2020 10:54:10 +0200
Subject: [PATCH] refactor: use hooks instead of recompose in Manuscript
 component

---
 .../src/components/Manuscript.md              | 20 ---------
 .../src/components/ManuscriptPage.js          | 44 ++++++++++---------
 2 files changed, 24 insertions(+), 40 deletions(-)
 delete mode 100644 app/components/component-manuscript/src/components/Manuscript.md

diff --git a/app/components/component-manuscript/src/components/Manuscript.md b/app/components/component-manuscript/src/components/Manuscript.md
deleted file mode 100644
index 3b13f77ee4..0000000000
--- a/app/components/component-manuscript/src/components/Manuscript.md
+++ /dev/null
@@ -1,20 +0,0 @@
-An editor for a manuscript.
-
-```js
-const content = `
-<container id="main">
-<h1>This is a heading</h1>
-<p>This is a paragraph.</p>
-</container>`
-
-const currentUser = {
-  teams: [{ teamType: { name: 'Production Editor' } }],
-}
-;<Manuscript
-  content={content}
-  currentUser={currentUser}
-  fileUpload={data => console.log(data)}
-  updateManuscript={data => console.log(data)}
-  version={{}}
-/>
-```
diff --git a/app/components/component-manuscript/src/components/ManuscriptPage.js b/app/components/component-manuscript/src/components/ManuscriptPage.js
index 2d1847f503..651957b5a5 100644
--- a/app/components/component-manuscript/src/components/ManuscriptPage.js
+++ b/app/components/component-manuscript/src/components/ManuscriptPage.js
@@ -1,9 +1,7 @@
-import { compose, withProps } from 'recompose'
-import { graphql } from '@apollo/client/react/hoc'
-import gql from 'graphql-tag'
-import { withLoader } from 'pubsweet-client'
-
+import React from 'react'
+import { useQuery, gql } from '@apollo/client'
 import Manuscript from './Manuscript'
+import { Spinner } from '../../../shared'
 
 const fragmentFields = `
   id
@@ -17,6 +15,7 @@ const fragmentFields = `
   meta {
     title
     source
+    manuscriptId
   }
   channels {
     id
@@ -38,18 +37,23 @@ const query = gql`
   }
 `
 
-export default compose(
-  graphql(query, {
-    options: ({ match }) => ({
-      variables: {
-        id: match.params.version,
-      },
-    }),
-  }),
-  withLoader(),
-  withProps(({ manuscript }) => ({
-    content: manuscript.meta.source,
-    file: manuscript.files.find(file => file.fileType === 'manuscript') || {},
-    channel: manuscript.channels.find(c => c.type === 'all'),
-  })),
-)(Manuscript)
+const ManuscriptPage = ({ match, ...props }) => {
+  const { data, loading, error } = useQuery(query, {
+    variables: {
+      id: match.params.version,
+    },
+  })
+
+  if (loading) return <Spinner />
+  if (error) return JSON.stringify(error)
+  const { manuscript } = data
+
+  return (
+    <Manuscript
+      channel={manuscript.channels.find(c => c.type === 'all')}
+      content={manuscript.meta?.source}
+      file={manuscript.files.find(file => file.fileType === 'manuscript') || {}}
+    />
+  )
+}
+export default ManuscriptPage
-- 
GitLab