From b2ebaa1fb79233c040b6d9deb92bac47e7c3425a Mon Sep 17 00:00:00 2001 From: Suhyma Date: Fri, 31 Mar 2023 15:04:05 -0400 Subject: [PATCH 1/9] Adding titles --- src/dashboard/category-results-screen.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/dashboard/category-results-screen.js b/src/dashboard/category-results-screen.js index f86ab6a..068dd87 100644 --- a/src/dashboard/category-results-screen.js +++ b/src/dashboard/category-results-screen.js @@ -28,6 +28,21 @@ export default function CategoryResultsScreen ({ store }) { h('div', { class: 'category-results-description' }, selectedCategory.description) ]) ]), - h('div', { class: 'papers' }, selectedPapers.map(paper => h(Paper, { paper }))) + h('div', { class: 'papers-today' }, [ + h('h2', { class: 'papers-today-title' }, 'New papers today'), + h('div', { class: 'papers' }, selectedPapers.map(paper => h(Paper, { paper }))) + ]), + h('div', { class: 'papers-last-few-days' }, [ + h('h2', { class: 'papers-last-few-days-title' }, 'Papers in the last few days'), + h('div', { class: 'papers' }, selectedPapers.map(paper => h(Paper, { paper }))) + ]), + h('div', { class: 'papers-last-week' }, [ + h('h2', { class: 'papers-last-week-title' }, 'Papers in the last week'), + h('div', { class: 'papers' }, selectedPapers.map(paper => h(Paper, { paper }))) + ]), + h('div', { class: 'papers-this-month' }, [ + h('h2', { class: 'papers-this-month-title' }, 'Papers this month'), + h('div', { class: 'papers' }, selectedPapers.map(paper => h(Paper, { paper }))) + ]) ]); } From a840a029604f5ee5993758b68ee11d781c0d442a Mon Sep 17 00:00:00 2001 From: Suhyma Date: Mon, 3 Apr 2023 12:28:11 -0400 Subject: [PATCH 2/9] Add initial findRelativeDate function --- src/dashboard/category-results-screen.js | 46 ++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/dashboard/category-results-screen.js b/src/dashboard/category-results-screen.js index 068dd87..4b46ab1 100644 --- a/src/dashboard/category-results-screen.js +++ b/src/dashboard/category-results-screen.js @@ -1,6 +1,7 @@ import { h } from 'preact'; import { Link } from 'preact-router/match'; import CategoryCard from './category-card.js'; +import { format, sub } from 'date-fns'; function Paper ({ paper }) { return h('div', { class: 'paper' }, [ @@ -15,6 +16,51 @@ function Paper ({ paper }) { ]); } +function findRelativeDate (papers, range) { + const now = new Date(); + const today = format(now, 'yyyy-MM-dd'); + const displayPapers = []; + + if (range === 'today') { + for (const paper of papers) { + const paperDate = paper.date.substring(0, 9); + if (paperDate === today) { + displayPapers.push(paper); + } + } + } else if (range === 'days') { // if between now & 3 days + const startOffset = { days: 3 }; + const start = format(sub(now, startOffset), 'yyyy-MM-dd'); + + for (const paper of papers) { + const paperDate = paper.date.substring(0, 9); + if (paperDate >= start && paperDate <= today) { + displayPapers.push(paper); + } + } + } else if (range === 'week') { + const startOffset = { weeks: 1 }; + const start = format(sub(now, startOffset), 'yyyy-MM-dd'); + + for (const paper of papers) { + const paperDate = paper.date.substring(0, 9); + if (paperDate >= start && paperDate <= today) { // between now & 7 days + displayPapers.push(paper); + } + } + } else { + const startOffset = { motnhs: 1 }; + const start = format(sub(now, startOffset), 'yyyy-MM-dd'); + + for (const paper of papers) { + const paperDate = paper.date.substring(0, 9); + if (paperDate >= start && paperDate <= today) { // past month + displayPapers.push(paper); + } + } + } +} + export default function CategoryResultsScreen ({ store }) { const { selectedPapers, selectedCategory } = store; From f4105d784a1b8a3ef846760efdfc2ef25efe1907 Mon Sep 17 00:00:00 2001 From: Suhyma Date: Mon, 3 Apr 2023 15:15:18 -0400 Subject: [PATCH 3/9] Changes to findRelativeDate function --- src/dashboard/category-results-screen.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/dashboard/category-results-screen.js b/src/dashboard/category-results-screen.js index 4b46ab1..529b8b4 100644 --- a/src/dashboard/category-results-screen.js +++ b/src/dashboard/category-results-screen.js @@ -34,27 +34,31 @@ function findRelativeDate (papers, range) { for (const paper of papers) { const paperDate = paper.date.substring(0, 9); - if (paperDate >= start && paperDate <= today) { + if (paperDate >= start && paperDate < today) { displayPapers.push(paper); } } } else if (range === 'week') { const startOffset = { weeks: 1 }; + const endOffset = { days: 3 }; const start = format(sub(now, startOffset), 'yyyy-MM-dd'); + const end = format(sub(now, endOffset), 'yyyy-MM-dd'); for (const paper of papers) { const paperDate = paper.date.substring(0, 9); - if (paperDate >= start && paperDate <= today) { // between now & 7 days + if (paperDate >= start && paperDate < end) { // between now & 7 days displayPapers.push(paper); } } } else { - const startOffset = { motnhs: 1 }; + const startOffset = { months: 1 }; + const endOffset = { weeks: 1 }; const start = format(sub(now, startOffset), 'yyyy-MM-dd'); + const end = format(sub(now, endOffset), 'yyyy-MM-dd'); for (const paper of papers) { const paperDate = paper.date.substring(0, 9); - if (paperDate >= start && paperDate <= today) { // past month + if (paperDate >= start && paperDate < end) { // past month displayPapers.push(paper); } } @@ -63,6 +67,10 @@ function findRelativeDate (papers, range) { export default function CategoryResultsScreen ({ store }) { const { selectedPapers, selectedCategory } = store; + const todayPapers = findRelativeDate(selectedPapers, 'today'); + const fewDaysPapers = findRelativeDate(selectedPapers, 'days'); + const weekPapers = findRelativeDate(selectedPapers, 'week'); + const monthPapers = findRelativeDate(selectedPapers, 'month'); return h('div', { class: 'category-results-screen' }, [ h(Link, { href: '/', class: 'category-results-reset link' }, '< Select a different topic'), // TODO: < should be a nice SVG icon From f61cfc638cb1a982a8f7ae213d7210d8ba1856a0 Mon Sep 17 00:00:00 2001 From: Suhyma Date: Tue, 4 Apr 2023 11:24:53 -0400 Subject: [PATCH 4/9] Implement sorting papers by relative date --- src/dashboard/categories.js | 4 +-- src/dashboard/category-results-screen.js | 31 ++++++++++++------------ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/dashboard/categories.js b/src/dashboard/categories.js index 5b9e902..5e239b7 100644 --- a/src/dashboard/categories.js +++ b/src/dashboard/categories.js @@ -6,10 +6,10 @@ const toDate = o => { }; const byDate = (a, b) => { return b.date - a.date; }; export const categories = data.map(({ id, name, description, img }) => ({ id, name, description, img })); -export const getPapers = ({ id, limit = 100 }) => { +export const getPapers = ({ id }) => { let papers = []; const category = data.find(cat => cat.id === id); - papers = category && category.papers.map(toDate).sort(byDate).slice(1, limit); + papers = category && category.papers.map(toDate).sort(byDate).slice(1); return papers; }; diff --git a/src/dashboard/category-results-screen.js b/src/dashboard/category-results-screen.js index 529b8b4..3021a72 100644 --- a/src/dashboard/category-results-screen.js +++ b/src/dashboard/category-results-screen.js @@ -23,30 +23,30 @@ function findRelativeDate (papers, range) { if (range === 'today') { for (const paper of papers) { - const paperDate = paper.date.substring(0, 9); - if (paperDate === today) { + const paperDate = format(paper.date, 'yyyy-MM-dd'); + if (paperDate >= today) { displayPapers.push(paper); } } - } else if (range === 'days') { // if between now & 3 days - const startOffset = { days: 3 }; + } else if (range === 'days') { // within the past 4 days + const startOffset = { days: 4 }; const start = format(sub(now, startOffset), 'yyyy-MM-dd'); for (const paper of papers) { - const paperDate = paper.date.substring(0, 9); + const paperDate = format(paper.date, 'yyyy-MM-dd'); if (paperDate >= start && paperDate < today) { displayPapers.push(paper); } } } else if (range === 'week') { const startOffset = { weeks: 1 }; - const endOffset = { days: 3 }; + const endOffset = { days: 4 }; const start = format(sub(now, startOffset), 'yyyy-MM-dd'); const end = format(sub(now, endOffset), 'yyyy-MM-dd'); for (const paper of papers) { - const paperDate = paper.date.substring(0, 9); - if (paperDate >= start && paperDate < end) { // between now & 7 days + const paperDate = format(paper.date, 'yyyy-MM-dd'); + if (paperDate >= start && paperDate < end) { // within the past week displayPapers.push(paper); } } @@ -57,12 +57,13 @@ function findRelativeDate (papers, range) { const end = format(sub(now, endOffset), 'yyyy-MM-dd'); for (const paper of papers) { - const paperDate = paper.date.substring(0, 9); - if (paperDate >= start && paperDate < end) { // past month + const paperDate = format(paper.date, 'yyyy-MM-dd'); + if (paperDate >= start && paperDate < end) { // everything else within the past month displayPapers.push(paper); } } } + return displayPapers; } export default function CategoryResultsScreen ({ store }) { @@ -84,19 +85,19 @@ export default function CategoryResultsScreen ({ store }) { ]), h('div', { class: 'papers-today' }, [ h('h2', { class: 'papers-today-title' }, 'New papers today'), - h('div', { class: 'papers' }, selectedPapers.map(paper => h(Paper, { paper }))) + h('div', { class: 'papers' }, todayPapers.map(paper => h(Paper, { paper }))) ]), h('div', { class: 'papers-last-few-days' }, [ h('h2', { class: 'papers-last-few-days-title' }, 'Papers in the last few days'), - h('div', { class: 'papers' }, selectedPapers.map(paper => h(Paper, { paper }))) + h('div', { class: 'papers' }, fewDaysPapers.map(paper => h(Paper, { paper }))) ]), h('div', { class: 'papers-last-week' }, [ h('h2', { class: 'papers-last-week-title' }, 'Papers in the last week'), - h('div', { class: 'papers' }, selectedPapers.map(paper => h(Paper, { paper }))) + h('div', { class: 'papers' }, weekPapers.map(paper => h(Paper, { paper }))) ]), h('div', { class: 'papers-this-month' }, [ - h('h2', { class: 'papers-this-month-title' }, 'Papers this month'), - h('div', { class: 'papers' }, selectedPapers.map(paper => h(Paper, { paper }))) + h('h2', { class: 'papers-this-month-title' }, 'Papers in the past month'), + h('div', { class: 'papers' }, monthPapers.map(paper => h(Paper, { paper }))) ]) ]); } From 95f49c3b976ee12c7aaa360bd2ec7255bfccaff7 Mon Sep 17 00:00:00 2001 From: Suhyma Date: Tue, 4 Apr 2023 12:49:51 -0400 Subject: [PATCH 5/9] Strict equality for today's date --- src/dashboard/category-results-screen.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dashboard/category-results-screen.js b/src/dashboard/category-results-screen.js index 3021a72..65d168e 100644 --- a/src/dashboard/category-results-screen.js +++ b/src/dashboard/category-results-screen.js @@ -24,7 +24,7 @@ function findRelativeDate (papers, range) { if (range === 'today') { for (const paper of papers) { const paperDate = format(paper.date, 'yyyy-MM-dd'); - if (paperDate >= today) { + if (paperDate === today) { displayPapers.push(paper); } } From 47ad9a7396335a66908cc5f8494534979909ea66 Mon Sep 17 00:00:00 2001 From: Suhyma Date: Tue, 4 Apr 2023 12:58:26 -0400 Subject: [PATCH 6/9] Current configuration for debugging app.js --- .vscode/launch.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.vscode/launch.json b/.vscode/launch.json index 6bb8cd5..32fe1bd 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -75,6 +75,16 @@ ], "program": "${workspaceFolder}/src/data-search.js", "console": "integratedTerminal" + }, + { + "type": "node", + "request": "launch", + "name": "App", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}/src/dashboard/app.js", + "console": "integratedTerminal" } ] } \ No newline at end of file From 0c302329d341dc8ba456ae95ff665b11bff3c007 Mon Sep 17 00:00:00 2001 From: Suhyma Date: Wed, 5 Apr 2023 15:35:13 -0400 Subject: [PATCH 7/9] Use date-fns --- src/dashboard/categories.js | 2 +- src/dashboard/category-results-screen.js | 101 ++++++++++++++--------- 2 files changed, 62 insertions(+), 41 deletions(-) diff --git a/src/dashboard/categories.js b/src/dashboard/categories.js index 5e239b7..ac575fc 100644 --- a/src/dashboard/categories.js +++ b/src/dashboard/categories.js @@ -9,7 +9,7 @@ export const categories = data.map(({ id, name, description, img }) => ({ id, na export const getPapers = ({ id }) => { let papers = []; const category = data.find(cat => cat.id === id); - papers = category && category.papers.map(toDate).sort(byDate).slice(1); + papers = category && category.papers.map(toDate).sort(byDate); return papers; }; diff --git a/src/dashboard/category-results-screen.js b/src/dashboard/category-results-screen.js index 65d168e..a96a634 100644 --- a/src/dashboard/category-results-screen.js +++ b/src/dashboard/category-results-screen.js @@ -1,7 +1,7 @@ import { h } from 'preact'; import { Link } from 'preact-router/match'; import CategoryCard from './category-card.js'; -import { format, sub } from 'date-fns'; +import { format, sub, isWithinInterval } from 'date-fns'; function Paper ({ paper }) { return h('div', { class: 'paper' }, [ @@ -18,57 +18,78 @@ function Paper ({ paper }) { function findRelativeDate (papers, range) { const now = new Date(); - const today = format(now, 'yyyy-MM-dd'); + // const today = format(now, 'yyyy-MM-dd'); const displayPapers = []; - if (range === 'today') { - for (const paper of papers) { - const paperDate = format(paper.date, 'yyyy-MM-dd'); - if (paperDate === today) { - displayPapers.push(paper); - } - } - } else if (range === 'days') { // within the past 4 days - const startOffset = { days: 4 }; - const start = format(sub(now, startOffset), 'yyyy-MM-dd'); + for (const paper of papers) { + const paperDate = new Date(paper.date); - for (const paper of papers) { - const paperDate = format(paper.date, 'yyyy-MM-dd'); - if (paperDate >= start && paperDate < today) { - displayPapers.push(paper); - } + if (range === 'today' && isWithinInterval(paperDate, { start: now, end: now })) { // Today's papers + displayPapers.push(paper); + } else if (range === 'days' && isWithinInterval(paperDate, { start: sub(now, { days: 4 }), end: sub(now, { days: 1 }) })) { // Papers from 4 days ago + displayPapers.push(paper); + } else if (range === 'week' && isWithinInterval(paperDate, { start: sub(now, { weeks: 1 }), end: sub(now, { days: 4 }) })) { // Papers from past week + displayPapers.push(paper); + } else if (range === 'month' && isWithinInterval(paperDate, { start: sub(now, { months: 1 }), end: sub(now, { weeks: 1 }) })) { // Rest of the papers from the past month + displayPapers.push(paper); + } else { + console.log('didnt work'); } - } else if (range === 'week') { - const startOffset = { weeks: 1 }; - const endOffset = { days: 4 }; - const start = format(sub(now, startOffset), 'yyyy-MM-dd'); - const end = format(sub(now, endOffset), 'yyyy-MM-dd'); + } - for (const paper of papers) { - const paperDate = format(paper.date, 'yyyy-MM-dd'); - if (paperDate >= start && paperDate < end) { // within the past week - displayPapers.push(paper); - } - } - } else { - const startOffset = { months: 1 }; - const endOffset = { weeks: 1 }; - const start = format(sub(now, startOffset), 'yyyy-MM-dd'); - const end = format(sub(now, endOffset), 'yyyy-MM-dd'); + // if (range === 'today') { + // console.log('today date: ' + today); + // for (const paper of papers) { + // const paperDate = format(paper.date, 'yyyy-MM-dd'); + // console.log('PAPER DATE: ' + paperDate); + // if (paperDate === today) { + // displayPapers.push(paper); + // } + // } + // } else if (range === 'days') { // within the past 4 days + // const startOffset = { days: 4 }; + // const start = format(sub(now, startOffset), 'yyyy-MM-dd'); - for (const paper of papers) { - const paperDate = format(paper.date, 'yyyy-MM-dd'); - if (paperDate >= start && paperDate < end) { // everything else within the past month - displayPapers.push(paper); - } - } - } + // for (const paper of papers) { + // const paperDate = format(paper.date, 'yyyy-MM-dd'); + // if (paperDate >= start && paperDate < today) { + // displayPapers.push(paper); + // } + // } + // } else if (range === 'week') { + // const startOffset = { weeks: 1 }; + // const endOffset = { days: 4 }; + // const start = format(sub(now, startOffset), 'yyyy-MM-dd'); + // const end = format(sub(now, endOffset), 'yyyy-MM-dd'); + + // for (const paper of papers) { + // const paperDate = format(paper.date, 'yyyy-MM-dd'); + // if (paperDate >= start && paperDate < end) { // within the past week + // displayPapers.push(paper); + // } + // } + // } else { + // const startOffset = { months: 1 }; + // const endOffset = { weeks: 1 }; + // const start = format(sub(now, startOffset), 'yyyy-MM-dd'); + // const end = format(sub(now, endOffset), 'yyyy-MM-dd'); + + // for (const paper of papers) { + // const paperDate = format(paper.date, 'yyyy-MM-dd'); + // if (paperDate >= start && paperDate < end) { // everything else within the past month + // displayPapers.push(paper); + // } + // } + // } return displayPapers; } export default function CategoryResultsScreen ({ store }) { const { selectedPapers, selectedCategory } = store; const todayPapers = findRelativeDate(selectedPapers, 'today'); + console.log('TODAYS PAPERS: '); + console.log(todayPapers); + const fewDaysPapers = findRelativeDate(selectedPapers, 'days'); const weekPapers = findRelativeDate(selectedPapers, 'week'); const monthPapers = findRelativeDate(selectedPapers, 'month'); From 7bccd391725f99c0102cd5d3e89b9983951cdd78 Mon Sep 17 00:00:00 2001 From: Suhyma Date: Mon, 10 Apr 2023 12:43:57 -0400 Subject: [PATCH 8/9] Finalize findRelativeDate function --- src/dashboard/category-results-screen.js | 67 ++++------------------ src/dashboard/category-selection-screen.js | 2 +- 2 files changed, 11 insertions(+), 58 deletions(-) diff --git a/src/dashboard/category-results-screen.js b/src/dashboard/category-results-screen.js index a96a634..750174a 100644 --- a/src/dashboard/category-results-screen.js +++ b/src/dashboard/category-results-screen.js @@ -1,7 +1,7 @@ import { h } from 'preact'; import { Link } from 'preact-router/match'; import CategoryCard from './category-card.js'; -import { format, sub, isWithinInterval } from 'date-fns'; +import { sub } from 'date-fns'; function Paper ({ paper }) { return h('div', { class: 'paper' }, [ @@ -18,78 +18,31 @@ function Paper ({ paper }) { function findRelativeDate (papers, range) { const now = new Date(); - // const today = format(now, 'yyyy-MM-dd'); + const today = now.toISOString().split('T')[0]; + const daysAgo = sub(now, { days: 4 }).toISOString(); + const weekAgo = sub(now, { weeks: 1 }).toISOString(); + const monthAgo = sub(now, { months: 1 }).toISOString(); const displayPapers = []; for (const paper of papers) { - const paperDate = new Date(paper.date); + const paperDate = paper.date.toISOString().split('T')[0]; - if (range === 'today' && isWithinInterval(paperDate, { start: now, end: now })) { // Today's papers + if (range === 'today' && paperDate === today) { // Today's papers displayPapers.push(paper); - } else if (range === 'days' && isWithinInterval(paperDate, { start: sub(now, { days: 4 }), end: sub(now, { days: 1 }) })) { // Papers from 4 days ago + } else if (range === 'days' && paperDate >= daysAgo && paperDate < today) { // Papers from 4 days ago displayPapers.push(paper); - } else if (range === 'week' && isWithinInterval(paperDate, { start: sub(now, { weeks: 1 }), end: sub(now, { days: 4 }) })) { // Papers from past week + } else if (range === 'week' && paperDate >= weekAgo && paperDate < daysAgo) { // Papers from past week displayPapers.push(paper); - } else if (range === 'month' && isWithinInterval(paperDate, { start: sub(now, { months: 1 }), end: sub(now, { weeks: 1 }) })) { // Rest of the papers from the past month + } else if (range === 'month' && paperDate >= monthAgo && paperDate < weekAgo) { // Rest of the papers from the past month displayPapers.push(paper); - } else { - console.log('didnt work'); } } - - // if (range === 'today') { - // console.log('today date: ' + today); - // for (const paper of papers) { - // const paperDate = format(paper.date, 'yyyy-MM-dd'); - // console.log('PAPER DATE: ' + paperDate); - // if (paperDate === today) { - // displayPapers.push(paper); - // } - // } - // } else if (range === 'days') { // within the past 4 days - // const startOffset = { days: 4 }; - // const start = format(sub(now, startOffset), 'yyyy-MM-dd'); - - // for (const paper of papers) { - // const paperDate = format(paper.date, 'yyyy-MM-dd'); - // if (paperDate >= start && paperDate < today) { - // displayPapers.push(paper); - // } - // } - // } else if (range === 'week') { - // const startOffset = { weeks: 1 }; - // const endOffset = { days: 4 }; - // const start = format(sub(now, startOffset), 'yyyy-MM-dd'); - // const end = format(sub(now, endOffset), 'yyyy-MM-dd'); - - // for (const paper of papers) { - // const paperDate = format(paper.date, 'yyyy-MM-dd'); - // if (paperDate >= start && paperDate < end) { // within the past week - // displayPapers.push(paper); - // } - // } - // } else { - // const startOffset = { months: 1 }; - // const endOffset = { weeks: 1 }; - // const start = format(sub(now, startOffset), 'yyyy-MM-dd'); - // const end = format(sub(now, endOffset), 'yyyy-MM-dd'); - - // for (const paper of papers) { - // const paperDate = format(paper.date, 'yyyy-MM-dd'); - // if (paperDate >= start && paperDate < end) { // everything else within the past month - // displayPapers.push(paper); - // } - // } - // } return displayPapers; } export default function CategoryResultsScreen ({ store }) { const { selectedPapers, selectedCategory } = store; const todayPapers = findRelativeDate(selectedPapers, 'today'); - console.log('TODAYS PAPERS: '); - console.log(todayPapers); - const fewDaysPapers = findRelativeDate(selectedPapers, 'days'); const weekPapers = findRelativeDate(selectedPapers, 'week'); const monthPapers = findRelativeDate(selectedPapers, 'month'); diff --git a/src/dashboard/category-selection-screen.js b/src/dashboard/category-selection-screen.js index 2afb9c6..408f69f 100644 --- a/src/dashboard/category-selection-screen.js +++ b/src/dashboard/category-selection-screen.js @@ -8,7 +8,7 @@ export default function CategorySelectionScreen ({ store }) { return h('div', { class: 'category-selection-screen' }, [ h('div', { class: 'app-name' }, 'The Digest'), - h('div', { class: 'app-tagline' }, 'Quick acess to the latest papers in the biomedicine.'), + h('div', { class: 'app-tagline' }, 'Quick access to the latest papers in the biomedicine.'), h('div', { class: 'categories' }, (haveCategories ? categories.map(category => h(CategoryCard, { category, store })) : h('div', {}, 'No categories!') From 6ad77d688daa9c09348bbf704e369f2e16aa9cfb Mon Sep 17 00:00:00 2001 From: Suhyma Date: Mon, 10 Apr 2023 15:37:18 -0400 Subject: [PATCH 9/9] Dynamic heading display --- src/dashboard/category-results-screen.js | 35 ++++++++++++++++-------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/dashboard/category-results-screen.js b/src/dashboard/category-results-screen.js index 750174a..21f469e 100644 --- a/src/dashboard/category-results-screen.js +++ b/src/dashboard/category-results-screen.js @@ -47,8 +47,8 @@ export default function CategoryResultsScreen ({ store }) { const weekPapers = findRelativeDate(selectedPapers, 'week'); const monthPapers = findRelativeDate(selectedPapers, 'month'); - return h('div', { class: 'category-results-screen' }, [ - h(Link, { href: '/', class: 'category-results-reset link' }, '< Select a different topic'), // TODO: < should be a nice SVG icon + const resultsScreenElements = [ + h(Link, { href: '/', class: 'category-results-reset link' }, '< Select a different topic'), h('div', { class: 'category-results-info' }, [ // TODO: better css for mobile CategoryCard({ category: selectedCategory, store, selectable: false, includeName: false }), h('div', { class: 'category-results-details' }, [ @@ -56,22 +56,33 @@ export default function CategoryResultsScreen ({ store }) { h('div', { class: 'category-results-date' }, 'Updated yesterday'), h('div', { class: 'category-results-description' }, selectedCategory.description) ]) - ]), - h('div', { class: 'papers-today' }, [ + ]) + ]; + + if (todayPapers.length !== 0) { + resultsScreenElements.push(h('div', { class: 'papers-today' }, [ h('h2', { class: 'papers-today-title' }, 'New papers today'), h('div', { class: 'papers' }, todayPapers.map(paper => h(Paper, { paper }))) - ]), - h('div', { class: 'papers-last-few-days' }, [ + ])); + } + if (fewDaysPapers.length !== 0) { + resultsScreenElements.push(h('div', { class: 'papers-last-few-days' }, [ h('h2', { class: 'papers-last-few-days-title' }, 'Papers in the last few days'), h('div', { class: 'papers' }, fewDaysPapers.map(paper => h(Paper, { paper }))) - ]), - h('div', { class: 'papers-last-week' }, [ + ])); + } + if (weekPapers.length !== 0) { + resultsScreenElements.push(h('div', { class: 'papers-last-week' }, [ h('h2', { class: 'papers-last-week-title' }, 'Papers in the last week'), h('div', { class: 'papers' }, weekPapers.map(paper => h(Paper, { paper }))) - ]), - h('div', { class: 'papers-this-month' }, [ + ])); + } + if (monthPapers.length !== 0) { + resultsScreenElements.push(h('div', { class: 'category-results-papers-this-month' }, [ h('h2', { class: 'papers-this-month-title' }, 'Papers in the past month'), h('div', { class: 'papers' }, monthPapers.map(paper => h(Paper, { paper }))) - ]) - ]); + ])); + } + + return h('div', { class: 'category-results-screen' }, resultsScreenElements); }