Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Commit

Permalink
Allow to add new preprints from dashboard.
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardosfl committed Aug 7, 2020
1 parent c4970a0 commit 79ae729
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function App({ user }) {
</ToCPage>
</Route>

<Route exact={true} path="/dashboard">
<Route exact={true} path="/dashboard/:new(new)?">
<Dashboard />
</Route>

Expand Down
126 changes: 102 additions & 24 deletions src/components/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import Org from './org';

// hooks
import { usePreprintSearchResults } from '../hooks/api-hooks';
import { useNewPreprints } from '../hooks/ui-hooks';

// utils
import { checkIfIsModerated } from '../utils/actions';
import { getUsersRank, isYes } from '../utils/stats';
import { createPreprintQs, apifyPreprintQs } from '../utils/search';
import { getId } from '../utils/jsonld'
import { getId, unprefix } from '../utils/jsonld'


// contexts
Expand All @@ -36,6 +37,9 @@ import SearchBar from './search-bar';
import XLink from './xlink';
import RecentActivity from './recent-activity'
import ActiveUser from './active-user'
import PrivateRoute from './private-route';
import NewPreprint from './new-preprint';
import Modal from './modal';


export default function Dashboard() {
Expand All @@ -44,6 +48,7 @@ export default function Dashboard() {
const [user] = useUser();

const [loginModalOpenNext, setLoginModalOpenNext] = useState(null);
const [newPreprints, setNewPreprints] = useNewPreprints();

const apiQs = apifyPreprintQs(
location.search,
Expand All @@ -55,7 +60,7 @@ export default function Dashboard() {

useEffect(() => {
if (location.search === "") {
history.replace({ search: createPreprintQs({ text: covidTerms }, location.search) });
history.replace({ search: createPreprintQs({ text: covidTerms }, location.search), state: location.state });
}
}, [apiQs]);

Expand Down Expand Up @@ -112,15 +117,21 @@ export default function Dashboard() {
const handleNewRequest = useCallback(
preprint => {
if (user) {
history.push('/new', {
preprint: omit(preprint, ['potentialAction']),
tab: 'request',
isSingleStep: true
history.push({
pathname: '/dashboard/new',
search: history.location.search,
state: {
preprint: omit(preprint, ['potentialAction']),
tab: 'request',
isSingleStep: true
}
});
} else {
setLoginModalOpenNext(
`/new?identifier=${preprint.doi || preprint.arXivId}&tab=request`
);
const search = new URLSearchParams(location.search);
search.set('identifier', preprint.doi || preprint.arXivId);
search.set('tab', 'request');

setLoginModalOpenNext(`/dashboard/new?${search}`);
}
},
[user, history]
Expand All @@ -129,13 +140,18 @@ export default function Dashboard() {
const handleNew = useCallback(
preprint => {
if (user) {
history.push('/new', {
preprint: omit(preprint, ['potentialAction'])
history.push({
pathname: '/dashboard/new',
search: history.location.search,
state: {
preprint: omit(preprint, ['potentialAction'])
}
});
} else {
setLoginModalOpenNext(
`/new?identifier=${preprint.doi || preprint.arXivId}`
);
const search = new URLSearchParams(location.search);
search.set('identifier', preprint.doi || preprint.arXivId);

setLoginModalOpenNext(`/dashboard/new?${search}`);
}
},
[user, history]
Expand All @@ -144,15 +160,21 @@ export default function Dashboard() {
const handleNewReview = useCallback(
preprint => {
if (user) {
history.push('/new', {
preprint: omit(preprint, ['potentialAction']),
tab: 'review',
isSingleStep: true
history.push({
pathname: '/dashboard/new',
search: history.location.search,
state: {
preprint: omit(preprint, ['potentialAction']),
tab: 'review',
isSingleStep: true
}
});
} else {
setLoginModalOpenNext(
`/new?identifier=${preprint.doi || preprint.arXivId}&tab=review`
);
const search = new URLSearchParams(location.search);
search.set('identifier', preprint.doi || preprint.arXivId);
search.set('tab', 'review');

setLoginModalOpenNext(`/dashboard/new?${search}`);
}
},
[user, history]
Expand All @@ -177,6 +199,45 @@ export default function Dashboard() {
}}
/>
)}
<PrivateRoute path="/dashboard/new" exact={true}>
<Modal
showCloseButton={true}
title="Add Entry"
onClose={() => {
history.push({ pathname: '/dashboard', search: location.search });
}}
>
<Helmet>
<title>Rapid PREreview • Add entry</title>
</Helmet>
<NewPreprint
user={user}
onCancel={() => {
history.push({ pathname: '/dashboard', search: location.search });
}}
onSuccess={(preprint, isNew) => {
history.push({ pathname: '/dashboard', search: location.search });
if (
isNew &&
!newPreprints.some(
_preprint => getId(_preprint) === getId(preprint)
)
) {
setNewPreprints(newPreprints.concat(preprint));
}
}}
onViewInContext={({ preprint, tab }, isNew) => {
history.push(
`/${unprefix(preprint.doi || preprint.arXivId)}`,
{
preprint: omit(preprint, ['potentialAction']),
tab
}
);
}}
/>
</Modal>
</PrivateRoute>
<article className="toc-page__main">
<div className="toc-page__body">
<section className="dashboard home__main">
Expand Down Expand Up @@ -333,6 +394,23 @@ export default function Dashboard() {
<div>No more preprints.</div>
) : (
<ul className="dashboard__preprint-list">
{newPreprints.length > 0 && (
newPreprints.map(preprint => (
<li key={getId(preprint)} className="dashboard__preprint-list__item">
<PreprintCard
isNew={true}
isDashboardCard={true}
user={user}
preprint={preprint}
onNewRequest={handleNewRequest}
onNew={handleNew}
onNewReview={handleNewReview}
hoveredSortOption={hoveredSortOption}
sortOption={params.get('sort') || 'score'}
/>
</li>
))
)}
{preprints.rows.length ? preprints.rows.map(row => (
<li key={row.id} className="dashboard__preprint-list__item">
<PreprintCard
Expand Down Expand Up @@ -390,12 +468,12 @@ export default function Dashboard() {
<AddButton
onClick={e => {
if (user) {
history.push('/new');
history.push({ pathname: '/dashboard/new', search: location.search });
} else {
setLoginModalOpenNext('/new');
setLoginModalOpenNext(`/dashboard/new?${location.search}`);
}
}}
disabled={location.pathname === '/new'}
disabled={location.pathname === '/dashboard/new'}
/>
</div>
<div className="dashboard__activity">
Expand Down
5 changes: 3 additions & 2 deletions src/components/preprint-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export default function PreprintCard({
onNew,
sortOption,
hoveredSortOption,
isNew = false
isNew = false,
isDashboardCard = false,
}) {
const [isOpened, setIsOpened] = useState(false);

Expand Down Expand Up @@ -93,7 +94,7 @@ export default function PreprintCard({
return (
<Fragment>
<div
className={classNames('preprint-card', { 'preprint-card--new': isNew })}
className={classNames('preprint-card', { 'preprint-card--new': isNew && !isDashboardCard })}
>
<div className="preprint-card__contents">
<div className="preprint-card__header">
Expand Down

0 comments on commit 79ae729

Please sign in to comment.