From 0b4a8215e3e3e3662ebdae72d892f40b2f24d078 Mon Sep 17 00:00:00 2001 From: sballesteros Date: Fri, 11 Oct 2019 16:11:56 +0200 Subject: [PATCH] poor man redux --- src/components/home.js | 13 +++--- src/components/new-preprint.js | 80 ++++++++++++++------------------- src/components/shell-content.js | 5 ++- src/hooks/api-hooks.js | 28 +++++++++++- src/stores/preprint-stores.js | 4 +- src/utils/ids.js | 27 +++++++++++ 6 files changed, 100 insertions(+), 57 deletions(-) diff --git a/src/components/home.js b/src/components/home.js index ba91ff9..3502e79 100644 --- a/src/components/home.js +++ b/src/components/home.js @@ -77,11 +77,14 @@ export default function Home() { console.log(action); history.push('/'); }} - onViewInContext={({ identifier, preprint, tab }) => { - history.push(`/${unprefix(identifier)}`, { - preprint, - tab - }); + onViewInContext={({ preprint, tab }) => { + history.push( + `/${unprefix(preprint.doi || preprint.arXivId)}`, + { + preprint, + tab + } + ); }} /> diff --git a/src/components/new-preprint.js b/src/components/new-preprint.js index 3f53aa2..9e9e545 100644 --- a/src/components/new-preprint.js +++ b/src/components/new-preprint.js @@ -5,6 +5,7 @@ import identifiersArxiv from 'identifiers-arxiv'; import doiRegex from 'doi-regex'; import { format } from 'date-fns'; import Value from './value'; +import { createPreprintIdentifierCurie } from '../utils/ids'; import { getId, arrayify, unprefix } from '../utils/jsonld'; import { usePostAction, usePreprint } from '../hooks/api-hooks'; import RapidFormFragment from './rapid-form-fragment'; @@ -45,6 +46,8 @@ export default function NewPreprint({ : 'NEW_PREPRINT' ); + if (!preprint) return null; + return (
{step === 'NEW_PREPRINT' ? ( @@ -61,7 +64,6 @@ export default function NewPreprint({ onCancel={e => { setStep('NEW_PREPRINT'); }} - identifier={identifier} preprint={preprint} onReviewed={onReviewed} onViewInContext={onViewInContext} @@ -71,7 +73,6 @@ export default function NewPreprint({ onCancel={e => { setStep('NEW_PREPRINT'); }} - identifier={identifier} preprint={preprint} onRequested={onRequested} onViewInContext={onViewInContext} @@ -159,43 +160,43 @@ function StepPreprint({ value={value} /> {/* + htmlFor="step-preprint-input" + className="step-preprint__input-label step-preprint__input-label--large" + > + Enter a DOI or an arXiv + ID + - { + { const value = e.target.value; const [arxivId] = identifiersArxiv.extract(value); let nextIdentifier; if (arxivId) { - nextIdentifier = `arXiv:${arxivId}`; + nextIdentifier = `arXiv:${arxivId}`; } else { - const doiMatch = value.match(doiRegex()); - const doi = doiMatch && doiMatch[0]; - if (doi) { - nextIdentifier = `doi:${doi}`; - } else { - nextIdentifier = ''; - } + const doiMatch = value.match(doiRegex()); + const doi = doiMatch && doiMatch[0]; + if (doi) { + nextIdentifier = `doi:${doi}`; + } else { + nextIdentifier = ''; + } } if (nextIdentifier !== identifier) { - onIdentifier(nextIdentifier); + onIdentifier(nextIdentifier); } setValue(value); - }} - value={value} - /> */} + }} + value={value} + /> */}
{preprint ? ( @@ -250,13 +251,7 @@ StepPreprint.propTypes = { resolvePreprintStatus: PropTypes.object.isRequired }; -function StepReview({ - identifier, - preprint, - onViewInContext, - onCancel, - onReviewed -}) { +function StepReview({ preprint, onViewInContext, onCancel, onReviewed }) { const [user] = useUser(); const [post, postData] = usePostAction(); const [answerMap, setAnswerMap] = useState({}); // TODO read from local storage ? @@ -299,7 +294,7 @@ function StepReview({ '@type': 'RapidPREreviewAction', actionStatus: 'CompletedActionStatus', agent: getId(arrayify(user.hasRole)[0]), - object: identifier, + object: createPreprintIdentifierCurie(preprint), resultReview: { '@type': 'RapidPREreview', reviewAnswer: getReviewAnswers(answerMap) @@ -315,7 +310,6 @@ function StepReview({