Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

♻️ Refactor poll header implementation (#2291)

Luke Vellad6b82accfe72
diff --git a/apps/web/src/components/poll/desktop-poll.tsx b/apps/web/src/components/poll/desktop-poll.tsx
index 94c8e5c02..f62cbe1ce 100644
--- a/apps/web/src/components/poll/desktop-poll.tsx
+++ b/apps/web/src/components/poll/desktop-poll.tsx
@@ -202,48 +202,48 @@ const DesktopPoll: React.FunctionComponent = () => {
<Trans i18nKey="scrollRight" defaults="Scroll Right" />
</TooltipContent>
</Tooltip>
+ {expanded ? (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button
+ variant="ghost"
+ size="icon"
+ onClick={() => {
+ collapse();
+ }}
+ >
+ <Icon>
+ <ShrinkIcon />
+ </Icon>
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>
+ <Trans i18nKey="shrink" defaults="Shrink" />
+ </TooltipContent>
+ </Tooltip>
+ ) : (
+ <Tooltip delayDuration={0}>
+ <TooltipTrigger asChild>
+ <Button
+ variant="ghost"
+ size="icon"
+ onClick={() => {
+ expand();
+ }}
+ >
+ <Icon>
+ <ExpandIcon />
+ </Icon>
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>
+ <Trans i18nKey="expand" defaults="Expand" />
+ </TooltipContent>
+ </Tooltip>
+ )}
+ {expanded ? <EscapeListener onEscape={collapse} /> : null}
</>
) : null}
- {expanded ? (
- <Tooltip>
- <TooltipTrigger asChild>
- <Button
- variant="ghost"
- size="icon"
- onClick={() => {
- collapse();
- }}
- >
- <Icon>
- <ShrinkIcon />
- </Icon>
- </Button>
- </TooltipTrigger>
- <TooltipContent>
- <Trans i18nKey="shrink" defaults="Shrink" />
- </TooltipContent>
- </Tooltip>
- ) : (
- <Tooltip delayDuration={0}>
- <TooltipTrigger asChild>
- <Button
- variant="ghost"
- size="icon"
- onClick={() => {
- expand();
- }}
- >
- <Icon>
- <ExpandIcon />
- </Icon>
- </Button>
- </TooltipTrigger>
- <TooltipContent>
- <Trans i18nKey="expand" defaults="Expand" />
- </TooltipContent>
- </Tooltip>
- )}
- {expanded ? <EscapeListener onEscape={collapse} /> : null}
</div>
</div>
);
diff --git a/apps/web/src/components/poll/desktop-poll/participant-row.tsx b/apps/web/src/components/poll/desktop-poll/participant-row.tsx
index 1d3583532..5b076f073 100644
--- a/apps/web/src/components/poll/desktop-poll/participant-row.tsx
+++ b/apps/web/src/components/poll/desktop-poll/participant-row.tsx
@@ -95,7 +95,6 @@ export const ParticipantRowView: React.FunctionComponent<{
</td>
);
})}
- <td className="border-l" />
</tr>
);
};
diff --git a/apps/web/src/components/poll/desktop-poll/poll-header.tsx b/apps/web/src/components/poll/desktop-poll/poll-header.tsx
index 65c6b2a29..cf095964f 100644
--- a/apps/web/src/components/poll/desktop-poll/poll-header.tsx
+++ b/apps/web/src/components/poll/desktop-poll/poll-header.tsx
@@ -47,11 +47,10 @@ const TimelineRow = ({
return (
<tr>
<th
- style={{ minWidth: 235, top }}
+ style={{ minWidth: 235, width: 300, top }}
className="sticky left-0 z-30 bg-background pr-4 pl-4"
/>
{children}
- <th className="w-full min-w-4 border-l" />
</tr>
);
};
@@ -61,42 +60,38 @@ const dayRowHeight = 60;
const scoreRowTop = monthRowHeight + dayRowHeight;
-const PollHeader: React.FunctionComponent = () => {
+const PollHeader = () => {
const { options } = useOptions();
+
+ const monthGroups: { month: string; year: string; count: number }[] = [];
+
+ for (const option of options) {
+ const last = monthGroups[monthGroups.length - 1];
+ if (last?.month === option.month && last?.year === option.year) {
+ last.count++;
+ } else {
+ monthGroups.push({ month: option.month, year: option.year, count: 1 });
+ }
+ }
+
return (
<>
<TimelineRow top={0}>
- {options.map((option, i) => {
- const firstOfMonth =
- i === 0 ||
- options[i - 1]?.month !== option.month ||
- options[i - 1]?.year !== option.year;
-
- return (
- <th
- key={option.optionId}
- style={{ height: monthRowHeight }}
- className={cn(
- "sticky top-0 space-y-3 bg-background",
- firstOfMonth
- ? "left-[235px] z-20 border-card-border border-l"
- : "z-10",
- )}
- >
- <div className="flex">
- <div
- className={cn(
- "inline-flex h-5 gap-1 px-2 py-0.5 font-medium text-xs uppercase",
- firstOfMonth ? "opacity-100" : "opacity-0",
- )}
- >
- <span>{option.month}</span>
- <span className="text-muted-foreground">{option.year}</span>
- </div>
- </div>
- </th>
- );
- })}
+ {monthGroups.map((group) => (
+ <th
+ key={`${group.month} ${group.year}`}
+ colSpan={group.count}
+ style={{ height: monthRowHeight }}
+ className={cn(
+ "sticky top-0 z-10 border-card-border border-l bg-background",
+ )}
+ >
+ <div className="sticky right-0 left-[235px] inline-flex h-5 gap-1 px-2 py-0.5 font-medium text-xs uppercase">
+ <span>{group.month}</span>
+ <span className="text-muted-foreground">{group.year}</span>
+ </div>
+ </th>
+ ))}
</TimelineRow>
<TimelineRow top={monthRowHeight}>
{options.map((option, i) => {
@@ -116,7 +111,6 @@ const PollHeader: React.FunctionComponent = () => {
key={option.optionId}
style={{
minWidth: 80,
- width: 80,
height: dayRowHeight,
left: firstOfDay && !lastOfDay ? 235 : 0,
top: monthRowHeight,
@@ -146,7 +140,7 @@ const PollHeader: React.FunctionComponent = () => {
return (
<th
key={option.optionId}
- style={{ minWidth: 80, maxWidth: 90, top: scoreRowTop }}
+ style={{ minWidth: 80, top: scoreRowTop }}
className="sticky z-20 border-b border-l bg-background pb-2.5 align-top"
>
<div className="flex flex-col items-center gap-3">