From 3e01fd6cc34d04f1e720b2bc7692f2c14e032242 Mon Sep 17 00:00:00 2001 From: Nikita Date: Wed, 28 Aug 2024 15:21:28 +0300 Subject: [PATCH 1/3] feat(feed-questions): add user prediction for continuous questions --- .../components/sidebar/news_match/index.tsx | 1 - .../question_numeric_tile.tsx | 1 + front_end/src/components/prediction_chip.tsx | 55 +++++++++++++++++-- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/front_end/src/app/(main)/questions/[id]/components/sidebar/news_match/index.tsx b/front_end/src/app/(main)/questions/[id]/components/sidebar/news_match/index.tsx index a0cb9abb55..9d115ca944 100644 --- a/front_end/src/app/(main)/questions/[id]/components/sidebar/news_match/index.tsx +++ b/front_end/src/app/(main)/questions/[id]/components/sidebar/news_match/index.tsx @@ -9,7 +9,6 @@ interface Props { } const fetchArticles = async (postId: number) => { - await new Promise((resolve) => setTimeout(resolve, 300)); return await PostsApi.getRelatedNews(postId); }; diff --git a/front_end/src/components/post_card/question_chart_tile/question_numeric_tile.tsx b/front_end/src/components/post_card/question_chart_tile/question_numeric_tile.tsx index 287e4411fb..ba3e32a57a 100644 --- a/front_end/src/components/post_card/question_chart_tile/question_numeric_tile.tsx +++ b/front_end/src/components/post_card/question_chart_tile/question_numeric_tile.tsx @@ -68,6 +68,7 @@ const QuestionNumericTile: FC = ({ question={question} prediction={prediction} status={curationStatus} + showUserForecast />
diff --git a/front_end/src/components/prediction_chip.tsx b/front_end/src/components/prediction_chip.tsx index 37d50682a4..010158057d 100644 --- a/front_end/src/components/prediction_chip.tsx +++ b/front_end/src/components/prediction_chip.tsx @@ -1,12 +1,13 @@ import { faUserGroup } from "@fortawesome/free-solid-svg-icons"; +import { faUser } from "@fortawesome/free-regular-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import classNames from "classnames"; import { useLocale, useTranslations } from "next-intl"; import { FC, PropsWithChildren } from "react"; -import { PostStatus, Resolution } from "@/types/post"; +import { PostStatus } from "@/types/post"; import { Question } from "@/types/question"; -import { getDisplayValue } from "@/utils/charts"; +import { getDisplayUserValue, getDisplayValue } from "@/utils/charts"; import { formatResolution } from "@/utils/questions"; type Size = "compact" | "large"; @@ -18,6 +19,7 @@ type Props = { size?: Size; className?: string; chipClassName?: string; + showUserForecast?: boolean; }; const PredictionChip: FC = ({ @@ -27,6 +29,7 @@ const PredictionChip: FC = ({ className, chipClassName, size, + showUserForecast, }) => { const t = useTranslations(); const locale = useLocale(); @@ -38,9 +41,27 @@ const PredictionChip: FC = ({ question.type, locale ); - - const fmted_prediction = formatResolution(prediction, question.type, locale); - + const userForecast = question.my_forecasts; + const aggregate = question.aggregations.recency_weighted; + const lastUserForecast = aggregate.history[aggregate.history.length - 1]; + if (question.id === 3104) { + console.log(lastUserForecast); + console.log(question.my_forecasts); + console.log(lastUserForecast.centers![0]); + console.log(lastUserForecast.start_time); + console.log(question.type); + console.log(question.scaling); + console.log( + getDisplayUserValue( + question.my_forecasts!, + lastUserForecast.centers![0], + lastUserForecast.start_time, + question.type, + question.scaling + ) + ); + } + console.log(question); switch (status) { case PostStatus.PENDING: return ( @@ -72,6 +93,18 @@ const PredictionChip: FC = ({ > {formattedResolution} + {showUserForecast && question.my_forecasts?.history.length && ( +

+ + {getDisplayUserValue( + question.my_forecasts, + lastUserForecast.centers![0], + lastUserForecast.start_time, + question.type, + question.scaling + )} +

+ )} {size !== "compact" && !!nr_forecasters && (

{nr_forecasters} {t("forecasters")} @@ -118,6 +151,18 @@ const PredictionChip: FC = ({ {nr_forecasters} {t("forecasters")}

)} + {showUserForecast && question.my_forecasts?.history.length && ( +

+ + {getDisplayUserValue( + question.my_forecasts, + lastUserForecast.centers![0], + lastUserForecast.start_time, + question.type, + question.scaling + )} +

+ )} ); } From 0592ae6a2d97129d9ca1b9cc10a82856339e2e8a Mon Sep 17 00:00:00 2001 From: Nikita Date: Wed, 28 Aug 2024 15:21:33 +0300 Subject: [PATCH 2/3] fix(prediction-chip): remove logs --- front_end/src/components/prediction_chip.tsx | 21 ++------------------ 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/front_end/src/components/prediction_chip.tsx b/front_end/src/components/prediction_chip.tsx index 010158057d..7fc129a2cc 100644 --- a/front_end/src/components/prediction_chip.tsx +++ b/front_end/src/components/prediction_chip.tsx @@ -41,27 +41,10 @@ const PredictionChip: FC = ({ question.type, locale ); - const userForecast = question.my_forecasts; + const aggregate = question.aggregations.recency_weighted; const lastUserForecast = aggregate.history[aggregate.history.length - 1]; - if (question.id === 3104) { - console.log(lastUserForecast); - console.log(question.my_forecasts); - console.log(lastUserForecast.centers![0]); - console.log(lastUserForecast.start_time); - console.log(question.type); - console.log(question.scaling); - console.log( - getDisplayUserValue( - question.my_forecasts!, - lastUserForecast.centers![0], - lastUserForecast.start_time, - question.type, - question.scaling - ) - ); - } - console.log(question); + switch (status) { case PostStatus.PENDING: return ( From 6f19f06ee3e94566166778417efcf1819788f92e Mon Sep 17 00:00:00 2001 From: Nikita Date: Wed, 28 Aug 2024 15:21:37 +0300 Subject: [PATCH 3/3] fix(prediction-chip): fix render condition --- front_end/src/components/prediction_chip.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front_end/src/components/prediction_chip.tsx b/front_end/src/components/prediction_chip.tsx index 7fc129a2cc..6db61def70 100644 --- a/front_end/src/components/prediction_chip.tsx +++ b/front_end/src/components/prediction_chip.tsx @@ -134,7 +134,7 @@ const PredictionChip: FC = ({ {nr_forecasters} {t("forecasters")}

)} - {showUserForecast && question.my_forecasts?.history.length && ( + {showUserForecast && !!question.my_forecasts?.history.length && (

{getDisplayUserValue(