From d8e9e7812a404327dc99525bc50ec85022b24a94 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Sat, 17 Sep 2022 19:47:04 -0500 Subject: [PATCH] Don't show Daily movers if there are none. Threshold is 1% --- web/components/contract/prob-change-table.tsx | 23 +++++++++++-------- web/pages/home/index.tsx | 9 ++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/web/components/contract/prob-change-table.tsx b/web/components/contract/prob-change-table.tsx index 644946c9..6a47a7b7 100644 --- a/web/components/contract/prob-change-table.tsx +++ b/web/components/contract/prob-change-table.tsx @@ -20,18 +20,21 @@ export function ProbChangeTable(props: { const { positiveChanges, negativeChanges } = changes - const threshold = 0.075 - const countOverThreshold = Math.max( - positiveChanges.findIndex((c) => c.probChanges.day < threshold) + 1, - negativeChanges.findIndex((c) => c.probChanges.day > -threshold) + 1 + const threshold = 0.01 + const positiveAboveThreshold = positiveChanges.filter( + (c) => c.probChanges.day > threshold ) - const maxRows = Math.min(positiveChanges.length, negativeChanges.length) - const rows = full - ? maxRows - : Math.min(3, Math.min(maxRows, countOverThreshold)) + const negativeAboveThreshold = negativeChanges.filter( + (c) => c.probChanges.day < threshold + ) + const maxRows = Math.min( + positiveAboveThreshold.length, + negativeAboveThreshold.length + ) + const rows = full ? maxRows : Math.min(3, maxRows) - const filteredPositiveChanges = positiveChanges.slice(0, rows) - const filteredNegativeChanges = negativeChanges.slice(0, rows) + const filteredPositiveChanges = positiveAboveThreshold.slice(0, rows) + const filteredNegativeChanges = negativeAboveThreshold.slice(0, rows) if (rows === 0) return
None
diff --git a/web/pages/home/index.tsx b/web/pages/home/index.tsx index 5e10bc3c..fe27a2a0 100644 --- a/web/pages/home/index.tsx +++ b/web/pages/home/index.tsx @@ -242,6 +242,15 @@ function DailyMoversSection(props: { userId: string | null | undefined }) { const { userId } = props const changes = useProbChangesAlgolia(userId ?? '') + if (changes) { + const { positiveChanges, negativeChanges } = changes + if ( + !positiveChanges.find((c) => c.probChanges.day >= 0.01) || + !negativeChanges.find((c) => c.probChanges.day <= -0.01) + ) + return null + } + return (