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 5ee97b3..990d5ff 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 @@ -27,6 +28,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'; @@ -35,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() { @@ -43,6 +48,7 @@ export default function Dashboard() { const [user] = useUser(); const [loginModalOpenNext, setLoginModalOpenNext] = useState(null); + const [newPreprints, setNewPreprints] = useNewPreprints(); const apiQs = apifyPreprintQs( location.search, @@ -54,7 +60,7 @@ export default function Dashboard() { useEffect(() => { if (!params.get('q')) { - history.replace({ search: createPreprintQs({ text: covidTerms }, location.search) }); + history.replace({ search: createPreprintQs({ text: covidTerms }, location.search), state: location.state }); } }, [apiQs]); @@ -111,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] @@ -128,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] @@ -143,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] @@ -168,6 +191,53 @@ export default function Dashboard() { setShowLeftPanel(!showLeftPanel); }} /> + {loginModalOpenNext && ( + { + setLoginModalOpenNext(null); + }} + /> + )} + + { + 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 + } + ); + }} + /> + +
@@ -324,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/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() }); } } 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 (