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

Commit

Permalink
Merge with master
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaituVR committed Aug 26, 2020
2 parents c39de50 + 25bc87a commit 45d5617
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 81 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
4 changes: 2 additions & 2 deletions src/components/banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export default function Banner() {
return (
<React.Fragment>
<div className='announcement'>
<p>Click <a className='announcement-link' href={`${process.env.API_URL}/dashboard`}>here</a> to find preprints on COVID-19 with reviews or requests for reviews.</p>
<p>Click <a className='announcement-link' href="https://oaspa.org/covid-19-publishers-open-letter-of-intent-rapid-review/?highlight=covid-19" target="_blank">here</a> to read OASPA's open letter of intent to ensure rapid review of key work related to COVID-19.</p>
<p>Get involved with rapidly reviewing COVID-19 preprints and then view our <a className='announcement-link' href={`${process.env.API_URL}/dashboard`}>COVID-19 Dashboard</a> of review activities and recommendations.</p>
<p>Read about the <a className='announcement-link' href="https://oaspa.org/covid-19-publishers-open-letter-of-intent-rapid-review/?highlight=covid-19" target="_blank">OASPA’s initiative</a> to ensure rapid review of key COVID-19 work.</p>
</div>
</React.Fragment>
)
Expand Down
135 changes: 111 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 @@ -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';
Expand All @@ -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() {
Expand All @@ -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,
Expand All @@ -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]);

Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -168,6 +191,53 @@ export default function Dashboard() {
setShowLeftPanel(!showLeftPanel);
}}
/>
{loginModalOpenNext && (
<LoginRequiredModal
next={loginModalOpenNext}
onClose={() => {
setLoginModalOpenNext(null);
}}
/>
)}
<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 @@ -324,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 @@ -381,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
2 changes: 2 additions & 0 deletions src/components/extension-fallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default function ExtensionFallback() {
<Suspense fallback={<SuspenseLoading>Loading PDF</SuspenseLoading>}>
<PdfViewer
docId={preprintId}
pdfUrl={pdfUrl}
loading={<SuspenseLoading>Loading PDF</SuspenseLoading>}
/>
</Suspense>
Expand All @@ -80,6 +81,7 @@ export default function ExtensionFallback() {
<Suspense fallback={<SuspenseLoading>Loading PDF</SuspenseLoading>}>
<PdfViewer
docId={identifier}
pdfUrl={pdfUrl}
loading={<SuspenseLoading>Loading PDF</SuspenseLoading>}
/>
</Suspense>
Expand Down
30 changes: 0 additions & 30 deletions src/components/header-bar.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,6 @@
}
}

& .header-bar__give-feedback {
position: fixed;
font: var(--ui-basic-font);
line-height: 1.25em;
background-color: var(--prereview-red);
color: white;
text-shadow: 0px 0px 10px #eb0000; /* improve contrast for accessability */
right: 0px;
bottom: var(--xlgrd);
width: 56px;
padding: var(--xsgrd);
padding-right: var(--mgrd);
border-top-left-radius: var(--xsgrd);
border-bottom-left-radius: var(--xsgrd);
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
@media (--narrow-screen) {
bottom: calc(var(--xlgrd) + 50px);
}
@media (--mobile) {
bottom: var(--xlgrd);
}
& :any-link {
color: white;
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
}

/* the hamburder is only visible on narrow screens */
& .header-bar__menu-button {
display: none;
Expand Down
10 changes: 0 additions & 10 deletions src/components/header-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,6 @@ export default function HeaderBar({ onClickMenuButton, closeGap }) {
)}
</span>
</div>
{/* TODO link to feedback form */}
<div className="header-bar__give-feedback">
<a
href="https://docs.google.com/forms/d/1ao2f12U96lKlbVJifrWHEhPmCAB3ZHD16s-I7WmJyU4/viewform?edit_requested=true"
target="_blank"
rel="noopener noreferrer"
>
Give Feedback
</a>
</div>
</div>
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/new-preprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() });
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/pdf-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const CSS_MAX_WIDTH = 900; // keep in sync with CSS
* This implement an infinite scroll mechanism so that we never load more than a
* few pages at the time
*/
export default function PdfViewer({ docId, loading }) {
export default function PdfViewer({ docId, pdfUrl, loading }) {
const containerEl = useRef(null);
const getWidth = () => {
const el = containerEl.current;
Expand Down Expand Up @@ -79,7 +79,7 @@ export default function PdfViewer({ docId, loading }) {
<Document
file={`${process.env.API_URL}/api/pdf?preprintId=${encodeURIComponent(
docId
)}`}
)}${pdfUrl ? `&pdfUrl=${encodeURIComponent(pdfUrl)}` : ''}`}
loading={loading}
onLoadSuccess={async pdf => {
let dims = [];
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
23 changes: 14 additions & 9 deletions src/routes/api-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,16 +375,21 @@ router.get(
* due to cross origin restriction we need to proxy the PDF
*/
router.get('/pdf', async (req, res, next) => {
let pdfUrl;
const preprintId = req.query.preprintId;
try {
const body = await req.db.get(`preprint:${preprintId}`);
pdfUrl = getPdfUrl(body);
if (!pdfUrl) {
return next(createError(500, `Could not determine PDF from prereview: ${JSON.stringify(body)}`));
let { preprintId, pdfUrl } = req.query;

// If we already have the pdfUrl, there's no need to look in the database.
// The pdfUrl is present in the case where the preprint is not in the database yet,
// but we were able to resolve it.
if (!pdfUrl) {
try {
const body = await req.db.get(`preprint:${preprintId}`);
pdfUrl = getPdfUrl(body);
if (!pdfUrl) {
return next(createError(500, `Could not determine PDF from prereview: ${JSON.stringify(body)}`));
}
} catch (err) {
return next(createError(500, `Prereview query failed: ${preprintId} ${JSON.stringify(err)}`));
}
} catch (err) {
return next(createError(500, `Prereview query failed: ${preprintId} ${JSON.stringify(err)}`));
}

if (!pdfUrl) {
Expand Down

0 comments on commit 45d5617

Please sign in to comment.