Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(meetings): add next meeting badge to calendar sidebar button (#7718)

Jacob Beckerman66171bf7eed2
diff --git a/apps/web/src/components/app/sidebar-next/list-nav.tsx b/apps/web/src/components/app/sidebar-next/list-nav.tsx
index 78984a6df7..a9c7207fd9 100644
--- a/apps/web/src/components/app/sidebar-next/list-nav.tsx
+++ b/apps/web/src/components/app/sidebar-next/list-nav.tsx
@@ -22,6 +22,8 @@ export type ListNavProps = {
item: SidebarNextNavItem;
unread?: boolean;
activeCall?: boolean;
+ /** A short status pill under the glyph, e.g. `Now` or `12m`. */
+ badge?: string;
onContextMenuOpenChange?: (open: boolean) => void;
};
@@ -204,7 +206,11 @@ export const ListNav = (props: ListNavProps) => {
)}
label={props.item.label}
aria-description={
- [props.unread && 'Unread items', props.activeCall && 'Active call']
+ [
+ props.unread && 'Unread items',
+ props.activeCall && 'Active call',
+ props.badge && `Next meeting: ${props.badge}`,
+ ]
.filter(Boolean)
.join('. ') || undefined
}
@@ -219,6 +225,7 @@ export const ListNav = (props: ListNavProps) => {
data-sidebar-next-item={props.item.id}
data-unread={props.unread ? '' : undefined}
data-active-call={props.activeCall ? '' : undefined}
+ data-badge={props.badge}
onMouseDown={onMouseDown}
onClick={onClick}
>
@@ -242,6 +249,17 @@ export const ListNav = (props: ListNavProps) => {
<PhoneCallIcon class="size-full" />
</span>
</Show>
+ <Show when={props.badge}>
+ {(badge) => (
+ <span
+ aria-hidden="true"
+ data-sidebar-badge
+ class="pointer-events-none absolute bottom-0 left-1/2 -translate-x-1/2 rounded-full bg-accent px-1 text-[9px] font-semibold leading-3 text-surface ring-2 ring-panel"
+ >
+ {badge()}
+ </span>
+ )}
+ </Show>
</Button>
</SidebarOpenInSplitMenu>
);
diff --git a/apps/web/src/components/app/sidebar-next/queries/use-next-meeting-badge.ts b/apps/web/src/components/app/sidebar-next/queries/use-next-meeting-badge.ts
new file mode 100644
index 0000000000..d199cfe146
--- /dev/null
+++ b/apps/web/src/components/app/sidebar-next/queries/use-next-meeting-badge.ts
@@ -0,0 +1,31 @@
+import { useCalendarSources } from '@app/features/calendar/hooks/use-calendar-sources';
+import { useCalendarPreferences } from '@app/features/calendar/utils/preferences';
+import { nextMeetingBadge } from '@app/features/meetings/core/next-meeting-badge';
+import { createCallSidebarClock } from '@app/features/meetings/primitives/call-sidebar';
+import { useUpcomingCalendarEventsSource } from '@app/features/meetings/queries/upcoming-calendar-events';
+import { useUserId } from '@core/context/user';
+import { createMemo } from 'solid-js';
+
+/**
+ * The Calendar button's badge: `Now` during a meeting, minutes until the next
+ * one when it is under an hour away. Reads the same visible calendars and
+ * upcoming-events source as the calendar view's agenda, so a calendar hidden
+ * there never counts here. Mount it only where Calendar is on the rail — it
+ * starts fetching on mount.
+ */
+export function useNextMeetingBadge() {
+ const userId = useUserId();
+ const now = createCallSidebarClock();
+ const { sourceById } = useCalendarSources();
+ const [preferences] = useCalendarPreferences();
+ const hiddenSourceIds = createMemo(
+ () => new Set(preferences.hiddenSourceIds)
+ );
+ const upcoming = useUpcomingCalendarEventsSource({
+ userId,
+ sourceById,
+ isSourceVisible: (sourceId) => !hiddenSourceIds().has(sourceId),
+ now,
+ });
+ return createMemo(() => nextMeetingBadge(upcoming.events(), now()));
+}
diff --git a/apps/web/src/components/app/sidebar-next/sidebar-rail.tsx b/apps/web/src/components/app/sidebar-next/sidebar-rail.tsx
index 08a62d1d4c..acba381e3e 100644
--- a/apps/web/src/components/app/sidebar-next/sidebar-rail.tsx
+++ b/apps/web/src/components/app/sidebar-next/sidebar-rail.tsx
@@ -7,12 +7,13 @@ import { useSplitLayout } from '@components/app/split-layout/layout';
import { hotkeyScopeNeutralAttribute } from '@core/dom-selectors';
import { isPlatform } from '@core/util/platform';
import { cn } from '@ui';
-import { createEffect, For, Show, Suspense } from 'solid-js';
+import { createEffect, For, Match, Suspense, Switch } from 'solid-js';
import { SidebarRailCreateButton } from './create-button';
import { FooterActions } from './footer-actions';
import { ListNav, type ListNavProps } from './list-nav';
import { MoreMenu } from './more-menu';
import { visibleNavItems } from './nav-items';
+import { useNextMeetingBadge } from './queries/use-next-meeting-badge';
import { useSidebarUnread } from './queries/use-sidebar-unread';
import { SearchRailButton } from './search-bar-button';
import { useNavItemGates } from './use-nav-item-gates';
@@ -23,6 +24,11 @@ function ChannelsListNav(props: Omit<ListNavProps, 'activeCall'>) {
return <ListNav {...props} activeCall={hasActiveCall()} />;
}
+function CalendarListNav(props: Omit<ListNavProps, 'badge'>) {
+ const badge = useNextMeetingBadge();
+ return <ListNav {...props} badge={badge()?.label} />;
+}
+
/**
* The app sidebar: a single always-narrow column of 40px icon buttons, labels
* in tooltips.
@@ -82,18 +88,27 @@ const SidebarRailContent = () => {
<For each={visibleNavItems(gates())}>
{(item) => (
<li class="flex">
- <Show
- when={item.id === 'channels'}
+ <Switch
fallback={<ListNav item={item} unread={hasUnread(item.id)} />}
>
- <Suspense
- fallback={
- <ListNav item={item} unread={hasUnread(item.id)} />
- }
- >
- <ChannelsListNav item={item} unread={hasUnread(item.id)} />
- </Suspense>
- </Show>
+ <Match when={item.id === 'channels'}>
+ <Suspense
+ fallback={
+ <ListNav item={item} unread={hasUnread(item.id)} />
+ }
+ >
+ <ChannelsListNav
+ item={item}
+ unread={hasUnread(item.id)}
+ />
+ </Suspense>
+ </Match>
+ <Match when={item.id === 'calendar'}>
+ <Suspense fallback={<ListNav item={item} />}>
+ <CalendarListNav item={item} />
+ </Suspense>
+ </Match>
+ </Switch>
</li>
)}
</For>
diff --git a/apps/web/src/features/meetings/core/next-meeting-badge.test.ts b/apps/web/src/features/meetings/core/next-meeting-badge.test.ts
new file mode 100644
index 0000000000..0771ee8fe1
--- /dev/null
+++ b/apps/web/src/features/meetings/core/next-meeting-badge.test.ts
@@ -0,0 +1,129 @@
+import { describe, expect, it } from 'vitest';
+import { nextMeetingBadge } from './next-meeting-badge';
+import type { UpcomingCalendarEvent } from './upcoming-calendar-events';
+
+const NOW = new Date('2026-10-07T15:00:00Z');
+
+const event = (
+ start: string,
+ end: string,
+ overrides: Partial<UpcomingCalendarEvent> = {}
+): UpcomingCalendarEvent => ({
+ id: `${start}-${end}`,
+ title: 'Standup',
+ color: '#000',
+ start,
+ end,
+ allDay: false,
+ eventId: `${start}-${end}`,
+ occurrenceKey: '',
+ ...overrides,
+});
+
+describe('nextMeetingBadge', () => {
+ it('shows nothing without events', () => {
+ expect(nextMeetingBadge([], NOW)).toBeUndefined();
+ });
+
+ it('shows Now while a meeting is in progress', () => {
+ expect(
+ nextMeetingBadge(
+ [event('2026-10-07T14:30:00Z', '2026-10-07T15:30:00Z')],
+ NOW
+ )
+ ).toEqual({ kind: 'now', label: 'Now' });
+ });
+
+ it('shows Now at the start instant and not at the end instant', () => {
+ expect(
+ nextMeetingBadge(
+ [event('2026-10-07T15:00:00Z', '2026-10-07T15:30:00Z')],
+ NOW
+ )?.kind
+ ).toBe('now');
+ expect(
+ nextMeetingBadge(
+ [event('2026-10-07T14:30:00Z', '2026-10-07T15:00:00Z')],
+ NOW
+ )
+ ).toBeUndefined();
+ });
+
+ it('counts minutes to the next meeting inside the hour', () => {
+ expect(
+ nextMeetingBadge(
+ [event('2026-10-07T15:12:00Z', '2026-10-07T15:42:00Z')],
+ NOW
+ )
+ ).toEqual({ kind: 'soon', label: '12m', minutes: 12 });
+ });
+
+ it('rounds a partial minute up so the badge never reads 0m', () => {
+ expect(
+ nextMeetingBadge(
+ [event('2026-10-07T15:00:20Z', '2026-10-07T15:30:00Z')],
+ NOW
+ )
+ ).toMatchObject({ kind: 'soon', label: '1m' });
+ });
+
+ it('stays hidden at an hour or more', () => {
+ expect(
+ nextMeetingBadge(
+ [event('2026-10-07T16:00:00Z', '2026-10-07T16:30:00Z')],
+ NOW
+ )
+ ).toBeUndefined();
+ expect(
+ nextMeetingBadge(
+ [event('2026-10-07T15:59:00Z', '2026-10-07T16:30:00Z')],
+ NOW
+ )
+ ).toMatchObject({ label: '59m' });
+ });
+
+ it('picks the soonest upcoming meeting regardless of order', () => {
+ expect(
+ nextMeetingBadge(
+ [
+ event('2026-10-07T15:40:00Z', '2026-10-07T16:00:00Z'),
+ event('2026-10-07T15:20:00Z', '2026-10-07T15:30:00Z'),
+ ],
+ NOW
+ )
+ ).toMatchObject({ label: '20m' });
+ });
+
+ it('prefers Now over an upcoming meeting', () => {
+ expect(
+ nextMeetingBadge(
+ [
+ event('2026-10-07T15:10:00Z', '2026-10-07T15:30:00Z'),
+ event('2026-10-07T14:50:00Z', '2026-10-07T15:20:00Z'),
+ ],
+ NOW
+ )?.kind
+ ).toBe('now');
+ });
+
+ it('ignores all-day events', () => {
+ expect(
+ nextMeetingBadge(
+ [event('2026-10-07', '2026-10-08', { allDay: true })],
+ NOW
+ )
+ ).toBeUndefined();
+ });
+
+ it('ignores events with unparseable or inverted times', () => {
+ expect(
+ nextMeetingBadge(
+ [
+ event('nope', '2026-10-07T15:30:00Z'),
+ event('2026-10-07T15:20:00Z', '2026-10-07T15:10:00Z'),
+ ],
+ NOW
+ )
+ ).toBeUndefined();
+ });
+});
diff --git a/apps/web/src/features/meetings/core/next-meeting-badge.ts b/apps/web/src/features/meetings/core/next-meeting-badge.ts
new file mode 100644
index 0000000000..4093bee4d4
--- /dev/null
+++ b/apps/web/src/features/meetings/core/next-meeting-badge.ts
@@ -0,0 +1,35 @@
+import type { UpcomingCalendarEvent } from './upcoming-calendar-events';
+
+/** How far ahead of a meeting the badge starts counting down. */
+export const NEXT_MEETING_BADGE_HORIZON_MS = 60 * 60_000;
+
+export type NextMeetingBadge =
+ | { kind: 'now'; label: 'Now' }
+ | { kind: 'soon'; label: string; minutes: number };
+
+/**
+ * The sidebar badge for the current moment: `Now` while a timed event is in
+ * progress, else the minutes until the next timed event when it is under an
+ * hour away. All-day events are ignored — they never mark a meeting.
+ */
+export function nextMeetingBadge(
+ events: readonly UpcomingCalendarEvent[],
+ now: Date
+): NextMeetingBadge | undefined {
+ const nowMs = now.getTime();
+ let soonest = Number.POSITIVE_INFINITY;
+ for (const event of events) {
+ if (event.allDay) continue;
+ const start = Date.parse(event.start);
+ const end = Date.parse(event.end);
+ if (!Number.isFinite(start) || !Number.isFinite(end) || end <= start) {
+ continue;
+ }
+ if (start <= nowMs && nowMs < end) return { kind: 'now', label: 'Now' };
+ if (start > nowMs) soonest = Math.min(soonest, start);
+ }
+ const untilMs = soonest - nowMs;
+ if (untilMs >= NEXT_MEETING_BADGE_HORIZON_MS) return undefined;
+ const minutes = Math.ceil(untilMs / 60_000);
+ return { kind: 'soon', label: `${minutes}m`, minutes };
+}