Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✨ Improve usability of mobile poll (#486)
Luke Vella8c74836de139
diff --git a/src/components/home/poll-demo.tsx b/src/components/home/poll-demo.tsxindex 4dd421279..edae44b23 100644--- a/src/components/home/poll-demo.tsx+++ b/src/components/home/poll-demo.tsx@@ -71,7 +71,7 @@ const PollDemo: React.VoidFunctionComponent = () => {month={dayjs(d).format("MMM")}/></div>- <div>+ <div className="flex justify-center"><ScoreSummary yesScore={score} /></div></div>diff --git a/src/components/poll/mobile-poll/poll-option.tsx b/src/components/poll/mobile-poll/poll-option.tsxindex c0cb38dfc..3a475ca76 100644--- a/src/components/poll/mobile-poll/poll-option.tsx+++ b/src/components/poll/mobile-poll/poll-option.tsx@@ -7,6 +7,7 @@ import * as React from "react";import ChevronDown from "@/components/icons/chevron-down.svg";import { useParticipants } from "../../participants-provider";+import { usePoll } from "../../poll-context";import { ScoreSummary } from "../score-summary";import UserAvatar from "../user-avatar";import VoteIcon from "../vote-icon";@@ -40,7 +41,7 @@ const CollapsibleContainer: React.VoidFunctionComponent<{},expanded: {opacity: 1,- width: 58,+ width: "auto",},}}initial="collapsed"@@ -112,6 +113,8 @@ const PollOptionVoteSummary: React.VoidFunctionComponent<{ optionId: string }> =<div className="text-slate-500">{name}</div></div>))}+ </div>+ <div className="col-span-1 space-y-2">{participantsWhoVotedIfNeedBe.map(({ name }, i) => (<div key={i} className="flex"><div className="relative mr-2 flex h-5 w-5 items-center justify-center">@@ -125,8 +128,6 @@ const PollOptionVoteSummary: React.VoidFunctionComponent<{ optionId: string }> =<div className="text-slate-500"> {name}</div></div>))}- </div>- <div className="col-span-1 space-y-2">{participantsWhoVotedNo.map(({ name }, i) => (<div key={i} className="flex"><div className="relative mr-2 flex h-5 w-5 items-center justify-center">@@ -183,10 +184,34 @@ const PollOption: React.VoidFunctionComponent<PollOptionProps> = ({yesScore,optionId,}) => {+ const { getVote } = usePoll();const showVotes = !!(selectedParticipantId || editable);const [expanded, setExpanded] = React.useState(false);const selectorRef = React.useRef<HTMLButtonElement>(null);const [active, setActive] = React.useState(false);++ const score = React.useMemo(() => {+ if (!editable) {+ return yesScore;+ }++ if (selectedParticipantId) {+ const currentVote = getVote(selectedParticipantId, optionId);+ return (+ yesScore ++ (currentVote === "yes"+ ? vote === "yes"+ ? 0+ : -1+ : vote === "yes"+ ? 1+ : 0)+ );+ }++ return yesScore + (vote === "yes" ? 1 : 0);+ }, [editable, getVote, optionId, selectedParticipantId, vote, yesScore]);+return (<divclassName={clsx("space-y-4 overflow-hidden p-3", {@@ -199,37 +224,36 @@ const PollOption: React.VoidFunctionComponent<PollOptionProps> = ({selectorRef.current?.click();}}>- <div className="flex select-none transition duration-75">- <div className="flex grow gap-3">- <div className="shrink-0">{children}</div>- <AnimatePresence initial={false}>- {showVotes ? null : (- <motion.div- exit={{ opacity: 0 }}- className="flex min-w-0 grow items-center justify-end gap-2 overflow-hidden"- >- <button- type="button"- onTouchStart={(e) => e.stopPropagation()}- className="flex justify-end gap-2 rounded-lg p-2 active:bg-slate-500/10"- onClick={(e) => {- e.stopPropagation();- setExpanded((value) => !value);- }}- >- {participants.length > 0 ? (- <SummarizedParticipantList participants={participants} />- ) : null}- <ScoreSummary yesScore={yesScore} />- <ChevronDown- className={clsx("h-5 text-slate-400 transition-transform", {- "-rotate-180": expanded,- })}- />- </button>- </motion.div>- )}- </AnimatePresence>+ <div className="flex select-none items-center transition duration-75">+ <div className="mr-3 shrink-0 grow">{children}</div>+ <AnimatePresence initial={false}>+ {editable ? null : (+ <motion.button+ exit={{ opacity: 0, x: -10 }}+ type="button"+ onTouchStart={(e) => e.stopPropagation()}+ className="flex min-w-0 justify-end gap-1 overflow-hidden rounded-lg p-2 active:bg-slate-500/10"+ onClick={(e) => {+ e.stopPropagation();+ setExpanded((value) => !value);+ }}+ >+ {participants.length > 0 ? (+ <SummarizedParticipantList participants={participants} />+ ) : null}+ <ChevronDown+ className={clsx(+ "h-5 shrink-0 text-slate-400 transition-transform",+ {+ "-rotate-180": expanded,+ },+ )}+ />+ </motion.button>+ )}+ </AnimatePresence>+ <div className="mx-3">+ <ScoreSummary yesScore={score} /></div><CollapsibleContainerexpanded={showVotes}@@ -245,10 +269,10 @@ const PollOption: React.VoidFunctionComponent<PollOptionProps> = ({/></div>) : (- <AnimatePresence initial={false}>+ <AnimatePresence initial={false} exitBeforeEnter={true}><PopInOutkey={vote}- className="absolute inset-0 flex h-full items-center justify-center"+ className="flex h-full w-9 items-center justify-center"><VoteIcon type={vote} /></PopInOut>@@ -257,7 +281,7 @@ const PollOption: React.VoidFunctionComponent<PollOptionProps> = ({</CollapsibleContainer></div><AnimatePresence initial={false}>- {expanded && !showVotes ? (+ {expanded && !editable ? (<PollOptionVoteSummary optionId={optionId} />) : null}</AnimatePresence>diff --git a/src/components/poll/mobile-poll/time-slot-option.tsx b/src/components/poll/mobile-poll/time-slot-option.tsxindex 995bee7bc..15b2a71e3 100644--- a/src/components/poll/mobile-poll/time-slot-option.tsx+++ b/src/components/poll/mobile-poll/time-slot-option.tsx@@ -12,14 +12,13 @@ export interface TimeSlotOptionProps extends PollOptionProps {const TimeSlotOption: React.VoidFunctionComponent<TimeSlotOptionProps> = ({startTime,- endTime,duration,...rest}) => {return (<PollOption {...rest}><div className="grow">- <div className="h-7">{`${startTime} - ${endTime}`}</div>+ <div className="h-7">{`${startTime}`}</div><div className="flex grow items-center text-sm text-slate-400"><Clock className="leading- mr-1 inline w-4" />{duration}diff --git a/src/components/poll/score-summary.tsx b/src/components/poll/score-summary.tsxindex 3d9823c79..320bc469d 100644--- a/src/components/poll/score-summary.tsx+++ b/src/components/poll/score-summary.tsx@@ -10,59 +10,38 @@ export interface PopularityScoreProps {highlight?: boolean;}-const Score = React.forwardRef<- HTMLDivElement,- {- icon: React.ComponentType<{ className?: string }>;- score: number;- }->(function Score({ icon: Icon, score }, ref) {- const prevScore = usePrevious(score);+export const ScoreSummary: React.VoidFunctionComponent<PopularityScoreProps> =+ React.memo(function PopularityScore({ yesScore: score }) {+ const prevScore = usePrevious(score);- const multiplier = prevScore !== undefined ? score - prevScore : 0;+ const direction = prevScore !== undefined ? score - prevScore : 0;- return (- <div- ref={ref}- className="relative inline-flex items-center text-sm font-bold"- >- <Icon className="mr-1 inline-block h-4 text-slate-300 transition-opacity" />- <span className="relative inline-block text-slate-500">- <AnimatePresence initial={false}>+ return (+ <div+ data-testid="popularity-score"+ className="flex items-center gap-1 text-sm font-bold tabular-nums"+ >+ <User className="inline-block h-4 text-slate-300 transition-opacity" />+ <AnimatePresence initial={false} exitBeforeEnter={true}><motion.spantransition={{- duration: 0.2,+ duration: 0.1,}}initial={{opacity: 0,- y: 10 * multiplier,+ y: 10 * direction,}}animate={{ opacity: 1, y: 0 }}exit={{opacity: 0,- y: 10 * multiplier,+ y: 10 * direction,}}key={score}- className="absolute inset-0"+ className="relative">{score}</motion.span></AnimatePresence>- {/* Invisible text just to give us the right width */}- <span className="text-transparent">{score}</span>- </span>- </div>- );-});--export const ScoreSummary: React.VoidFunctionComponent<PopularityScoreProps> =- React.memo(function PopularityScore({ yesScore }) {- return (- <div- data-testid="popularity-score"- className="relative inline-flex items-center space-x-2"- >- <Score icon={User} score={yesScore} /></div>);});