diff --git a/src/app/calendar/page.tsx b/src/app/calendar/page.tsx index c0c2c21..fae38fd 100644 --- a/src/app/calendar/page.tsx +++ b/src/app/calendar/page.tsx @@ -9,20 +9,13 @@ import { createDragAndDropPlugin } from '@schedule-x/drag-and-drop'; import '@/calendar-theme.css'; import { MouseEventHandler, useEffect, useState } from 'react'; import App from '@/components/app'; -import { - ContextMenu, - ContextMenuContent, - ContextMenuItem, - ContextMenuTrigger, -} from '@/components/ui/context-menu'; - -import { PlusCircle, Trash } from 'lucide-react'; import { format, parse } from 'date-fns'; import PostDialog, { today } from './postDialog'; import axios from 'axios'; import Cookies from 'js-cookie'; import { Schedule, ScheduleRemoveRequest, ScheduleRequest } from '@/utils'; +import Calendar, { CalendarSchedule } from './calendar'; function closestChild(children: any, clientX: number, clientY: number) { let closestElement = null; @@ -43,7 +36,7 @@ function closestChild(children: any, clientX: number, clientY: number) { return closestElement; } -function CalendarApp() { +export default function CalendarApp() { const eventsService = useState(() => createEventsServicePlugin())[0]; const dragAndDrop = useState(() => createDragAndDropPlugin())[0]; const [eventCount, setEventCount] = useState(0); @@ -56,96 +49,17 @@ function CalendarApp() { isDark: true, }); + const [events, setEvents] = useState([]); + useEffect(() => { axios.get(`/api/posts/?id=${sessionId}`).then((response) => { - for (const [id, sched] of ( - response.data.schedules as ScheduleRequest[] - ).entries()) { - const date = parse( - sched.scheduled, - 'y-MM-dd hh:mm', - new Date() - ); - const end = new Date(date); - end.setHours(date.getHours() + 1); - - calendar.events.add({ - title: 'Post', - id, - start: format(date, 'y-MM-dd hh:mm'), - end: format(end, 'y-MM-dd hh:mm'), - }); - setEventCount(eventCount + 1); - } + setEvents(response.data.schedules as CalendarSchedule[]); + setEventCount(response.data.schedules.length); }); }, []); - const [newPostDialogOpen, setNewPostDialogOpen] = useState(false); + const [postDialog, setDialog] = useState(false); const [date, setDate] = useState(today); - const [selected, setSelected] = useState(null); - const [scrollY, setScrollY] = useState(0); - - useEffect(() => { - const interval = setInterval(() => { - window.scrollTo(0, scrollY); - }, 10); - - setTimeout(() => { - clearInterval(interval); - }, 300); - }, [scrollY]); - - const handleDialog: MouseEventHandler = (event) => { - setScrollY(window.scrollY); - - const target = event.target as HTMLElement; - - if (target.className === 'sx__time-grid-event-time') { - const id = - target.parentElement?.parentElement?.getAttribute( - 'data-event-id' - ); - setSelected(id); - - setDate( - parse( - calendar.events.get(parseInt(id || ''))?.start || '', - 'y-MM-dd hh:mm', - new Date() - ) - ); - } else { - setSelected(null); - - try { - const dayElement = target.closest('.sx__time-grid-day'); - - const dayText = dayElement - ? dayElement.getAttribute('aria-label') - : null; - - const hourElement = closestChild( - target.parentElement?.children[0].children || [], - event.clientX, - event.clientY - ); - - if (!dayText || !hourElement) { - event.preventDefault(); - } else { - const toDate = parse( - (dayText || '') + - ' ' + - (hourElement?.textContent || ''), - 'MMMM dd, yyyy h a', - new Date() - ); - if (toDate instanceof Date && !isNaN(toDate.getTime())) - setDate(toDate); - } - } catch {} - } - }; return ( @@ -153,8 +67,8 @@ function CalendarApp() { { calendar.events.add(e); setEventCount(eventCount + 1); @@ -162,58 +76,13 @@ function CalendarApp() { eventId={eventCount} sessionId={sessionId} /> - - - - - - { - setNewPostDialogOpen(true); - }} - > - {' '} -

New post

-
- {selected ? ( - { - if (selected) { - calendar.events.remove( - parseInt(selected) - ); - - axios.delete( - `/api/posts`, - { - params: { - id: sessionId, - date: format( - date, - 'y-MM-dd hh:mm' - ), - } satisfies ScheduleRemoveRequest, - } - ); - } - }} - className="" - > - {' '} -

Delete

-
- ) : ( - '' - )} -
-
+
); } - -export default CalendarApp; diff --git a/src/app/signup/page.tsx b/src/app/signup/page.tsx index b9ab438..33701b2 100644 --- a/src/app/signup/page.tsx +++ b/src/app/signup/page.tsx @@ -15,7 +15,6 @@ export default function SignUp() { const router = useRouter(); return ( - //

Create an account

@@ -73,8 +72,8 @@ export default function SignUp() { By clicking continue, you agree to our{' '} Terms of Service - {' '} - {'and '} + + {' and '} Privacy Policy @@ -83,6 +82,5 @@ export default function SignUp() {
- // ); }