diff --git a/src/components/dashboard.js b/src/components/dashboard.js
index 2f08c95..08e720e 100644
--- a/src/components/dashboard.js
+++ b/src/components/dashboard.js
@@ -58,95 +58,9 @@ export default function Dashboard() {
}, [apiQs]);
const [preprints, fetchResultsProgress] = usePreprintSearchResults(apiQs);
-
+
const [hoveredSortOption, setHoveredSortOption] = useState(null);
- const [filters, setFilters] = useState({
- hasCode: false,
- hasData: false,
- recToOthers: false,
- recForPeerReview: false
- })
-
- const handleFilterChange = (e) => {
- setFilters({
- ...filters,
- [e.target.name]: !filters[e.target.name]
- })
- }
-
- // calculating tags, following the logic in utils/stats
- preprints.rows.length ? preprints.rows.map(preprint => {
- let codeCount = 0
- let dataCount = 0
- let othersCount = 0
- let peerCount = 0
- let reviewCount = 0
-
- preprint.doc.potentialAction.forEach(action => {
- if (!checkIfIsModerated(action) && action.resultReview && action.resultReview.reviewAnswer) {
- reviewCount += 1
-
- const answers = action.resultReview.reviewAnswer;
-
- for (let i = 0; i < answers.length; i++) {
- const answer = answers[i];
- if (answer.parentItem) {
- const questionId = getId(answer.parentItem);
- if (questionId === 'question:ynAvailableCode' && isYes(answer)) {
- // Is the code used in the manuscript available?
- codeCount += 1
- }
- if (questionId === 'question:ynPeerReview' && isYes(answer)) {
- // Do you recommend this manuscript for peer review?
- peerCount += 1
- }
- if (questionId === 'question:ynAvailableData' && isYes(answer)) {
- // Are the data used in the manuscript available?
- dataCount += 1
- }
- if (questionId === 'question:ynRecommend' && isYes(answer)) {
- // Would you recommend this manuscript to others?
- othersCount += 1
- }
- }
- }
- }
- })
-
- // majority rule calculation
- const threshold = Math.ceil(reviewCount / 2)
-
- preprint.doc.hasCode = codeCount > 0 && codeCount >= threshold;
- preprint.doc.hasData = dataCount > 0 && dataCount >= threshold;
- preprint.doc.recToOthers = othersCount > 0 && othersCount >= threshold;
- preprint.doc.recForPeerReview = peerCount > 0 && peerCount >= threshold;
- }) : null
-
- // filtering preprints to render
- const filteredPreprints = () => {
-
- return preprints.rows.filter(preprint => {
- if (filters.hasCode && !preprint.doc.hasCode) {
- return false
- }
- if (filters.hasData && !preprint.doc.hasData) {
- return false
- }
- if (filters.recToOthers && !preprint.doc.recToOthers) {
- return false
- }
- if (filters.recForPeerReview && !preprint.doc.recForPeerReview) {
- return false
- }
- return true
- })
- }
-
- useEffect(() => {
- filteredPreprints()
- }, [filters])
-
/**
* builds an array where each item of the array is an object with an 'actions' key,
* the value to which are all of actions from each preprint
@@ -265,29 +179,53 @@ export default function Dashboard() {
Recommended to others{' '}
}
- // disabled={!(counts.hasData || {}).true}
- checked={filters['recToOthers']}
- onChange={e => handleFilterChange(e)}
+ checked={params.get('others') === 'true'}
+ onChange={e => {
+ const search = createPreprintQs(
+ {
+ hasOthersRec: e.target.checked || null
+ },
+ location.search
+ );
+
+ history.push({
+ pathname: location.pathname,
+ search,
+ state: { prevSearch: location.search }
+ });
+ }}
/>
Recommended for peer review{' '}
}
- // disabled={!(counts.hasData || {}).true}
- checked={filters['recForPeerReview']}
- onChange={e => handleFilterChange(e)}
+ checked={params.get('peer') === 'true'}
+ onChange={e => {
+ const search = createPreprintQs(
+ {
+ hasPeerRec: e.target.checked || null
+ },
+ location.search
+ );
+
+ history.push({
+ pathname: location.pathname,
+ search,
+ state: { prevSearch: location.search }
+ });
+ }}
/>
@@ -296,12 +234,24 @@ export default function Dashboard() {
name="hasData"
label={
- With reported data{' '}
+ With Reported Data{' '}
}
- // disabled={!(counts.hasData || {}).true}
- checked={filters['hasData']}
- onChange={e => handleFilterChange(e)}
+ checked={params.get('data') === 'true'}
+ onChange={e => {
+ const search = createPreprintQs(
+ {
+ hasData: e.target.checked || null
+ },
+ location.search
+ );
+
+ history.push({
+ pathname: location.pathname,
+ search,
+ state: { prevSearch: location.search }
+ });
+ }}
/>
@@ -310,12 +260,24 @@ export default function Dashboard() {
name="hasCode"
label={
- With reported code{' '}
+ With Reported Code{' '}
}
- // disabled={!(counts.hasCode || {}).true}
- checked={filters['hasCode']}
- onChange={e=>handleFilterChange(e)}
+ checked={params.get('code') === 'true'}
+ onChange={e => {
+ const search = createPreprintQs(
+ {
+ hasCode: e.target.checked || null
+ },
+ location.search
+ );
+
+ history.push({
+ pathname: location.pathname,
+ search,
+ state: { prevSearch: location.search }
+ });
+ }}
/>
@@ -357,7 +319,7 @@ export default function Dashboard() {
No more preprints.
) : (
- {filteredPreprints() ? filteredPreprints().map(row => (
+ {preprints.rows.length ? preprints.rows.map(row => (
-
= threshold;
+ index('hasOthersRec', hasOthersRec ? 'true' : 'false', {
+ facet: true
+ });
+
+ // has recommendations for peer review
+ var reviewsWithPeers = reviewActions.filter(function (action) {
+ if (action.resultReview && action.resultReview.reviewAnswer) {
+ var answers = action.resultReview.reviewAnswer;
+
+ for (var i = 0; i < answers.length; i++) {
+ var answer = answers[i];
+ if (answer.parentItem) {
+ var questionId =
+ answer.parentItem['@id'] || answer.parentItem;
+ if (questionId === 'question:ynPeerReview') {
+ return (answer.text || '').toLowerCase().trim() === 'yes';
+ }
+ }
+ }
+ }
+ return false;
+ });
+
+ var hasPeerRec =
+ reviewsWithPeers.length && reviewsWithPeers.length >= threshold;
+ index('hasPeerRec', hasPeerRec ? 'true' : 'false', {
+ facet: true
+ });
+
// subjectName
var subjectCountMap = {};
reviewActions.forEach(function(action) {
diff --git a/src/utils/search.js b/src/utils/search.js
index efff957..448d81d 100644
--- a/src/utils/search.js
+++ b/src/utils/search.js
@@ -261,12 +261,10 @@ export function apifyPreprintQs(uiQs = '', bookmark) {
api.set(
'counts',
JSON.stringify([
- // 'hasPeerRec',
- // 'hasOthersRec',
+ 'hasPeerRec',
+ 'hasOthersRec',
'hasData',
'hasCode',
- // 'hasPeerRec',
- // 'hasOthersRec',
'hasReviews',
'hasRequests',
'subjectName'