Skip to content

Commit 46b1ba5

Browse files
committed
Improve ongoing event and stay labeling
1 parent 8d36e44 commit 46b1ba5

3 files changed

Lines changed: 39 additions & 25 deletions

File tree

app/web/features/dashboard/EventListRow.tsx

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,19 @@ const DateChip = styled("div")({
5252
},
5353
});
5454

55-
const DateMonth = styled("div")({
56-
fontSize: "9px",
57-
textTransform: "uppercase",
58-
letterSpacing: "0.08em",
59-
color: "var(--mui-palette-secondary-main)",
60-
fontWeight: 700,
61-
lineHeight: 1.2,
62-
"[data-today] &": {
63-
color: "var(--mui-palette-primary-main)",
64-
},
65-
});
55+
const DateMonth = styled("div")<{ $labelFontSize?: number }>(
56+
({ $labelFontSize }) => ({
57+
fontSize: $labelFontSize ? `${$labelFontSize}px` : "9px",
58+
textTransform: "uppercase",
59+
letterSpacing: "0.08em",
60+
color: "var(--mui-palette-secondary-main)",
61+
fontWeight: 700,
62+
lineHeight: 1.2,
63+
"[data-today] &": {
64+
color: "var(--mui-palette-primary-main)",
65+
},
66+
}),
67+
);
6668

6769
const DateDay = styled("div")({
6870
fontSize: "16px",
@@ -170,11 +172,16 @@ export default function EventListRow({ event }: EventListRowProps) {
170172
i18n: { language: locale },
171173
} = useTranslation([DASHBOARD]);
172174

175+
const now = new Date();
173176
const startDate = timestamp2Date(event.startTime!);
174-
const isToday = startDate.toDateString() === new Date().toDateString();
177+
const endDate = event.endTime ? timestamp2Date(event.endTime) : null;
178+
const isOngoing = endDate !== null && startDate <= now && endDate >= now;
179+
const isToday = !isOngoing && startDate.toDateString() === now.toDateString();
175180
const todayLabel = t("dashboard:events.today_label");
176-
const todayFontSize =
177-
todayLabel.length <= 5 ? 9 : todayLabel.length <= 7 ? 8 : 7;
181+
const nowLabel = t("dashboard:now_label");
182+
const chipLabel = isOngoing ? nowLabel : todayLabel;
183+
const chipFontSize =
184+
chipLabel.length <= 5 ? 9 : chipLabel.length <= 7 ? 8 : 7;
178185
const month = localizeMonthAbbreviation(startDate, {
179186
locale,
180187
timezone: BROWSER_TIMEZONE,
@@ -194,11 +201,13 @@ export default function EventListRow({ event }: EventListRowProps) {
194201

195202
return (
196203
<RowLink href={routeToEvent(event.eventId, event.slug)}>
197-
<DateChip data-today={isToday || undefined}>
198-
<DateMonth style={isToday ? { fontSize: todayFontSize } : undefined}>
199-
{isToday ? todayLabel : month}
204+
<DateChip data-today={isToday || isOngoing || undefined}>
205+
<DateMonth
206+
$labelFontSize={isToday || isOngoing ? chipFontSize : undefined}
207+
>
208+
{isOngoing ? nowLabel : isToday ? todayLabel : month}
200209
</DateMonth>
201-
{!isToday && <DateDay>{day}</DateDay>}
210+
{!isToday && !isOngoing && <DateDay>{day}</DateDay>}
202211
</DateChip>
203212
<ContentWrapper>
204213
<TitleRow>

app/web/features/dashboard/UpcomingStayCard.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ interface UpcomingStayCardProps {
8989
hostRequest: HostRequest.AsObject;
9090
}
9191

92-
function daysUntilLabel(days: number, locale: string): string {
93-
return localizeRelativeDays(days, locale);
94-
}
95-
9692
export function UpcomingStayCardSkeleton() {
9793
return (
9894
<Box
@@ -150,8 +146,15 @@ export default function UpcomingStayCard({
150146
const fromDate = dayjs.tz(hostRequest.fromDate, UTC_TIMEZONE);
151147
const toDate = dayjs.tz(hostRequest.toDate, UTC_TIMEZONE);
152148
const nights = toDate.diff(fromDate, "day");
153-
const daysUntil = fromDate.diff(dayjs().tz(timezone).startOf("day"), "day");
149+
const today = dayjs().tz(timezone).startOf("day");
150+
const daysUntil = fromDate.diff(today, "day");
151+
const daysUntilEnd = toDate.diff(today, "day");
152+
const isOngoing = daysUntil <= 0 && daysUntilEnd >= 0;
154153
const isImminent = daysUntil <= 3;
154+
const relativeDaysLabel = (() => {
155+
const label = localizeRelativeDays(daysUntil, locale);
156+
return label.charAt(0).toUpperCase() + label.slice(1);
157+
})();
155158

156159
const dateRange = localizeDateTimeRange(fromDate, toDate, {
157160
timezone: UTC_TIMEZONE,
@@ -218,7 +221,9 @@ export default function UpcomingStayCard({
218221
</Typography>
219222
</TextBlock>
220223
{isImminent && (
221-
<DaysChip imminent>{daysUntilLabel(daysUntil, locale)}</DaysChip>
224+
<DaysChip imminent>
225+
{isOngoing ? t("dashboard:now_label") : relativeDaysLabel}
226+
</DaysChip>
222227
)}
223228
</IdentityRow>
224229
<MetaRow>

app/web/features/dashboard/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"hero_image_attribution": "Photo by <1>Mesut Kaya</1> on <3>Unsplash</3>",
4646
"prev_page_button_a11y": "Previous page",
4747
"next_page_button_a11y": "Next page",
48+
"now_label": "Now",
4849
"discussions": {
4950
"community_header": "Discussions in your communities",
5051
"community_empty_message": "No discussions yet in your communities.",
@@ -64,7 +65,6 @@
6465
"upcoming_guests_header": "Your upcoming guests",
6566
"night_count_one": "{{count}} night",
6667
"night_count_other": "{{count}} nights",
67-
6868
"no_upcoming_trips": "No upcoming trips. Ready to explore?",
6969
"no_upcoming_guests": "No upcoming guests yet."
7070
},

0 commit comments

Comments
 (0)