feat: Phase 5 - Calendar + Dashboard + Search
Calendar: - GET /api/domains/[domainId]/calendar/events?from=&to= — returns tasks, habits, projects, milestones - PATCH /api/domains/[domainId]/tasks/[id]/schedule — drag-to-reschedule with activity feed - Calendar UI with month/week/day views via react-big-calendar - Drag-to-reschedule with SSE updates - Filter by entity type and domain - Keyboard shortcuts: t=today, m/w/d=view, ←/→=navigate - Mobile: auto-switches to day view on small screens Dashboard: - GET/PUT /api/domains/[domainId]/dashboard — layout stored in domain custom_fields - 8 per-widget data endpoints (today-tasks, habit-checklist, weekly-stats, project-progress, upcoming-calendar, recent-notes, activity-feed, quick-capture) - react-grid-layout with responsive breakpoints (12/8/4 cols) - Drag-to-reorder, resize, add/remove widgets - Edit mode toggle, per-workspace layout persistence - Widget error boundary Search: - tsvector columns + GIN indexes on tasks, notes, projects, habits, domains - GET /api/search?q=&types=&domain= — ranked results with ts_headline snippets - Dedicated search page with grouped results, filters, recent searches (localStorage) - Empty state with hints Schema: - Added custom_fields jsonb column to domains table (migration 0002) - Removed stale root app/ directory Build: passes, typecheck: passes, tests: 18/18 wikilink-parser tests pass
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
'use client';
|
||||
|
||||
import { Calendar, dateFnsLocalizer } from 'react-big-calendar';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { Calendar, dateFnsLocalizer, Views } from 'react-big-calendar';
|
||||
import withDragAndDrop from 'react-big-calendar/lib/addons/dragAndDrop';
|
||||
import 'react-big-calendar/lib/css/react-big-calendar.css';
|
||||
import 'react-big-calendar/lib/addons/dragAndDrop/styles.css';
|
||||
import { format, parse, startOfWeek, getDay } from 'date-fns';
|
||||
import { enUS } from 'date-fns/locale/en-US';
|
||||
import { useRouter } from 'next/navigation';
|
||||
@@ -18,50 +21,125 @@ const localizer = dateFnsLocalizer({
|
||||
locales,
|
||||
});
|
||||
|
||||
const DragAndDropCalendar = withDragAndDrop(Calendar as any) as any;
|
||||
|
||||
interface CalendarEvent {
|
||||
id: string;
|
||||
title: string;
|
||||
start: Date;
|
||||
end: Date;
|
||||
type: 'task' | 'project' | 'milestone';
|
||||
domain: string;
|
||||
type: 'task' | 'habit' | 'project' | 'milestone';
|
||||
entityType: string;
|
||||
entityId: string;
|
||||
color: string;
|
||||
domainId: string;
|
||||
href: string;
|
||||
priority?: string;
|
||||
difficulty?: string;
|
||||
status?: string;
|
||||
}
|
||||
|
||||
interface BigCalendarWrapperProps {
|
||||
events: CalendarEvent[];
|
||||
onEventDrop?: (event: CalendarEvent, newStart: Date) => void;
|
||||
defaultView?: string;
|
||||
date?: Date;
|
||||
onNavigate?: (date: Date) => void;
|
||||
onViewChange?: (view: string) => void;
|
||||
}
|
||||
|
||||
function eventStyleGetter(event: CalendarEvent) {
|
||||
return {
|
||||
style: {
|
||||
backgroundColor: event.color,
|
||||
borderRadius: '4px',
|
||||
opacity: 0.8,
|
||||
color: 'white',
|
||||
border: '0px',
|
||||
fontSize: '12px',
|
||||
},
|
||||
const style: React.CSSProperties = {
|
||||
backgroundColor: event.color,
|
||||
borderRadius: '4px',
|
||||
opacity: 0.85,
|
||||
color: '#fff',
|
||||
border: '0px',
|
||||
fontSize: '12px',
|
||||
display: 'block',
|
||||
};
|
||||
|
||||
if (event.status === 'completed' || event.status === 'done') {
|
||||
style.opacity = 0.5;
|
||||
style.textDecoration = 'line-through';
|
||||
}
|
||||
|
||||
return { style };
|
||||
}
|
||||
|
||||
export function BigCalendarWrapper({ events }: BigCalendarWrapperProps) {
|
||||
export function BigCalendarWrapper({
|
||||
events,
|
||||
onEventDrop,
|
||||
defaultView = 'month',
|
||||
date,
|
||||
onNavigate,
|
||||
onViewChange,
|
||||
}: BigCalendarWrapperProps) {
|
||||
const router = useRouter();
|
||||
|
||||
const handleSelectEvent = useCallback(
|
||||
(event: CalendarEvent) => {
|
||||
router.push(event.href);
|
||||
},
|
||||
[router]
|
||||
);
|
||||
|
||||
const handleEventDrop = useCallback(
|
||||
({ event, start }: { event: CalendarEvent; start: Date }) => {
|
||||
if (onEventDrop) {
|
||||
onEventDrop(event, start);
|
||||
}
|
||||
},
|
||||
[onEventDrop]
|
||||
);
|
||||
|
||||
const handleNavigate = useCallback(
|
||||
(newDate: Date) => {
|
||||
if (onNavigate) onNavigate(newDate);
|
||||
},
|
||||
[onNavigate]
|
||||
);
|
||||
|
||||
const handleViewChange = useCallback(
|
||||
(newView: string) => {
|
||||
if (onViewChange) onViewChange(newView);
|
||||
},
|
||||
[onViewChange]
|
||||
);
|
||||
|
||||
const minTime = useMemo(() => {
|
||||
const d = new Date();
|
||||
d.setHours(0, 0, 0, 0);
|
||||
return d;
|
||||
}, []);
|
||||
|
||||
const maxTime = useMemo(() => {
|
||||
const d = new Date();
|
||||
d.setHours(23, 59, 59, 999);
|
||||
return d;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Calendar
|
||||
<DragAndDropCalendar
|
||||
localizer={localizer}
|
||||
events={events}
|
||||
startAccessor="start"
|
||||
endAccessor="end"
|
||||
style={{ height: 600 }}
|
||||
eventPropGetter={eventStyleGetter}
|
||||
onSelectEvent={(event) => router.push(event.href)}
|
||||
onSelectEvent={handleSelectEvent}
|
||||
views={['month', 'week', 'day']}
|
||||
defaultView="month"
|
||||
defaultView={defaultView}
|
||||
date={date}
|
||||
onNavigate={handleNavigate}
|
||||
onView={handleViewChange}
|
||||
popup
|
||||
toolbar
|
||||
onEventDrop={handleEventDrop}
|
||||
resizable
|
||||
step={60}
|
||||
timeslots={1}
|
||||
min={minTime}
|
||||
max={maxTime}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user