Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions apps/web/src/components/calendar/CalendarSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ interface CalendarSidebarProps {
userEventsVisible: boolean;
onToggleAgentEvents: () => void;
onToggleUserEvents: () => void;
selectedKey?: string;
onSelectCalendar?: (key: string) => void;
className?: string;
}

Expand All @@ -32,6 +34,8 @@ export function CalendarSidebar({
userEventsVisible,
onToggleAgentEvents,
onToggleUserEvents,
selectedKey,
onSelectCalendar,
className,
}: CalendarSidebarProps) {
const hasCalendars = calendars.length > 0;
Expand All @@ -57,18 +61,22 @@ export function CalendarSidebar({
key={cal.key}
role="button"
tabIndex={0}
onClick={() => onToggle(cal.key)}
onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); onToggle(cal.key); } }}
onClick={() => onSelectCalendar ? onSelectCalendar(cal.key) : onToggle(cal.key)}
onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); if (onSelectCalendar) { onSelectCalendar(cal.key); } else { onToggle(cal.key); } } }}
className={cn(
'flex items-center gap-2 px-1.5 py-1 rounded cursor-pointer transition-colors',
'hover:bg-muted/50',
!cal.visible && 'opacity-50'
!cal.visible && 'opacity-50',
cal.key === selectedKey && 'bg-accent/50'
)}
>
<span
role="checkbox"
aria-checked={cal.visible}
aria-label={`Toggle ${cal.name}`}
tabIndex={0}
onClick={(e) => { e.stopPropagation(); onToggle(cal.key); }}
onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); e.stopPropagation(); onToggle(cal.key); } }}
className={cn(
Comment thread
coderabbitai[bot] marked this conversation as resolved.
'size-3.5 shrink-0 rounded-sm border transition-colors',
cal.visible
Expand Down
29 changes: 24 additions & 5 deletions apps/web/src/components/calendar/CalendarView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export function CalendarView({ context, driveId, driveName: _driveName, classNam
const { hiddenCalendars, toggleCalendar, showAll, hideAll, hiddenEventTypes, toggleEventType, isEventTypeVisible } =
useCalendarFilterStore();
const [sidebarOpen, setSidebarOpen] = useState(true);
const [selectedCalendarKey, setSelectedCalendarKey] = useState('personal');

// Force-refresh drives on mount so the sidebar reflects current memberships
const isUserContext = context === 'user';
Expand Down Expand Up @@ -165,6 +166,19 @@ export function CalendarView({ context, driveId, driveName: _driveName, classNam
[calendarEntries]
);

// When user context: derive the effective driveId/context for the event modal.
// Editing an existing event: use the event's own driveId. A null driveId means
// the event is personal — convert null→undefined so it isn't confused with "no
// event selected". Never inherit the selected calendar key when editing.
// Creating a new event: use the selected calendar key.
const creationDriveId = isUserContext && selectedCalendarKey !== 'personal'
? selectedCalendarKey
: (isUserContext ? undefined : driveId);
const effectiveModalDriveId = selectedEvent
? (selectedEvent.driveId ?? undefined)
: creationDriveId;
const effectiveModalContext: 'user' | 'drive' = effectiveModalDriveId ? 'drive' : 'user';

const { data: googleCalendarStatus } = useSWR<GoogleCalendarStatusResponse>(
'/api/integrations/google-calendar/status',
googleCalendarStatusFetcher,
Expand Down Expand Up @@ -265,10 +279,13 @@ export function CalendarView({ context, driveId, driveName: _driveName, classNam
} else {
// POST schema doesn't accept null (only undefined no-op or object upsert)
const { agentTrigger, ...rest } = eventData;
const driveOverride = isUserContext && selectedCalendarKey !== 'personal'
? selectedCalendarKey
: undefined;
await createEvent({
...rest,
agentTrigger: agentTrigger ?? undefined,
});
}, driveOverride);
}
setIsEventModalOpen(false);
};
Expand Down Expand Up @@ -410,8 +427,8 @@ export function CalendarView({ context, driveId, driveName: _driveName, classNam
onRsvp={handleRsvp}
onAddAttendee={handleAddAttendee}
onRemoveAttendee={handleRemoveAttendee}
driveId={driveId}
context={context}
driveId={effectiveModalDriveId}
context={effectiveModalContext}
/>
</div>
);
Expand Down Expand Up @@ -604,6 +621,8 @@ export function CalendarView({ context, driveId, driveName: _driveName, classNam
userEventsVisible={isEventTypeVisible('user')}
onToggleAgentEvents={() => toggleEventType('agent')}
onToggleUserEvents={() => toggleEventType('user')}
selectedKey={selectedCalendarKey}
onSelectCalendar={setSelectedCalendarKey}
/>
</aside>
)}
Expand Down Expand Up @@ -673,8 +692,8 @@ export function CalendarView({ context, driveId, driveName: _driveName, classNam
onRsvp={handleRsvp}
onAddAttendee={handleAddAttendee}
onRemoveAttendee={handleRemoveAttendee}
driveId={driveId}
context={context}
driveId={effectiveModalDriveId}
context={effectiveModalContext}
/>
</div>
);
Expand Down
7 changes: 5 additions & 2 deletions apps/web/src/components/calendar/useCalendarData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,12 @@ export function useCalendarData({
instructionPageId: string | null;
contextPageIds: string[];
};
}) => {
}, overrideDriveId?: string | null) => {
const targetDriveId = overrideDriveId !== undefined
? overrideDriveId
: (context === 'drive' ? driveId : null);
const result = await post<CalendarEvent>('/api/calendar/events', {
driveId: context === 'drive' ? driveId : null,
driveId: targetDriveId,
...eventData,
startAt: eventData.startAt.toISOString(),
endAt: eventData.endAt.toISOString(),
Expand Down
Loading