Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✨ Highlight option with highest score (#595)
Luke Vella92a1d9f7874e
diff --git a/apps/web/src/components/home/poll-demo.tsx b/apps/web/src/components/home/poll-demo.tsxindex b100199f1..97c119257 100644--- a/apps/web/src/components/home/poll-demo.tsx+++ b/apps/web/src/components/home/poll-demo.tsx@@ -73,7 +73,7 @@ const PollDemo: React.FunctionComponent = () => {/></div><div className="flex justify-center">- <ScoreSummary yesScore={score} />+ <ScoreSummary yesScore={score} highlight={score === 4} /></div></div>);diff --git a/apps/web/src/components/poll-context.tsx b/apps/web/src/components/poll-context.tsxindex 967318989..9d740ddbc 100644--- a/apps/web/src/components/poll-context.tsx+++ b/apps/web/src/components/poll-context.tsx@@ -76,10 +76,13 @@ export const PollContextProvider: React.FunctionComponent<{if (vote.type === "ifNeedBe") {acc.ifNeedBe += 1;}+ if (vote.type === "no") {+ acc.no += 1;+ }});return acc;},- { yes: 0, ifNeedBe: 0 },+ { yes: 0, ifNeedBe: 0, no: 0 },);},[participants],diff --git a/apps/web/src/components/poll/desktop-poll/poll-header.tsx b/apps/web/src/components/poll/desktop-poll/poll-header.tsxindex cbbf75913..3348d9424 100644--- a/apps/web/src/components/poll/desktop-poll/poll-header.tsx+++ b/apps/web/src/components/poll/desktop-poll/poll-header.tsx@@ -4,7 +4,7 @@ import * as React from "react";import { usePoll } from "@/components/poll-context";import DateCard from "../../date-card";-import { ScoreSummary } from "../score-summary";+import { ConnectedScoreSummary } from "../score-summary";import ControlledScrollArea from "./controlled-scroll-area";import { usePollContext } from "./poll-context";@@ -27,14 +27,13 @@ const TimeRange: React.FunctionComponent<{};const PollHeader: React.FunctionComponent = () => {- const { options, getScore } = usePoll();+ const { options } = usePoll();const { setActiveOptionId, columnWidth } = usePollContext();return (<ControlledScrollArea>{options.map((option) => {const { optionId } = option;- const numVotes = getScore(optionId);return (<divkey={optionId}@@ -58,10 +57,7 @@ const PollHeader: React.FunctionComponent = () => {/>) : null}<div className="flex justify-center">- <ScoreSummary- yesScore={numVotes.yes}- ifNeedBeScore={numVotes.ifNeedBe}- />+ <ConnectedScoreSummary optionId={option.optionId} /></div></div>);diff --git a/apps/web/src/components/poll/mobile-poll/poll-option.tsx b/apps/web/src/components/poll/mobile-poll/poll-option.tsxindex bf3d7f7d8..cd3190ac6 100644--- a/apps/web/src/components/poll/mobile-poll/poll-option.tsx+++ b/apps/web/src/components/poll/mobile-poll/poll-option.tsx@@ -8,7 +8,7 @@ import ChevronDown from "@/components/icons/chevron-down.svg";import { useParticipants } from "../../participants-provider";import { usePoll } from "../../poll-context";-import { ScoreSummary } from "../score-summary";+import { ConnectedScoreSummary } from "../score-summary";import UserAvatar from "../user-avatar";import VoteIcon from "../vote-icon";import { VoteSelector } from "../vote-selector";@@ -253,7 +253,7 @@ const PollOption: React.FunctionComponent<PollOptionProps> = ({)}</AnimatePresence><div className="mx-3">- <ScoreSummary yesScore={score} />+ <ConnectedScoreSummary optionId={optionId} /></div><CollapsibleContainerexpanded={showVotes}diff --git a/apps/web/src/components/poll/score-summary.tsx b/apps/web/src/components/poll/score-summary.tsxindex 891818a28..a6df24468 100644--- a/apps/web/src/components/poll/score-summary.tsx+++ b/apps/web/src/components/poll/score-summary.tsx@@ -1,8 +1,10 @@+import clsx from "clsx";import { AnimatePresence, m } from "framer-motion";import * as React from "react";import { usePrevious } from "react-use";import CheckCircle from "@/components/icons/check-circle.svg";+import { usePoll } from "@/components/poll-context";export interface PopularityScoreProps {yesScore: number;@@ -10,8 +12,19 @@ export interface PopularityScoreProps {highlight?: boolean;}+export const ConnectedScoreSummary: React.FunctionComponent<{+ optionId: string;+}> = ({ optionId }) => {+ const { getScore, highScore } = usePoll();+ const score = getScore(optionId);++ return (+ <ScoreSummary yesScore={score.yes} highlight={score.yes === highScore} />+ );+};+export const ScoreSummary: React.FunctionComponent<PopularityScoreProps> =- React.memo(function PopularityScore({ yesScore: score }) {+ React.memo(function PopularityScore({ yesScore: score, highlight }) {const prevScore = usePrevious(score);const direction = prevScore !== undefined ? score - prevScore : 0;@@ -19,9 +32,15 @@ export const ScoreSummary: React.FunctionComponent<PopularityScoreProps> =return (<divdata-testid="popularity-score"- className="flex items-center gap-1 text-sm font-bold tabular-nums"+ className={clsx(+ "flex select-none items-center gap-1 px-2 text-sm font-bold tabular-nums",+ {+ "rounded-full bg-green-50 text-green-400": highlight,+ },+ { "text-slate-400": !highlight },+ )}>- <CheckCircle className="inline-block h-4 text-slate-300 transition-opacity" />+ <CheckCircle className="-ml-1 inline-block h-4 transition-opacity" /><AnimatePresence initial={false} exitBeforeEnter={true}><m.spantransition={{diff --git a/apps/web/src/server/routers/polls/demo.ts b/apps/web/src/server/routers/polls/demo.tsindex 481b792f9..e152b78ba 100644--- a/apps/web/src/server/routers/polls/demo.ts+++ b/apps/web/src/server/routers/polls/demo.ts@@ -7,7 +7,7 @@ import { possiblyPublicProcedure, router } from "../../trpc";const participantData: Array<{ name: string; votes: VoteType[] }> = [{name: "Reed",- votes: ["yes", "no", "ifNeedBe", "no"],+ votes: ["yes", "no", "yes", "no"],},{name: "Susan",