import Exclamation from "@rallly/icons/exclamation.svg"; import LockClosed from "@rallly/icons/lock-closed.svg"; import { useTranslation } from "next-i18next"; import React from "react"; import Discussion from "@/components/discussion"; import DesktopPoll from "@/components/poll/desktop-poll"; import MobilePoll from "@/components/poll/mobile-poll"; import { preventWidows } from "@/utils/prevent-widows"; import { useParticipants } from "./participants-provider"; import PollSubheader from "./poll/poll-subheader"; import TruncatedLinkify from "./poll/truncated-linkify"; import { useTouchBeacon } from "./poll/use-touch-beacon"; import { UserAvatarProvider } from "./poll/user-avatar"; import VoteIcon from "./poll/vote-icon"; import { usePoll } from "./poll-context"; const checkIfWideScreen = () => window.innerWidth > 640; export const Poll = (props: { children?: React.ReactNode }) => { const { t } = useTranslation("app"); const { poll } = usePoll(); useTouchBeacon(poll.id); const { participants } = useParticipants(); const names = React.useMemo( () => participants?.map(({ name }) => name) ?? [], [participants], ); React.useEffect(() => { const listener = () => setIsWideScreen(checkIfWideScreen()); window.addEventListener("resize", listener); return () => { window.removeEventListener("resize", listener); }; }, []); const [isWideScreen, setIsWideScreen] = React.useState(checkIfWideScreen); const PollComponent = isWideScreen ? DesktopPoll : MobilePoll; return (
{props.children} {poll.demo ? (
{t("demoPollNotice")}
) : null} {poll.closed ? (
{t("pollHasBeenLocked")}
) : null}
{preventWidows(poll.title)}
{poll.description ? (
{preventWidows(poll.description)}
) : null} {poll.location ? (
{t("location")}
{poll.location}
) : null}
{t("possibleAnswers")}
{t("yes")} {t("ifNeedBe")} {t("no")}
{participants ? (
) : null}
{t("loading")}
}>
); };