Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: Show calendar events on every day they occupy (#8212)

[._.]/ Adam Eivycf67706ab748
diff --git a/client/src/components/calendar/DayView.jsx b/client/src/components/calendar/DayView.jsx
index 18eae69539..0e7ec26144 100644
--- a/client/src/components/calendar/DayView.jsx
+++ b/client/src/components/calendar/DayView.jsx
@@ -4,89 +4,14 @@ import * as api from '../../services/api';
import socket from '../../services/socket';
import EventDetail from './EventDetail';
import ChronotypeOverlay from './ChronotypeOverlay';
-import { buildSubcalendarColorMap, eventChipStyle, getEventDayMinutes } from './calendarUtils';
+import { buildSubcalendarColorMap, eventChipStyle, eventOccursOnDay } from './calendarUtils';
+import { HOURS, PX_PER_HOUR, PX_PER_15MIN, START_HOUR, eventKey, getEventPosition, layoutEvents } from './calendarTimeGrid';
import { formatDateFull, formatHourOfDay } from '../../utils/formatters';
import BrailleSpinner from '../BrailleSpinner';
import EmptyState from '../EmptyState';
import { useThemeContext } from '../ThemeContext';
import useUrlParams from '../../hooks/useUrlParams';
-const START_HOUR = 0;
-const END_HOUR = 24;
-const HOURS = Array.from({ length: END_HOUR - START_HOUR }, (_, i) => i + START_HOUR);
-const PX_PER_HOUR = 80;
-const PX_PER_15MIN = PX_PER_HOUR / 4; // 20px per 15-min block
-const START_MINUTES = START_HOUR * 60;
-
-function getEventPosition(event, day) {
- const { startMin, endMin } = getEventDayMinutes(event, day);
- const top = ((startMin - START_MINUTES) / 60) * PX_PER_HOUR;
- const height = Math.min(
- Math.max(((endMin - startMin) / 60) * PX_PER_HOUR, PX_PER_15MIN),
- HOURS.length * PX_PER_HOUR - top,
- );
- return { top, height };
-}
-
-/**
- * Assign columns to overlapping events so they render side-by-side.
- * Returns a Map of eventKey -> { column, totalColumns }
- */
-function layoutEvents(events, day) {
- const items = events.map(e => {
- const { startMin, endMin } = getEventDayMinutes(e, day);
- return { event: e, startMin, endMin: Math.max(endMin, startMin + 15) };
- }).sort((a, b) => a.startMin - b.startMin || a.endMin - b.endMin);
-
- const groups = []; // groups of overlapping events
- let currentGroup = [];
- let groupEnd = -1;
-
- for (const item of items) {
- if (currentGroup.length === 0 || item.startMin < groupEnd) {
- currentGroup.push(item);
- groupEnd = Math.max(groupEnd, item.endMin);
- } else {
- groups.push(currentGroup);
- currentGroup = [item];
- groupEnd = item.endMin;
- }
- }
- if (currentGroup.length > 0) groups.push(currentGroup);
-
- const layout = new Map();
- for (const group of groups) {
- // Assign columns greedily
- const columns = [];
- for (const item of group) {
- let placed = false;
- for (let col = 0; col < columns.length; col++) {
- if (columns[col] <= item.startMin) {
- columns[col] = item.endMin;
- layout.set(eventKey(item.event), { column: col, totalColumns: 0 });
- placed = true;
- break;
- }
- }
- if (!placed) {
- layout.set(eventKey(item.event), { column: columns.length, totalColumns: 0 });
- columns.push(item.endMin);
- }
- }
- // Set totalColumns for all events in this group
- const total = columns.length;
- for (const item of group) {
- const l = layout.get(eventKey(item.event));
- if (l) l.totalColumns = total;
- }
- }
- return layout;
-}
-
-function eventKey(e) {
- return `${e.accountId}-${e.id}`;
-}
-
export default function DayView({ accounts }) {
const [date, setDate] = useState(() => {
const d = new Date();
@@ -130,8 +55,8 @@ export default function DayView({ accounts }) {
setLoading(true);
};
- const allDayEvents = useMemo(() => events.filter(e => e.isAllDay), [events]);
- const timedEvents = useMemo(() => events.filter(e => !e.isAllDay && getEventDayMinutes(e, date)), [events, date]);
+ const allDayEvents = useMemo(() => events.filter(e => e.isAllDay && eventOccursOnDay(e, date)), [events, date]);
+ const timedEvents = useMemo(() => events.filter(e => !e.isAllDay && eventOccursOnDay(e, date)), [events, date]);
const layout = useMemo(() => layoutEvents(timedEvents, date), [timedEvents, date]);
const colorMap = useMemo(() => buildSubcalendarColorMap(accounts), [accounts]);
const selectedEventKey = searchParams.get('event');
@@ -145,7 +70,7 @@ export default function DayView({ accounts }) {
}, []);
const isToday = date.toDateString() === now.toDateString();
const nowMinutes = now.getHours() * 60 + now.getMinutes();
- const nowTop = ((nowMinutes - START_MINUTES) / 60) * PX_PER_HOUR;
+ const nowTop = (nowMinutes / 60) * PX_PER_HOUR;
return (
<div className="space-y-4">
diff --git a/client/src/components/calendar/MonthView.jsx b/client/src/components/calendar/MonthView.jsx
index 622d9d5796..08d65af3cf 100644
--- a/client/src/components/calendar/MonthView.jsx
+++ b/client/src/components/calendar/MonthView.jsx
@@ -4,7 +4,7 @@ import * as api from '../../services/api';
import socket from '../../services/socket';
import EventDetail from './EventDetail';
import Drawer from '../Drawer';
-import { buildSubcalendarColorMap, eventChipStyle } from './calendarUtils';
+import { buildSubcalendarColorMap, eventChipStyle, eventOccursOnDay } from './calendarUtils';
import BrailleSpinner from '../BrailleSpinner';
import EmptyState from '../EmptyState';
import { useThemeContext } from '../ThemeContext';
@@ -89,13 +89,10 @@ export default function MonthView({ accounts }) {
updateParams({ month: localDateKey(now).slice(0, 7), day: null, event: null });
};
- // Group events by day string
- const eventsByDay = {};
- for (const event of events) {
- const dayKey = new Date(event.startTime).toDateString();
- if (!eventsByDay[dayKey]) eventsByDay[dayKey] = [];
- eventsByDay[dayKey].push(event);
- }
+ // The server returns a coarse range; place each event on every visible day it occupies.
+ const eventsByDay = Object.fromEntries(cells.map(cell => [
+ cell.date.toDateString(), events.filter(event => eventOccursOnDay(event, cell.date)),
+ ]));
const colorMap = useMemo(() => buildSubcalendarColorMap(accounts), [accounts]);
const selectedEventKey = searchParams.get('event');
@@ -190,7 +187,8 @@ export default function MonthView({ accounts }) {
>
{!event.isAllDay && (
<span className="text-gray-500 mr-1">
- {formatTimeOfDay(event.startTime)}
+ {new Date(event.startTime).toDateString() === dayStr
+ ? formatTimeOfDay(event.startTime) : 'Continues'}
</span>
)}
{event.title}
@@ -236,7 +234,9 @@ export default function MonthView({ accounts }) {
className="w-full min-h-[44px] text-left px-3 py-2 rounded transition-colors hover:brightness-125"
style={eventChipStyle(colorMap.get(event.subcalendarId) || null, theme?.mode)}
>
- <span className="block text-xs">{event.isAllDay ? 'All day' : formatTimeOfDay(event.startTime)}</span>
+ <span className="block text-xs">{event.isAllDay ? 'All day'
+ : new Date(event.startTime).toDateString() === selectedDay.date.toDateString()
+ ? formatTimeOfDay(event.startTime) : 'Continues'}</span>
<span className="block text-sm break-words">{event.title}</span>
</button>
))}
diff --git a/client/src/components/calendar/WeekView.jsx b/client/src/components/calendar/WeekView.jsx
index 38c6c05daf..9e7dc8a031 100644
--- a/client/src/components/calendar/WeekView.jsx
+++ b/client/src/components/calendar/WeekView.jsx
@@ -4,20 +4,14 @@ import * as api from '../../services/api';
import socket from '../../services/socket';
import EventDetail from './EventDetail';
import ChronotypeOverlay from './ChronotypeOverlay';
-import { buildSubcalendarColorMap, eventChipStyle, getEventDayMinutes } from './calendarUtils';
+import { buildSubcalendarColorMap, eventChipStyle, eventOccursOnDay } from './calendarUtils';
+import { HOURS, PX_PER_HOUR, PX_PER_15MIN, START_HOUR, eventKey, getEventPosition, layoutEvents } from './calendarTimeGrid';
import BrailleSpinner from '../BrailleSpinner';
import EmptyState from '../EmptyState';
import { useThemeContext } from '../ThemeContext';
import { formatMonthDay, formatWeekdayShort, formatDateShort, formatHourOfDay } from '../../utils/formatters';
import useUrlParams from '../../hooks/useUrlParams';
-const START_HOUR = 0;
-const END_HOUR = 24;
-const HOURS = Array.from({ length: END_HOUR - START_HOUR }, (_, i) => i + START_HOUR);
-const PX_PER_HOUR = 80;
-const PX_PER_15MIN = PX_PER_HOUR / 4; // 20px per 15-min block
-const START_MINUTES = START_HOUR * 60;
-
function getWeekStart(date) {
const d = new Date(date);
d.setDate(d.getDate() - d.getDay());
@@ -33,71 +27,6 @@ function getWeekDays(weekStart) {
});
}
-function getEventPosition(event, day) {
- const { startMin, endMin } = getEventDayMinutes(event, day);
- const top = ((startMin - START_MINUTES) / 60) * PX_PER_HOUR;
- const height = Math.min(
- Math.max(((endMin - startMin) / 60) * PX_PER_HOUR, PX_PER_15MIN),
- HOURS.length * PX_PER_HOUR - top,
- );
- return { top, height };
-}
-
-function eventKey(e) {
- return `${e.accountId}-${e.id}`;
-}
-
-function layoutEvents(events, day) {
- const items = events.map(e => {
- const { startMin, endMin } = getEventDayMinutes(e, day);
- return { event: e, startMin, endMin: Math.max(endMin, startMin + 15) };
- }).sort((a, b) => a.startMin - b.startMin || a.endMin - b.endMin);
-
- const groups = [];
- let currentGroup = [];
- let groupEnd = -1;
-
- for (const item of items) {
- if (currentGroup.length === 0 || item.startMin < groupEnd) {
- currentGroup.push(item);
- groupEnd = Math.max(groupEnd, item.endMin);
- } else {
- groups.push(currentGroup);
- currentGroup = [item];
- groupEnd = item.endMin;
- }
- }
- if (currentGroup.length > 0) groups.push(currentGroup);
-
- const layout = new Map();
- for (const group of groups) {
- const columns = [];
- for (const item of group) {
- let placed = false;
- for (let col = 0; col < columns.length; col++) {
- if (columns[col] <= item.startMin) {
- columns[col] = item.endMin;
- layout.set(eventKey(item.event), { column: col, totalColumns: 0 });
- placed = true;
- break;
- }
- }
- if (!placed) {
- layout.set(eventKey(item.event), { column: columns.length, totalColumns: 0 });
- columns.push(item.endMin);
- }
- }
- const total = columns.length;
- for (const item of group) {
- const l = layout.get(eventKey(item.event));
- if (l) l.totalColumns = total;
- }
- }
- return layout;
-}
-
-
-
export default function WeekView({ accounts }) {
const [weekStart, setWeekStart] = useState(() => getWeekStart(new Date()));
const [events, setEvents] = useState([]);
@@ -147,13 +76,12 @@ export default function WeekView({ accounts }) {
// Group events by day
const eventsByDay = useMemo(() => weekDays.map(day =>
- events.filter(e => !e.isAllDay && getEventDayMinutes(e, day))
+ events.filter(e => !e.isAllDay && eventOccursOnDay(e, day))
), [events, weekDays]);
- const allDayByDay = useMemo(() => weekDays.map(day => {
- const dayStr = day.toDateString();
- return events.filter(e => e.isAllDay && new Date(e.startTime).toDateString() === dayStr);
- }), [events, weekDays]);
+ const allDayByDay = useMemo(() => weekDays.map(day =>
+ events.filter(e => e.isAllDay && eventOccursOnDay(e, day))
+ ), [events, weekDays]);
// Memoize layouts per day
const layoutsByDay = useMemo(
@@ -164,7 +92,7 @@ export default function WeekView({ accounts }) {
const now = new Date();
const todayStr = now.toDateString();
const nowMinutes = now.getHours() * 60 + now.getMinutes();
- const nowTop = ((nowMinutes - START_MINUTES) / 60) * PX_PER_HOUR;
+ const nowTop = (nowMinutes / 60) * PX_PER_HOUR;
const weekLabel = `${formatMonthDay(weekDays[0])} - ${formatDateShort(weekDays[6])}`;
diff --git a/client/src/components/calendar/calendarEventChips.test.jsx b/client/src/components/calendar/calendarEventChips.test.jsx
index d4d61b7547..2a72aca046 100644
--- a/client/src/components/calendar/calendarEventChips.test.jsx
+++ b/client/src/components/calendar/calendarEventChips.test.jsx
@@ -59,6 +59,37 @@ const renderView = async (ui) => {
const chipFor = (title) => screen.getByRole('button', { name: new RegExp(title) });
+it('keeps all-day membership consistent across Day, Week, and Month views', async () => {
+ vi.useFakeTimers({ toFake: ['Date'] });
+ vi.setSystemTime(new Date(2026, 8, 23, 12));
+ const allDay = (id, title, start, end) => ({
+ ...ALL_DAY, id, title,
+ startTime: new Date(2026, 8, start).toISOString(),
+ endTime: new Date(2026, 8, end).toISOString(),
+ });
+ api.getCalendarEvents.mockResolvedValue({ events: [
+ allDay('previous', 'Previous day only', 22, 23),
+ allDay('spanning', 'Spanning days', 21, 25),
+ allDay('tomorrow', 'Tomorrow only', 24, 25),
+ ] });
+
+ const mounted = render(<MemoryRouter><DayView accounts={ACCOUNTS} /></MemoryRouter>);
+ await act(async () => {});
+ expect(screen.getAllByRole('button', { name: 'Spanning days' })).toHaveLength(1);
+ expect(screen.queryByRole('button', { name: 'Previous day only' })).not.toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: 'Tomorrow only' })).not.toBeInTheDocument();
+ mounted.unmount();
+
+ const week = render(<MemoryRouter><WeekView accounts={ACCOUNTS} /></MemoryRouter>);
+ await act(async () => {});
+ expect(screen.getAllByRole('button', { name: 'Spanning days' })).toHaveLength(4);
+ week.unmount();
+
+ render(<MemoryRouter><MonthView accounts={ACCOUNTS} /></MemoryRouter>);
+ await act(async () => {});
+ expect(screen.getAllByRole('button', { name: 'Spanning days' })).toHaveLength(4);
+});
+
/** The graded color for the ACTIVE mode, and for the other one. */
const expectGradedForActiveMode = (element, rawColor) => {
const other = themeMode.current === 'day' ? 'night' : 'day';
@@ -280,10 +311,10 @@ function MonthHistory() {
describe('MonthView overflow navigation', () => {
beforeEach(() => {
api.getCalendarEvents.mockResolvedValue({ events: [
- { ...TIMED, id: 'late', title: 'Example late appointment', startTime: new Date(2027, 0, 12, 18).toISOString() },
- { ...ALL_DAY, id: 'day', title: 'Example all-day entry', startTime: new Date(2027, 0, 12).toISOString() },
- { ...TIMED, id: 'early', title: 'Example early appointment', startTime: new Date(2027, 0, 12, 8).toISOString() },
- { ...TIMED, id: 'hidden', title: 'Example hidden appointment', startTime: new Date(2027, 0, 12, 12).toISOString() },
+ { ...TIMED, id: 'late', title: 'Example late appointment', startTime: new Date(2027, 0, 12, 18).toISOString(), endTime: new Date(2027, 0, 12, 19).toISOString() },
+ { ...ALL_DAY, id: 'day', title: 'Example all-day entry', startTime: new Date(2027, 0, 12).toISOString(), endTime: new Date(2027, 0, 13).toISOString() },
+ { ...TIMED, id: 'early', title: 'Example early appointment', startTime: new Date(2027, 0, 12, 8).toISOString(), endTime: new Date(2027, 0, 12, 9).toISOString() },
+ { ...TIMED, id: 'hidden', title: 'Example hidden appointment', startTime: new Date(2027, 0, 12, 12).toISOString(), endTime: new Date(2027, 0, 12, 13).toISOString() },
] });
});
@@ -345,7 +376,7 @@ describe('MonthView overflow navigation', () => {
api.getCalendarEvents.mockReturnValue(new Promise(resolve => { finish = resolve; }));
render(<MemoryRouter initialEntries={['/calendar/month?month=2027-01&day=2027-01-12&event=acct-1:hidden']}><MonthView accounts={ACCOUNTS} /></MemoryRouter>);
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
- await act(async () => finish({ events: [{ ...TIMED, id: 'hidden', title: 'Example hidden appointment', startTime: new Date(2027, 0, 12, 12).toISOString() }] }));
+ await act(async () => finish({ events: [{ ...TIMED, id: 'hidden', title: 'Example hidden appointment', startTime: new Date(2027, 0, 12, 12).toISOString(), endTime: new Date(2027, 0, 12, 13).toISOString() }] }));
expect(screen.getByRole('dialog', { name: 'Example hidden appointment' })).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: 'Close', exact: true }));
expect(screen.getByRole('button', { name: 'Close day events' })).toBeInTheDocument();
diff --git a/client/src/components/calendar/calendarTimeGrid.js b/client/src/components/calendar/calendarTimeGrid.js
new file mode 100644
index 0000000000..ba35b70844
--- /dev/null
+++ b/client/src/components/calendar/calendarTimeGrid.js
@@ -0,0 +1,70 @@
+import { getEventDayMinutes } from './calendarUtils';
+
+export const START_HOUR = 0;
+export const HOURS = Array.from({ length: 24 }, (_, hour) => hour);
+export const PX_PER_HOUR = 80;
+export const PX_PER_15MIN = PX_PER_HOUR / 4;
+
+export function getEventPosition(event, day) {
+ const { startMin, endMin } = getEventDayMinutes(event, day);
+ const top = (startMin / 60) * PX_PER_HOUR;
+ const height = Math.min(
+ Math.max(((endMin - startMin) / 60) * PX_PER_HOUR, PX_PER_15MIN),
+ HOURS.length * PX_PER_HOUR - top,
+ );
+ return { top, height };
+}
+
+export function eventKey(event) {
+ return `${event.accountId}-${event.id}`;
+}
+
+/** Assign side-by-side columns to timed events that overlap on this day. */
+export function layoutEvents(events, day) {
+ const items = events.map(event => {
+ const { startMin, endMin } = getEventDayMinutes(event, day);
+ return { event, startMin, endMin: Math.max(endMin, startMin + 15) };
+ }).sort((a, b) => a.startMin - b.startMin || a.endMin - b.endMin);
+
+ const groups = [];
+ let currentGroup = [];
+ let groupEnd = -1;
+
+ for (const item of items) {
+ if (currentGroup.length === 0 || item.startMin < groupEnd) {
+ currentGroup.push(item);
+ groupEnd = Math.max(groupEnd, item.endMin);
+ } else {
+ groups.push(currentGroup);
+ currentGroup = [item];
+ groupEnd = item.endMin;
+ }
+ }
+ if (currentGroup.length > 0) groups.push(currentGroup);
+
+ const layout = new Map();
+ for (const group of groups) {
+ const columns = [];
+ for (const item of group) {
+ let placed = false;
+ for (let col = 0; col < columns.length; col++) {
+ if (columns[col] <= item.startMin) {
+ columns[col] = item.endMin;
+ layout.set(eventKey(item.event), { column: col, totalColumns: 0 });
+ placed = true;
+ break;
+ }
+ }
+ if (!placed) {
+ layout.set(eventKey(item.event), { column: columns.length, totalColumns: 0 });
+ columns.push(item.endMin);
+ }
+ }
+ const total = columns.length;
+ for (const item of group) {
+ const position = layout.get(eventKey(item.event));
+ if (position) position.totalColumns = total;
+ }
+ }
+ return layout;
+}
diff --git a/client/src/components/calendar/calendarUtils.js b/client/src/components/calendar/calendarUtils.js
index 7660bb8a9d..146e3e1c8b 100644
--- a/client/src/components/calendar/calendarUtils.js
+++ b/client/src/components/calendar/calendarUtils.js
@@ -21,6 +21,20 @@ export function getEventDayMinutes(event, day) {
};
}
+/** An event occupies a local calendar day when its half-open interval overlaps it. */
+export function eventOccursOnDay(event, day) {
+ if (!event.isAllDay) return getEventDayMinutes(event, day) !== null;
+
+ const start = new Date(event.startTime);
+ const end = new Date(event.endTime);
+ const dayStart = new Date(day);
+ dayStart.setHours(0, 0, 0, 0);
+ const dayEnd = new Date(dayStart);
+ dayEnd.setDate(dayEnd.getDate() + 1);
+ return [start, end, dayStart].every(date => Number.isFinite(date.getTime()))
+ && end > start && start < dayEnd && end > dayStart;
+}
+
/**
* Neutral chip for an event whose subcalendar has no color (or one we can't
* parse). `--port-accent` is a space-separated RGB triple, so it only becomes a
diff --git a/client/src/components/calendar/calendarUtils.test.js b/client/src/components/calendar/calendarUtils.test.js
index 4797f9fe76..58c41b32dc 100644
--- a/client/src/components/calendar/calendarUtils.test.js
+++ b/client/src/components/calendar/calendarUtils.test.js
@@ -1,8 +1,51 @@
import { describe, it, expect } from 'vitest';
-import { buildSubcalendarColorMap, eventChipStyle } from './calendarUtils';
+import { buildSubcalendarColorMap, eventChipStyle, eventOccursOnDay } from './calendarUtils';
import { chipColors, parseColor, contrastRatio, chipBackdrop } from '../../lib/chipContrast';
+describe('eventOccursOnDay', () => {
+ const day = (date) => new Date(2026, 8, date);
+ const event = (start, end, isAllDay = true) => ({
+ startTime: day(start).toISOString(), endTime: day(end).toISOString(), isAllDay,
+ });
+
+ it('treats the end midnight as exclusive for one-day and three-day all-day events', () => {
+ const oneDay = event(23, 24);
+ expect([22, 23, 24].map(date => eventOccursOnDay(oneDay, day(date))))
+ .toEqual([false, true, false]);
+
+ const threeDays = event(21, 24);
+ expect([20, 21, 22, 23, 24].map(date => eventOccursOnDay(threeDays, day(date))))
+ .toEqual([false, true, true, true, false]);
+ });
+
+ it('includes an all-day event that began before the visible range', () => {
+ expect(eventOccursOnDay(event(19, 22), day(21))).toBe(true);
+ });
+
+ it('handles a timed event crossing midnight and rejects an end at midnight', () => {
+ const overnight = {
+ startTime: new Date(2026, 8, 23, 23).toISOString(),
+ endTime: new Date(2026, 8, 24, 1).toISOString(),
+ isAllDay: false,
+ };
+ expect(eventOccursOnDay(overnight, day(23))).toBe(true);
+ expect(eventOccursOnDay(overnight, day(24))).toBe(true);
+ expect(eventOccursOnDay(overnight, day(25))).toBe(false);
+ expect(eventOccursOnDay({ ...overnight, endTime: day(24).toISOString() }, day(24))).toBe(false);
+ });
+
+ it('uses local midnight across daylight-saving transitions', () => {
+ const spring = {
+ startTime: new Date(2026, 2, 7).toISOString(),
+ endTime: new Date(2026, 2, 9).toISOString(),
+ isAllDay: true,
+ };
+ expect(eventOccursOnDay(spring, new Date(2026, 2, 8))).toBe(true);
+ expect(eventOccursOnDay(spring, new Date(2026, 2, 9))).toBe(false);
+ });
+});
+
describe('buildSubcalendarColorMap', () => {
it('flattens every account\'s colored subcalendars into one id → color map', () => {
const map = buildSubcalendarColorMap([