import Link from "next/link"; import { FaExpand } from "react-icons/fa"; import ReactMarkdown from "react-markdown"; import { Card } from "../../../common/Card"; import { CopyText } from "../../../common/CopyText"; import { QuestionFragment } from "../../../fragments.generated"; import { cleanText } from "../../../utils"; import { QuestionOptions } from "../QuestionOptions"; import { QuestionFooter } from "./QuestionFooter"; const truncateText = (length: number, text: string): string => { if (!text) { return ""; } if (text.length <= length) { return text; } const breakpoints = " .!?"; let lastLetter: string | undefined = undefined; let lastIndex: number | undefined = undefined; for (let index = length; index > 0; index--) { const letter = text[index]; if (breakpoints.includes(letter)) { lastLetter = letter; lastIndex = index; break; } } let truncatedText = text.slice(0, lastIndex) + (lastLetter != "." ? "..." : ".."); return truncatedText; }; // Auxiliary components const DisplayMarkdown: React.FC<{ description: string }> = ({ description, }) => { const formatted = truncateText(250, cleanText(description)); // overflow-hidden overflow-ellipsis h-24 return formatted === "" ? null : (
{formatted}
); }; const LastUpdated: React.FC<{ timestamp: Date }> = ({ timestamp }) => (
Last updated:{" "} {timestamp ? timestamp.toISOString().slice(0, 10) : "unknown"}
); // Main component interface Props { question: QuestionFragment; showTimeStamp: boolean; expandFooterToFullWidth: boolean; showIdToggle?: boolean; showExpandButton?: boolean; } export const QuestionCard: React.FC = ({ question, showTimeStamp, expandFooterToFullWidth, showIdToggle, showExpandButton = true, }) => { const { options } = question; const lastUpdated = new Date(question.timestamp * 1000); const isBinary = options.length === 2 && (options[0].name === "Yes" || options[0].name === "No"); return (
{showIdToggle ? (
) : null}
{showExpandButton ? ( ) : null} {question.title}
{isBinary ? (
) : (
)} {question.platform.id !== "guesstimate" && options.length < 3 && (
)} {question.platform.id === "guesstimate" && question.visualization && ( Guesstimate Screenshot )}
{/* This one is exclusively for mobile*/}
); };