Skip to content
Snippets Groups Projects
Commit f206fa58 authored by Alexandru Munteanu's avatar Alexandru Munteanu
Browse files

remove unused code and use pubsweet-modal for dashboard

parent 81044138
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,10 @@ class Modal extends React.Component { ...@@ -16,7 +16,10 @@ class Modal extends React.Component {
render() { render() {
const { component: Component, overlayColor, ...rest } = this.props const { component: Component, overlayColor, ...rest } = this.props
return ReactDOM.createPortal( return ReactDOM.createPortal(
<ModalRoot overlayColor={overlayColor}> <ModalRoot
onClick={rest.dismissable ? rest.hideModal : null}
overlayColor={overlayColor}
>
<Component {...rest} /> <Component {...rest} />
</ModalRoot>, </ModalRoot>,
modalRoot, modalRoot,
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
"react-dnd": "^2.5.4", "react-dnd": "^2.5.4",
"react-dnd-html5-backend": "^2.5.4", "react-dnd-html5-backend": "^2.5.4",
"react-dom": "^15.6.1", "react-dom": "^15.6.1",
"react-modal": "^3.2.1",
"react-router-dom": "^4.2.2", "react-router-dom": "^4.2.2",
"recompose": "^0.26.0", "recompose": "^0.26.0",
"redux": "^3.6.0", "redux": "^3.6.0",
......
import React from 'react' import React from 'react'
import { get } from 'lodash' import { get } from 'lodash'
import Modal from 'react-modal'
import { Icon } from '@pubsweet/ui' import { Icon } from '@pubsweet/ui'
import styled from 'styled-components' import styled from 'styled-components'
const customStyles = { const AbstractModal = ({ metadata, hideModal }) => (
overlay: { <Root>
position: 'fixed', <CloseIcon onClick={hideModal}>
top: 0, <Icon color="#667080">x</Icon>
left: 0, </CloseIcon>
right: 0, <Title dangerouslySetInnerHTML={{ __html: get(metadata, 'title') }} />
bottom: 0, <Subtitle>Abstract</Subtitle>
backgroundColor: 'rgba(102, 112, 128, 0.8)', <Content dangerouslySetInnerHTML={{ __html: get(metadata, 'abstract') }} />
}, </Root>
content: { )
top: '50%',
left: '50%',
right: 'auto',
bottom: 'auto',
marginRight: '-50%',
transform: 'translate(-50%, -50%)',
width: 600,
maxHeight: 500,
padding: 0,
overflowY: 'auto',
opacity: 1,
backgroundColor: 'transparent',
border: 'none',
borderRadius: 0,
},
}
const AbstractModal = ({ abstractModal, onClose }) => {
const isOpen = !!abstractModal
return (
<Modal
ariaHideApp={false}
isOpen={isOpen}
onRequestClose={onClose}
shouldCloseOnOverlayClick
style={customStyles}
>
<Root>
<CloseIcon onClick={onClose}>
<Icon color="#667080">x</Icon>
</CloseIcon>
<Title
dangerouslySetInnerHTML={{ __html: get(abstractModal, 'title') }}
/>
<Subtitle>Abstract</Subtitle>
<Content
dangerouslySetInnerHTML={{ __html: get(abstractModal, 'abstract') }}
/>
</Root>
</Modal>
)
}
export default AbstractModal export default AbstractModal
...@@ -65,6 +22,8 @@ const Root = styled.div` ...@@ -65,6 +22,8 @@ const Root = styled.div`
padding: 50px 32px 32px 32px; padding: 50px 32px 32px 32px;
border: 1px solid #667080; border: 1px solid #667080;
position: relative; position: relative;
width: 600px;
max-height: 500px;
` `
const Title = styled.div` const Title = styled.div`
......
import React from 'react' import React from 'react'
import { get } from 'lodash' import { get } from 'lodash'
import { Button } from '@pubsweet/ui' import { Button } from '@pubsweet/ui'
import styled from 'styled-components'
import { compose, withHandlers } from 'recompose' import { compose, withHandlers } from 'recompose'
import { withModal } from 'pubsweet-component-modal/src/components' import { withModal } from 'pubsweet-component-modal/src/components'
...@@ -23,9 +22,7 @@ const Dashboard = ({ ...@@ -23,9 +22,7 @@ const Dashboard = ({
changeFilterValue, changeFilterValue,
filterValues, filterValues,
filterItems, filterItems,
abstractModal, showAbstractModal,
setModal,
showModal,
...rest ...rest
}) => ( }) => (
<div className={classes.root}> <div className={classes.root}>
...@@ -35,17 +32,6 @@ const Dashboard = ({ ...@@ -35,17 +32,6 @@ const Dashboard = ({
<Button onClick={createDraftSubmission} primary> <Button onClick={createDraftSubmission} primary>
New New
</Button> </Button>
<Button
onClick={() =>
showModal({
onConfirm: () => alert('confirm'),
costel: true,
})
}
primary
>
Show modal
</Button>
</div> </div>
</div> </div>
<DashboardFilters <DashboardFilters
...@@ -58,34 +44,22 @@ const Dashboard = ({ ...@@ -58,34 +44,22 @@ const Dashboard = ({
deleteProject={deleteProject} deleteProject={deleteProject}
list={getItems()} list={getItems()}
listView={listView} listView={listView}
showAbstractModal={showAbstractModal}
/> />
<AbstractModal abstractModal={abstractModal} onClose={setModal()} />
</div> </div>
) )
const ModalRoot = styled.div`
width: 300px;
height: 400px;
background-color: gray;
`
const ModalComponent = ({ hideModal, dismissable, onConfirm, costel }) => (
<ModalRoot onClick={dismissable ? hideModal : null}>
This is our custom modal component.
<div>
<button onClick={onConfirm}>Yes</button>
<button onClick={hideModal}>Hide modal</button>
<span>{costel ? 'e costel' : 'nu e'}</span>
</div>
</ModalRoot>
)
export default compose( export default compose(
withModal({ withModal({
modalComponent: ModalComponent, modalComponent: AbstractModal,
overlayColor: 'rgba(255, 0,0,0.8)',
}), }),
withHandlers({ withHandlers({
showAbstractModal: ({ showModal }) => metadata => () => {
showModal({
metadata,
dismissable: true,
})
},
getItems: ({ getItems: ({
filters, filters,
sortOrder, sortOrder,
......
import React from 'react' import React from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames' import classnames from 'classnames'
import { get, isEmpty } from 'lodash' import { get, isEmpty } from 'lodash'
import styled from 'styled-components' import styled from 'styled-components'
import { Button, Icon } from '@pubsweet/ui' import { Button, Icon } from '@pubsweet/ui'
import { compose, getContext } from 'recompose'
import { parseVersion, getFilesURL, downloadAll } from './utils' import { parseVersion, getFilesURL, downloadAll } from './utils'
import classes from './Dashboard.local.scss' import classes from './Dashboard.local.scss'
...@@ -15,7 +13,7 @@ const DashboardCard = ({ ...@@ -15,7 +13,7 @@ const DashboardCard = ({
listView, listView,
project, project,
version, version,
setModal, showAbstractModal,
}) => { }) => {
const { submitted, author, title, type, version: vers } = parseVersion( const { submitted, author, title, type, version: vers } = parseVersion(
version, version,
...@@ -75,7 +73,7 @@ const DashboardCard = ({ ...@@ -75,7 +73,7 @@ const DashboardCard = ({
<div className={classes.column2}> <div className={classes.column2}>
<div>{author}</div> <div>{author}</div>
{abstract && ( {abstract && (
<ViewAbstractContainer onClick={setModal(metadata)}> <ViewAbstractContainer onClick={showAbstractModal(metadata)}>
<Icon color="#667080" size={18}> <Icon color="#667080" size={18}>
eye eye
</Icon> </Icon>
...@@ -131,8 +129,4 @@ const ViewAbstractContainer = styled.div` ...@@ -131,8 +129,4 @@ const ViewAbstractContainer = styled.div`
} }
` `
export default compose( export default DashboardCard
getContext({
setModal: PropTypes.func,
}),
)(DashboardCard)
...@@ -6,7 +6,12 @@ import classes from './Dashboard.local.scss' ...@@ -6,7 +6,12 @@ import classes from './Dashboard.local.scss'
const DashboardItem = withVersion(Item) const DashboardItem = withVersion(Item)
const DashboardItems = ({ list, listView = true, deleteProject }) => ( const DashboardItems = ({
list,
listView = true,
deleteProject,
showAbstractModal,
}) => (
<div> <div>
{!list.length && ( {!list.length && (
<div className={classes.empty}> <div className={classes.empty}>
...@@ -22,6 +27,7 @@ const DashboardItems = ({ list, listView = true, deleteProject }) => ( ...@@ -22,6 +27,7 @@ const DashboardItems = ({ list, listView = true, deleteProject }) => (
key={p.id} key={p.id}
listView={listView} listView={listView}
project={p} project={p}
showAbstractModal={showAbstractModal}
/> />
))} ))}
</div> </div>
......
import { get } from 'lodash' import { get } from 'lodash'
import PropTypes from 'prop-types'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { actions } from 'pubsweet-client' import { actions } from 'pubsweet-client'
import { ConnectPage } from 'xpub-connect' import { ConnectPage } from 'xpub-connect'
import { withRouter } from 'react-router-dom' import { withRouter } from 'react-router-dom'
import { compose, withState, withHandlers, withContext } from 'recompose' import { compose, withState, withHandlers } from 'recompose'
import { newestFirst, selectCurrentUser } from 'xpub-selectors' import { newestFirst, selectCurrentUser } from 'xpub-selectors'
import { createDraftSubmission } from 'pubsweet-component-wizard/src/redux/conversion' import { createDraftSubmission } from 'pubsweet-component-wizard/src/redux/conversion'
...@@ -19,12 +18,8 @@ export default compose( ...@@ -19,12 +18,8 @@ export default compose(
actions.getUsers(), actions.getUsers(),
]), ]),
withState('listView', 'changeView', true), withState('listView', 'changeView', true),
withState('abstractModal', 'setAbstractModal', null),
withHandlers({ withHandlers({
changeViewMode: ({ changeView }) => () => changeView(listView => !listView), changeViewMode: ({ changeView }) => () => changeView(listView => !listView),
setModal: ({ setAbstractModal }) => (metadata = null) => () => {
setAbstractModal(metadata)
},
}), }),
connect( connect(
state => { state => {
...@@ -91,14 +86,4 @@ export default compose( ...@@ -91,14 +86,4 @@ export default compose(
}, },
}, },
}), }),
withContext(
{
abstractModal: PropTypes.object,
setModal: PropTypes.func,
},
({ abstractModal, setModal }) => ({
abstractModal,
setModal,
}),
),
)(Dashboard) )(Dashboard)
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