From e4f7ae95fdb6572652fa1288fe5892f10f1a8c72 Mon Sep 17 00:00:00 2001 From: Alexandru Munteanu <alexandru.munteanu@thinslices.com> Date: Tue, 6 Feb 2018 11:48:13 +0200 Subject: [PATCH] Remove authors from redux --- .../component-wizard/src/components/WizardStep.js | 2 -- .../src/components/AuthorList/AuthorAdder.js | 6 ++++-- .../src/components/AuthorList/AuthorList.js | 3 +++ .../src/components/SortableList/SortableList.js | 2 +- packages/components-faraday/src/redux/authors.js | 15 ++++----------- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/packages/component-wizard/src/components/WizardStep.js b/packages/component-wizard/src/components/WizardStep.js index 17b35ccd5..4c369eeed 100644 --- a/packages/component-wizard/src/components/WizardStep.js +++ b/packages/component-wizard/src/components/WizardStep.js @@ -2,7 +2,6 @@ import React from 'react' import { get } from 'lodash' import classnames from 'classnames' import { ValidatedField, Button } from '@pubsweet/ui' -import { AuthorList } from 'pubsweet-components-faraday/src/components' import classes from './WizardStep.local.scss' import AutosaveIndicator from './AutosaveIndicator' @@ -67,7 +66,6 @@ export default ({ }, )} - <AuthorList /> <div className={classnames(classes.buttons)}> <Button onClick={isFirst ? () => history.push('/') : prevStep}> {isFirst diff --git a/packages/components-faraday/src/components/AuthorList/AuthorAdder.js b/packages/components-faraday/src/components/AuthorList/AuthorAdder.js index 5e9587c40..30a532678 100644 --- a/packages/components-faraday/src/components/AuthorList/AuthorAdder.js +++ b/packages/components-faraday/src/components/AuthorList/AuthorAdder.js @@ -83,7 +83,7 @@ export default compose( onSubmit: ( values, dispatch, - { authors, addAuthor, setEditMode, reset, match }, + { authors, addAuthor, setEditMode, setFormAuthors, reset, match }, ) => { const collectionId = get(match, 'params.project') const fragmentId = get(match, 'params.version') @@ -96,7 +96,9 @@ export default compose( }, collectionId, fragmentId, - ).then(() => { + ).then(author => { + const newAuthors = [...authors, author] + setFormAuthors(newAuthors) reset() setEditMode(false)() }) diff --git a/packages/components-faraday/src/components/AuthorList/AuthorList.js b/packages/components-faraday/src/components/AuthorList/AuthorList.js index 2b1db5af8..06f4f7bb2 100644 --- a/packages/components-faraday/src/components/AuthorList/AuthorList.js +++ b/packages/components-faraday/src/components/AuthorList/AuthorList.js @@ -38,6 +38,7 @@ const Authors = ({ editMode, setEditMode, editedAuthor, + setFormAuthors, ...rest }) => ( <div> @@ -48,12 +49,14 @@ const Authors = ({ editMode={editMode} match={match} setEditMode={setEditMode} + setFormAuthors={setFormAuthors} /> {editedAuthor > -1 ? ( <StaticList authors={authors} editComponent={AuthorEditor} editIndex={editedAuthor} + setFormAuthors={setFormAuthors} {...rest} /> ) : ( diff --git a/packages/components-faraday/src/components/SortableList/SortableList.js b/packages/components-faraday/src/components/SortableList/SortableList.js index b19cc9d88..8b8baa482 100644 --- a/packages/components-faraday/src/components/SortableList/SortableList.js +++ b/packages/components-faraday/src/components/SortableList/SortableList.js @@ -104,7 +104,7 @@ const SortableList = ({ <DecoratedItem dragHandle={dragHandle} index={i} - key={item.name || Math.random()} + key={item.id} listItem={listItem} moveItem={moveItem} {...item} diff --git a/packages/components-faraday/src/redux/authors.js b/packages/components-faraday/src/redux/authors.js index 7f5500564..5d78978e7 100644 --- a/packages/components-faraday/src/redux/authors.js +++ b/packages/components-faraday/src/redux/authors.js @@ -1,4 +1,3 @@ -import { get } from 'lodash' import * as api from 'pubsweet-client/src/helpers/api' // constants @@ -6,16 +5,10 @@ export const SET_AUTHORS = 'authors/SET_AUTHORS' // actions export const addAuthor = (author, collectionId, fragmentId) => dispatch => - api - .create( - `/collections/${collectionId}/fragments/${fragmentId}/authors`, - author, - ) - .then(r => console.log('esposa', r)) -// .then(() => -// dispatch(actions.getFragment({ id: collectionId }, { id: fragmentId })), -// ) -// .then(({ fragment: { authors, id } }) => dispatch(setAuthors(authors, id))) + api.create( + `/collections/${collectionId}/fragments/${fragmentId}/authors`, + author, + ) // selectors -- GitLab