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

refactor: extract shared color map, debounce color picker, consolidate declined filter

Adam Eivy852010076c72
diff --git a/client/src/components/calendar/ConfigTab.jsx b/client/src/components/calendar/ConfigTab.jsx
index 19279f5be6..a3ef3fea66 100644
--- a/client/src/components/calendar/ConfigTab.jsx
+++ b/client/src/components/calendar/ConfigTab.jsx
@@ -132,16 +132,28 @@ export default function ConfigTab({ accounts, setAccounts }) {
setExpandedAccounts(prev => ({ ...prev, [id]: !prev[id] }));
};
+ // Update subcalendar field locally only (no API call) — used for color picker dragging
+ const handleSubcalendarLocal = (account, calendarId, field, value) => {
+ const subcalendars = (account.subcalendars || []).map(sc =>
+ sc.calendarId === calendarId ? { ...sc, [field]: value } : sc
+ );
+ setAccounts(prev => prev.map(a => a.id === account.id ? { ...a, subcalendars } : a));
+ };
+
+ // Update subcalendar field and persist to server
const handleSubcalendarToggle = async (account, calendarId, field, value) => {
const subcalendars = (account.subcalendars || []).map(sc =>
sc.calendarId === calendarId ? { ...sc, [field]: value } : sc
);
- // Update local state immediately for visual feedback
setAccounts(prev => prev.map(a => a.id === account.id ? { ...a, subcalendars } : a));
setSavingSubcals(account.id);
const result = await api.updateSubcalendars(account.id, { subcalendars }).catch(() => null);
setSavingSubcals(null);
- if (!result) return toast.error('Failed to update subcalendars');
+ if (!result) {
+ // Rollback on failure
+ setAccounts(prev => prev.map(a => a.id === account.id ? account : a));
+ return toast.error('Failed to update subcalendars');
+ }
};
const handleDiscoverCalendars = async (account) => {
@@ -498,6 +510,7 @@ export default function ConfigTab({ accounts, setAccounts }) {
<input
type="color"
value={sc.color || '#3b82f6'}
+ onInput={(e) => handleSubcalendarLocal(account, sc.calendarId, 'color', e.target.value)}
onChange={(e) => handleSubcalendarToggle(account, sc.calendarId, 'color', e.target.value)}
className="absolute inset-0 opacity-0 w-full h-full cursor-pointer"
/>
diff --git a/client/src/components/calendar/DayView.jsx b/client/src/components/calendar/DayView.jsx
index 1a89f91951..12184d8549 100644
--- a/client/src/components/calendar/DayView.jsx
+++ b/client/src/components/calendar/DayView.jsx
@@ -3,6 +3,7 @@ import { ChevronLeft, ChevronRight, RefreshCw, MapPin } from 'lucide-react';
import * as api from '../../services/api';
import socket from '../../services/socket';
import EventDetail from './EventDetail';
+import { buildSubcalendarColorMap } from './calendarUtils';
const START_HOUR = 6;
const END_HOUR = 23;
@@ -97,16 +98,6 @@ function formatDate(date) {
return date.toLocaleDateString([], { weekday: 'long', month: 'long', day: 'numeric', year: 'numeric' });
}
-function buildSubcalendarColorMap(accounts) {
- const map = new Map();
- for (const account of (accounts || [])) {
- for (const sc of (account.subcalendars || [])) {
- if (sc.color) map.set(sc.calendarId, sc.color);
- }
- }
- return map;
-}
-
export default function DayView({ accounts }) {
const [date, setDate] = useState(() => {
const d = new Date();
diff --git a/client/src/components/calendar/MonthView.jsx b/client/src/components/calendar/MonthView.jsx
index b1879a4714..d030f73548 100644
--- a/client/src/components/calendar/MonthView.jsx
+++ b/client/src/components/calendar/MonthView.jsx
@@ -3,6 +3,7 @@ import { ChevronLeft, ChevronRight, RefreshCw } from 'lucide-react';
import * as api from '../../services/api';
import socket from '../../services/socket';
import EventDetail from './EventDetail';
+import { buildSubcalendarColorMap } from './calendarUtils';
function getMonthGrid(year, month) {
const firstDay = new Date(year, month, 1);
@@ -30,16 +31,6 @@ function getMonthGrid(year, month) {
const DAY_NAMES = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
-function buildSubcalendarColorMap(accounts) {
- const map = new Map();
- for (const account of (accounts || [])) {
- for (const sc of (account.subcalendars || [])) {
- if (sc.color) map.set(sc.calendarId, sc.color);
- }
- }
- return map;
-}
-
export default function MonthView({ accounts }) {
const now = new Date();
const [year, setYear] = useState(now.getFullYear());
diff --git a/client/src/components/calendar/WeekView.jsx b/client/src/components/calendar/WeekView.jsx
index aa32569db9..3efeffb8af 100644
--- a/client/src/components/calendar/WeekView.jsx
+++ b/client/src/components/calendar/WeekView.jsx
@@ -3,6 +3,7 @@ import { ChevronLeft, ChevronRight, RefreshCw } from 'lucide-react';
import * as api from '../../services/api';
import socket from '../../services/socket';
import EventDetail from './EventDetail';
+import { buildSubcalendarColorMap } from './calendarUtils';
const START_HOUR = 6;
const END_HOUR = 23;
@@ -102,15 +103,7 @@ function layoutEvents(events) {
return layout;
}
-function buildSubcalendarColorMap(accounts) {
- const map = new Map();
- for (const account of (accounts || [])) {
- for (const sc of (account.subcalendars || [])) {
- if (sc.color) map.set(sc.calendarId, sc.color);
- }
- }
- return map;
-}
+
export default function WeekView({ accounts }) {
const [weekStart, setWeekStart] = useState(() => getWeekStart(new Date()));
diff --git a/client/src/components/calendar/calendarUtils.js b/client/src/components/calendar/calendarUtils.js
new file mode 100644
index 0000000000..665d3ddcc8
--- /dev/null
+++ b/client/src/components/calendar/calendarUtils.js
@@ -0,0 +1,13 @@
+/**
+ * Build a Map of subcalendarId → color from the accounts array.
+ * Used by Day, Week, and Month views for event color coding.
+ */
+export function buildSubcalendarColorMap(accounts) {
+ const map = new Map();
+ for (const account of (accounts || [])) {
+ for (const sc of (account.subcalendars || [])) {
+ if (sc.color) map.set(sc.calendarId, sc.color);
+ }
+ }
+ return map;
+}
diff --git a/server/services/calendarApiSync.js b/server/services/calendarApiSync.js
index a9dbc76aaf..5f5f61b489 100644
--- a/server/services/calendarApiSync.js
+++ b/server/services/calendarApiSync.js
@@ -140,11 +140,7 @@ export async function syncOutlookCalendarApi(account, _cache, io, options = {})
io.emit('calendar:sync:event', { accountId: account.id, events });
}
- // Filter out declined events (user configured Outlook to retain declined invites)
- const filtered = events.filter(e => e.myStatus !== 'declined');
- const declined = events.length - filtered.length;
- if (declined > 0) console.log(`📅 Filtered ${declined} declined events`);
-
- console.log(`📅 Calendar API sync complete: ${filtered.length} events (${declined} declined skipped) in ${page} page(s)`);
- return { events: filtered, status: 'success', syncMethod: 'api' };
+ // Declined/cancelled filtering handled universally by calendarSync.filterDeclinedAndCancelled at read time
+ console.log(`📅 Calendar API sync complete: ${events.length} events in ${page} page(s)`);
+ return { events, status: 'success', syncMethod: 'api' };
}