mirror of
https://github.com/dylanbenzi/yellowbird.git
synced 2026-11-27 01:07:01 +00:00
cleaned up code prior to calendar migration to db data
This commit is contained in:
@@ -20,7 +20,7 @@ const page = async () => {
|
|||||||
const endDate = addDays(startDate, 41);
|
const endDate = addDays(startDate, 41);
|
||||||
|
|
||||||
const getEventArray = await getEvents(startDate, endDate);
|
const getEventArray = await getEvents(startDate, endDate);
|
||||||
// console.log(getEventArray);
|
console.log(getEventArray);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col w-full h-full gap-4">
|
<div className="flex flex-col w-full h-full gap-4">
|
||||||
@@ -57,7 +57,7 @@ const page = async () => {
|
|||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full h-full flex gap-4">
|
<div className="w-full h-full flex gap-4">
|
||||||
<MonthCalendar />
|
<MonthCalendar events={getEventArray} />
|
||||||
<Day />
|
<Day />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -20,8 +20,9 @@ import { Tabs, TabsList, TabsTrigger } from "../ui/tabs";
|
|||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
import { ArrowLeftIcon, ArrowRightIcon } from "lucide-react";
|
import { ArrowLeftIcon, ArrowRightIcon } from "lucide-react";
|
||||||
import { dates, week } from "../../../public/MockData/Calendar";
|
import { dates, week } from "../../../public/MockData/Calendar";
|
||||||
|
import { Event } from "@/db/db_calls";
|
||||||
|
|
||||||
const MonthCalendar = () => {
|
const MonthCalendar = (props: { events: Event[] }) => {
|
||||||
const startDate = startOfWeek(startOfMonth(new Date("2024-09-22")));
|
const startDate = startOfWeek(startOfMonth(new Date("2024-09-22")));
|
||||||
const endDate = addDays(startDate, 41);
|
const endDate = addDays(startDate, 41);
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
|
|||||||
+5
-29
@@ -42,10 +42,10 @@ export const syncUsers = async ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface EventArray {
|
// export interface EventArray {
|
||||||
date?: string;
|
// date?: string;
|
||||||
events?: Event[];
|
// events?: Event[];
|
||||||
}
|
// }
|
||||||
|
|
||||||
export interface Event {
|
export interface Event {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -63,9 +63,7 @@ export interface Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const getEvents = async (startDate: Date, endDate: Date) => {
|
export const getEvents = async (startDate: Date, endDate: Date) => {
|
||||||
const eventArray: EventArray[] = [];
|
const eventArray: Event[] = await db
|
||||||
|
|
||||||
const events: Event[] = await db
|
|
||||||
.select()
|
.select()
|
||||||
.from(EventsTable)
|
.from(EventsTable)
|
||||||
.where(
|
.where(
|
||||||
@@ -76,27 +74,5 @@ export const getEvents = async (startDate: Date, endDate: Date) => {
|
|||||||
)
|
)
|
||||||
.orderBy(asc(EventsTable.datetime));
|
.orderBy(asc(EventsTable.datetime));
|
||||||
|
|
||||||
events.forEach((e) => {
|
|
||||||
const UTCDate = e.datetime;
|
|
||||||
const localDate = UTCDate.toLocaleString("en-US", {
|
|
||||||
timeZone: "America/New_York",
|
|
||||||
});
|
|
||||||
console.log(new Date(localDate));
|
|
||||||
});
|
|
||||||
|
|
||||||
// console.log(events);
|
|
||||||
|
|
||||||
for (let d = startDate; d <= endDate; d.setDate(d.getDate() + 1)) {
|
|
||||||
const eventsByDay: Event[] = [];
|
|
||||||
|
|
||||||
events.forEach((e) => {
|
|
||||||
if (isSameDay(e.datetime, d)) {
|
|
||||||
eventsByDay.push(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
eventArray.push({ "date": d.toString(), events: eventsByDay });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return eventArray;
|
return eventArray;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user