From eb31c92ee3120ba9a5c32070fc4097523e4d0c15 Mon Sep 17 00:00:00 2001 From: leonardosfl Date: Wed, 5 Aug 2020 00:35:16 -0300 Subject: [PATCH 1/3] Show login required modal on dashboard Fix #158 --- src/components/dashboard.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/components/dashboard.js b/src/components/dashboard.js index 48afc7b..cd12d5b 100644 --- a/src/components/dashboard.js +++ b/src/components/dashboard.js @@ -27,6 +27,7 @@ import AddButton from './add-button'; import Banner from "./banner.js"; import Button from './button'; +import LoginRequiredModal from './login-required-modal'; import Checkbox from './checkbox'; import SortOptions from './sort-options'; import HeaderBar from './header-bar'; @@ -167,6 +168,14 @@ export default function Dashboard() { setShowLeftPanel(!showLeftPanel); }} /> + {loginModalOpenNext && ( + { + setLoginModalOpenNext(null); + }} + /> + )}
From c4970a014efb545cf789f09203a0880bc1bf67fe Mon Sep 17 00:00:00 2001 From: leonardosfl Date: Fri, 7 Aug 2020 10:19:18 -0300 Subject: [PATCH 2/3] Delete only the identifier param instead of everything. --- src/components/new-preprint.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/new-preprint.js b/src/components/new-preprint.js index 0ab7e4d..217d87e 100644 --- a/src/components/new-preprint.js +++ b/src/components/new-preprint.js @@ -214,7 +214,8 @@ function StepPreprint({ if (location.search) { const qs = new URLSearchParams(location.search); if (qs.get('identifier')) { - history.replace('/new'); + qs.delete('identifier'); + history.replace({ pathname: location.pathname, search: qs.toString() }); } } From 79ae729500ac7c01be4e4ade8c6b664bc63ecbad Mon Sep 17 00:00:00 2001 From: leonardosfl Date: Fri, 7 Aug 2020 10:29:12 -0300 Subject: [PATCH 3/3] Allow to add new preprints from dashboard. --- src/components/app.js | 2 +- src/components/dashboard.js | 126 ++++++++++++++++++++++++++------ src/components/preprint-card.js | 5 +- 3 files changed, 106 insertions(+), 27 deletions(-) diff --git a/src/components/app.js b/src/components/app.js index 3ef86e2..ea6e34a 100644 --- a/src/components/app.js +++ b/src/components/app.js @@ -58,7 +58,7 @@ export default function App({ user }) { - + diff --git a/src/components/dashboard.js b/src/components/dashboard.js index ab24e62..44c3fdf 100644 --- a/src/components/dashboard.js +++ b/src/components/dashboard.js @@ -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 @@ -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() { @@ -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, @@ -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]); @@ -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] @@ -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] @@ -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] @@ -177,6 +199,45 @@ export default function Dashboard() { }} /> )} + + { + history.push({ pathname: '/dashboard', search: location.search }); + }} + > + + Rapid PREreview • Add entry + + { + 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 + } + ); + }} + /> + +
@@ -333,6 +394,23 @@ export default function Dashboard() {
No more preprints.
) : (
    + {newPreprints.length > 0 && ( + newPreprints.map(preprint => ( +
  • + +
  • + )) + )} {preprints.rows.length ? preprints.rows.map(row => (
  • { 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'} />
diff --git a/src/components/preprint-card.js b/src/components/preprint-card.js index ca0f0b7..703b241 100644 --- a/src/components/preprint-card.js +++ b/src/components/preprint-card.js @@ -39,7 +39,8 @@ export default function PreprintCard({ onNew, sortOption, hoveredSortOption, - isNew = false + isNew = false, + isDashboardCard = false, }) { const [isOpened, setIsOpened] = useState(false); @@ -93,7 +94,7 @@ export default function PreprintCard({ return (