Skip to content
Snippets Groups Projects
Commit b7ce3132 authored by Jure's avatar Jure
Browse files

refactor: use hooks instead of recompose in Manuscript component

parent f2d9d8a7
No related branches found
No related tags found
No related merge requests found
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={{}}
/>
```
import { compose, withProps } from 'recompose' import React from 'react'
import { graphql } from '@apollo/client/react/hoc' import { useQuery, gql } from '@apollo/client'
import gql from 'graphql-tag'
import { withLoader } from 'pubsweet-client'
import Manuscript from './Manuscript' import Manuscript from './Manuscript'
import { Spinner } from '../../../shared'
const fragmentFields = ` const fragmentFields = `
id id
...@@ -17,6 +15,7 @@ const fragmentFields = ` ...@@ -17,6 +15,7 @@ const fragmentFields = `
meta { meta {
title title
source source
manuscriptId
} }
channels { channels {
id id
...@@ -38,18 +37,23 @@ const query = gql` ...@@ -38,18 +37,23 @@ const query = gql`
} }
` `
export default compose( const ManuscriptPage = ({ match, ...props }) => {
graphql(query, { const { data, loading, error } = useQuery(query, {
options: ({ match }) => ({ variables: {
variables: { id: match.params.version,
id: match.params.version, },
}, })
}),
}), if (loading) return <Spinner />
withLoader(), if (error) return JSON.stringify(error)
withProps(({ manuscript }) => ({ const { manuscript } = data
content: manuscript.meta.source,
file: manuscript.files.find(file => file.fileType === 'manuscript') || {}, return (
channel: manuscript.channels.find(c => c.type === 'all'), <Manuscript
})), channel={manuscript.channels.find(c => c.type === 'all')}
)(Manuscript) content={manuscript.meta?.source}
file={manuscript.files.find(file => file.fileType === 'manuscript') || {}}
/>
)
}
export default ManuscriptPage
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment