Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
💄 Comments UX: fix mobile footer overlap and polish the sheet (#3082)
Luke Vella898025688c1b
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.jsonindex 3fb15a64f..18b3ffe72 100644--- a/apps/web/public/locales/en/app.json+++ b/apps/web/public/locales/en/app.json@@ -146,13 +146,16 @@"commandMenuNavigation": "Navigation","commandMenuNoResults": "No results","commandMenuSearchPlaceholder": "Type a command or search...",- "commentPlaceholder": "Leave a comment on this poll (visible to everyone)","comments": "Comments",+ "commentsComposerPlaceholder": "Write a comment…",+ "commentsComposerVisibility": "Visible to everyone","commentsSettingDescription": "Allow participants to post public comments on the poll.","commentsSettingTitle": "Comments","commentsSheetDescription": "View and add comments on this poll","commentsSheetEmpty": "No comments yet",+ "commentsSheetEmptyDescription": "Be the first to share your thoughts on this poll.","commentsSheetSubmitted": "Your comment has been added",+ "commentsTriggerLabel": "{count, plural, =0 {Comments} one {1 Comment} other {# Comments}}","configuredByEnvironmentVariable": "This setting has been configured by environment variable.","confirm": "Confirm","confirmSpaceName": "Please type the space name to confirm:",diff --git a/apps/web/src/app/[locale]/invite/[urlId]/invite-page.tsx b/apps/web/src/app/[locale]/invite/[urlId]/invite-page.tsxindex ae113090e..f3cf88104 100644--- a/apps/web/src/app/[locale]/invite/[urlId]/invite-page.tsx+++ b/apps/web/src/app/[locale]/invite/[urlId]/invite-page.tsx@@ -1,5 +1,5 @@"use client";-import { buttonVariants } from "@rallly/ui";+import { buttonVariants, cn } from "@rallly/ui";import { Alert, AlertAction, AlertDescription } from "@rallly/ui/alert";import { ArrowUpRightIcon, CrownIcon } from "lucide-react";import Link from "next/link";@@ -8,10 +8,31 @@ import { CommentsSheet } from "@/features/poll/components/comments-sheet";import { EventCard } from "@/features/poll/components/event-card";import { PollFooter } from "@/features/poll/components/poll-footer";import { ResponsiveResults } from "@/features/poll/components/responsive-results";-import { VotingForm } from "@/features/poll/components/voting-form";+import {+ useVotingForm,+ VotingForm,+} from "@/features/poll/components/voting-form";import { useUser } from "@/features/user/client";import { Trans } from "@/i18n/client";+const FloatingComments = () => {+ const votingForm = useVotingForm();+ const isVoting = votingForm.watch("mode") !== "view";++ return (+ <div+ className={cn(+ "fixed right-4 z-40 m-0 transition-[bottom] duration-300 ease-out lg:right-6 lg:bottom-6",+ // The mobile poll (below sm) shows a sticky voting footer while a+ // response is being edited; lift the button clear of it.+ isVoting ? "bottom-20 sm:bottom-4" : "bottom-4",+ )}+ >+ <CommentsSheet className="rounded-full shadow-lg" />+ </div>+ );+};+const GoToApp = () => {const poll = usePoll();const { user } = useUser();@@ -61,11 +82,9 @@ export function InvitePage({<EventCard /><VotingForm><ResponsiveResults />+ <FloatingComments /></VotingForm><PollFooter footerLinks={footerLinks} />- <div className="fixed right-4 bottom-15 z-40 lg:right-6 lg:bottom-6">- <CommentsSheet className="rounded-full shadow-lg" />- </div><div className="h-24 lg:hidden" /></main></div>diff --git a/apps/web/src/features/poll/components/comments-sheet.tsx b/apps/web/src/features/poll/components/comments-sheet.tsxindex 52741bf93..5a04346a9 100644--- a/apps/web/src/features/poll/components/comments-sheet.tsx+++ b/apps/web/src/features/poll/components/comments-sheet.tsx@@ -26,14 +26,21 @@ import {} from "@rallly/ui/sheet";import { toast } from "@rallly/ui/sonner";import {+ ArrowUpIcon,CheckCircle2Icon,- CornerDownLeftIcon,+ EyeIcon,MessageCircleIcon,MoreHorizontalIcon,TrashIcon,} from "lucide-react";import * as React from "react";import { Controller, useForm } from "react-hook-form";+import {+ EmptyState,+ EmptyStateDescription,+ EmptyStateIcon,+ EmptyStateTitle,+} from "@/components/empty-state";import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";import { usePoll, useRole } from "@/features/poll/client";import { useEditToken } from "@/features/poll/components/mutations";@@ -105,7 +112,7 @@ function NewCommentForm({ onSubmitted }: { onSubmitted: () => void }) {onSubmitted();})}>- <InputGroup className="bg-background shadow-lg dark:bg-card">+ <InputGroup><InputGroupAddon align="block-start" className="border-b">{user && !user.isGuest ? (<>@@ -137,21 +144,31 @@ function NewCommentForm({ onSubmitted }: { onSubmitted: () => void }) {</>)}</InputGroupAddon>- <div className="flex w-full items-end">- <InputGroupTextarea- id="comment"- maxLength={MAX_COMMENT_LENGTH}- placeholder={t("commentPlaceholder")}- aria-invalid={!!formState.errors.content}- {...register("content", { validate: requiredString })}- onKeyDown={(e) => {- if (e.key === "Enter" && !e.shiftKey) {- e.preventDefault();- e.currentTarget.form?.requestSubmit();- }- }}- />- <InputGroupAddon align="inline-end" className="pb-1.5">+ <InputGroupTextarea+ id="comment"+ className="max-h-40 min-h-9"+ maxLength={MAX_COMMENT_LENGTH}+ placeholder={t("commentsComposerPlaceholder", {+ defaultValue: "Write a comment…",+ })}+ aria-invalid={!!formState.errors.content}+ {...register("content", { validate: requiredString })}+ onKeyDown={(e) => {+ if (e.key === "Enter" && !e.shiftKey) {+ e.preventDefault();+ e.currentTarget.form?.requestSubmit();+ }+ }}+ />+ <InputGroupAddon align="block-end">+ <InputGroupText className="text-muted-foreground text-xs">+ <EyeIcon />+ <Trans+ i18nKey="commentsComposerVisibility"+ defaults="Visible to everyone"+ />+ </InputGroupText>+ <div className="ml-auto flex items-center gap-2"><MaxCharLengthlength={contentLength}maxLength={MAX_COMMENT_LENGTH}@@ -164,13 +181,14 @@ function NewCommentForm({ onSubmitted }: { onSubmitted: () => void }) {<InputGroupButtontype="submit"size="icon-sm"+ variant="primary"aria-label={t("addComment", { defaultValue: "Add comment" })}loading={formState.isSubmitting}>- <CornerDownLeftIcon />+ <ArrowUpIcon /></InputGroupButton>- </InputGroupAddon>- </div>+ </div>+ </InputGroupAddon></InputGroup></form>);@@ -220,22 +238,33 @@ function CommentsSheetInner({ className }: { className?: string }) {const count = comments?.length ?? 0;+ const sortedComments = React.useMemo(+ () =>+ comments+ ? [...comments].sort(+ (a, b) =>+ new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),+ )+ : [],+ [comments],+ );+return (<>- <Button className={className} onClick={() => dialog.trigger()}>+ <Button className={className} size="lg" onClick={() => dialog.trigger()}><MessageCircleIcon data-icon="inline-start" />- <Trans i18nKey="comments" defaults="Comments" />- {count > 0 ? <Badge>{count}</Badge> : null}+ <Trans+ i18nKey="commentsTriggerLabel"+ defaults="{count, plural, =0 {Comments} one {1 Comment} other {# Comments}}"+ values={{ count }}+ /></Button><Sheet {...dialog.dialogProps}>- <SheetContent className="flex flex-col sm:max-w-md">+ <SheetContent className="flex flex-col p-4 sm:max-w-md sm:p-6"><SheetHeader>- <div className="flex items-center gap-2">- <SheetTitle>- <Trans i18nKey="comments" defaults="Comments" />- </SheetTitle>- {count > 0 ? <Badge>{count}</Badge> : null}- </div>+ <SheetTitle>+ <Trans i18nKey="comments" defaults="Comments" />+ </SheetTitle><SheetDescription className="sr-only"><Transi18nKey="commentsSheetDescription"@@ -243,17 +272,36 @@ function CommentsSheetInner({ className }: { className?: string }) {/></SheetDescription></SheetHeader>- <div className="-mx-6 -mb-6 flex grow flex-col overflow-y-auto px-6">- <div className="flex grow flex-col">+ {!poll.event ? (+ <div className="pb-4">+ {hasCommented ? (+ <div className="flex items-center gap-2 rounded-lg border bg-muted/50 p-3 text-muted-foreground text-sm">+ <CheckCircle2Icon className="size-4 text-green-600 dark:text-green-500" />+ <Trans+ i18nKey="commentsSheetSubmitted"+ defaults="Your comment has been added"+ />+ </div>+ ) : (+ <NewCommentForm onSubmitted={() => setHasCommented(true)} />+ )}+ </div>+ ) : null}+ <div className="-mx-4 -mb-4 flex grow flex-col overflow-y-auto border-t px-4 pt-4 sm:-mx-6 sm:-mb-6 sm:px-6">+ <div className="flex grow flex-col pb-4 sm:pb-6">{count > 0 ? (- <div className="space-y-4">- {comments?.map((comment) => {+ <div className="divide-y">+ {sortedComments.map((comment) => {const canDelete =role === "admin" || session.ownsObject(comment);return (- <div data-testid="comment" key={comment.id}>- <div className="mb-1 flex items-center space-x-2">+ <div+ data-testid="comment"+ key={comment.id}+ className="py-4 first:pt-0 last:pb-0"+ >+ <div className="relative mb-1 flex items-center gap-x-2 text-foreground"><Participant><OptimizedAvatarImagename={comment.authorName}@@ -268,77 +316,73 @@ function CommentsSheetInner({ className }: { className?: string }) {</Badge>) : null}</Participant>- <div className="flex items-center gap-2 text-sm">- <div className="text-muted-foreground">- <RelativeTime value={comment.createdAt} />- </div>- {canDelete && (- <DropdownMenu>- <DropdownMenuTrigger- render={- <Button- aria-label={t("moreOptions", {- defaultValue: "More options",- })}- variant="ghost"- size="icon-xs"- />- }+ {canDelete && (+ <DropdownMenu>+ <DropdownMenuTrigger+ render={+ <Button+ // Out of flow: the menu mounts focus-guard+ // spans into the row, which would re-target+ // space-x-2's not-last-child margin and+ // shift an in-flow trigger while open.+ className="absolute top-1/2 right-0 -translate-y-1/2 text-muted-foreground"+ aria-label={t("moreOptions", {+ defaultValue: "More options",+ })}+ variant="ghost"+ size="icon-xs"+ />+ }+ >+ <MoreHorizontalIcon />+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <DropdownMenuItem+ variant="destructive"+ onClick={() => {+ deleteComment.mutate({+ commentId: comment.id,+ token,+ });+ }}>- <MoreHorizontalIcon />- </DropdownMenuTrigger>- <DropdownMenuContent align="start">- <DropdownMenuItem- variant="destructive"- onClick={() => {- deleteComment.mutate({- commentId: comment.id,- token,- });- }}- >- <TrashIcon />- <Trans i18nKey="delete" />- </DropdownMenuItem>- </DropdownMenuContent>- </DropdownMenu>- )}- </div>+ <TrashIcon />+ <Trans i18nKey="delete" />+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ )}</div>- <div className="w-fit whitespace-pre-wrap pl-8 text-sm leading-relaxed">+ <div className="w-fit whitespace-pre-wrap pl-8 text-foreground text-sm leading-relaxed"><TruncatedLinkify>{comment.content}</TruncatedLinkify></div>+ <div className="mt-2 pl-8 text-muted-foreground text-xs dark:text-muted-foreground/75">+ <RelativeTime value={comment.createdAt} />+ </div></div>);})}</div>) : (- <div className="flex grow flex-col items-center justify-center gap-2 text-center">- <MessageCircleIcon className="size-5 text-muted-foreground" />- <p className="text-muted-foreground text-sm">+ <EmptyState className="grow">+ <EmptyStateIcon>+ <MessageCircleIcon />+ </EmptyStateIcon>+ <EmptyStateTitle><Transi18nKey="commentsSheetEmpty"defaults="No comments yet"/>- </p>- </div>- )}- </div>- {!poll.event ? (- <div className="sticky bottom-0 pt-3 pb-6">- {hasCommented ? (- <div className="flex items-center gap-2 rounded-lg border bg-background p-3 text-muted-foreground text-sm shadow-lg dark:bg-card">- <CheckCircle2Icon className="size-4 text-green-600 dark:text-green-500" />+ </EmptyStateTitle>+ <EmptyStateDescription><Trans- i18nKey="commentsSheetSubmitted"- defaults="Your comment has been added"+ i18nKey="commentsSheetEmptyDescription"+ defaults="Be the first to share your thoughts on this poll."/>- </div>- ) : (- <NewCommentForm onSubmitted={() => setHasCommented(true)} />- )}- </div>- ) : null}+ </EmptyStateDescription>+ </EmptyState>+ )}+ </div></div></SheetContent></Sheet>diff --git a/apps/web/src/features/poll/components/mobile-poll.tsx b/apps/web/src/features/poll/components/mobile-poll.tsxindex 555283ba2..6419d0d1c 100644--- a/apps/web/src/features/poll/components/mobile-poll.tsx+++ b/apps/web/src/features/poll/components/mobile-poll.tsx@@ -1,3 +1,4 @@+import { cn } from "@rallly/ui";import { Badge } from "@rallly/ui/badge";import { Button } from "@rallly/ui/button";import { Card } from "@rallly/ui/card";@@ -12,7 +13,7 @@ import {import { MoreHorizontalIcon, PlusIcon, UsersIcon } from "lucide-react";import { AnimatePresence } from "motion/react";import * as m from "motion/react-m";-import type * as React from "react";+import * as React from "react";import smoothscroll from "smoothscroll-polyfill";import { TimesShownIn } from "@/components/clock";@@ -61,6 +62,25 @@ const MobilePoll: React.FunctionComponent = () => {const isEditing = votingForm.watch("mode") !== "view";+ // True while the sticky footer is pinned to the viewport (floating over+ // the option list) rather than resting at the card's end. Tracked via a+ // sentinel after the footer: while the card's end is off-screen, the+ // footer is stuck.+ const footerSentinelRef = React.useRef<HTMLDivElement>(null);+ const [isFooterFloating, setIsFooterFloating] = React.useState(true);++ React.useEffect(() => {+ const sentinel = footerSentinelRef.current;+ if (!sentinel) {+ return;+ }+ const observer = new IntersectionObserver(([entry]) => {+ setIsFooterFloating(!entry.isIntersecting);+ });+ observer.observe(sentinel);+ return () => observer.disconnect();+ }, []);+const { t } = useTranslation();const participantOptions = [@@ -237,10 +257,20 @@ const MobilePoll: React.FunctionComponent = () => {transition: { duration: 0.2 },}}>- <VotingFooter className="px-3 pb-3" />+ {/* While floating, 3px + the page's p-3 and the card's 1px+ border puts the footer's edges at 16px from the viewport,+ flush with the floating comments button (right-4). At rest+ it returns to the card's normal inset. */}+ <VotingFooter+ className={cn(+ "pb-3 transition-[padding] duration-200 ease-out",+ isFooterFloating ? "px-[3px]" : "px-3",+ )}+ /></m.div>) : null}</AnimatePresence>+ <div ref={footerSentinelRef} aria-hidden="true" /></Card>);};diff --git a/apps/web/tests/poll-page.ts b/apps/web/tests/poll-page.tsindex a230c72ca..3af99a132 100644--- a/apps/web/tests/poll-page.ts+++ b/apps/web/tests/poll-page.ts@@ -26,9 +26,7 @@ export class PollPage {await page.getByRole("button", { name: "Comments" }).click();const sheet = page.getByRole("dialog", { name: "Comments" });- await sheet- .getByPlaceholder("Leave a comment on this poll")- .fill("This is a comment!");+ await sheet.getByPlaceholder("Write a comment").fill("This is a comment!");await sheet.getByPlaceholder("Your name…").fill("Test user");await sheet.getByRole("button", { name: "Add comment" }).click();