Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ interface Props {
}

const fetchArticles = async (postId: number) => {
await new Promise((resolve) => setTimeout(resolve, 300));
return await PostsApi.getRelatedNews(postId);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const QuestionNumericTile: FC<Props> = ({
question={question}
prediction={prediction}
status={curationStatus}
showUserForecast
/>
</div>
<div className="my-1 h-24 w-2/3 min-w-24 max-w-[500px] flex-1 overflow-visible">
Expand Down
34 changes: 31 additions & 3 deletions front_end/src/components/prediction_chip.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -18,6 +19,7 @@ type Props = {
size?: Size;
className?: string;
chipClassName?: string;
showUserForecast?: boolean;
};

const PredictionChip: FC<Props> = ({
Expand All @@ -27,6 +29,7 @@ const PredictionChip: FC<Props> = ({
className,
chipClassName,
size,
showUserForecast,
}) => {
const t = useTranslations();
const locale = useLocale();
Expand All @@ -39,7 +42,8 @@ const PredictionChip: FC<Props> = ({
locale
);

const fmted_prediction = formatResolution(prediction, question.type, locale);
const aggregate = question.aggregations.recency_weighted;
const lastUserForecast = aggregate.history[aggregate.history.length - 1];

switch (status) {
case PostStatus.PENDING:
Expand Down Expand Up @@ -72,6 +76,18 @@ const PredictionChip: FC<Props> = ({
>
{formattedResolution}
</Chip>
{showUserForecast && question.my_forecasts?.history.length && (
<p className="m-2 text-orange-800 dark:text-orange-800-dark">
<FontAwesomeIcon icon={faUser} className="mr-1" />
{getDisplayUserValue(
question.my_forecasts,
lastUserForecast.centers![0],
lastUserForecast.start_time,
question.type,
question.scaling
)}
</p>
)}
{size !== "compact" && !!nr_forecasters && (
<p>
{nr_forecasters} {t("forecasters")}
Expand Down Expand Up @@ -118,6 +134,18 @@ const PredictionChip: FC<Props> = ({
{nr_forecasters} {t("forecasters")}
</p>
)}
{showUserForecast && !!question.my_forecasts?.history.length && (
<p className="m-2 text-orange-800 dark:text-orange-800-dark">
<FontAwesomeIcon icon={faUser} className="mr-1" />
{getDisplayUserValue(
question.my_forecasts,
lastUserForecast.centers![0],
lastUserForecast.start_time,
question.type,
question.scaling
)}
</p>
)}
</span>
);
}
Expand Down