mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
more date fixes
This commit is contained in:
@@ -1,16 +1,10 @@
|
|||||||
"use client"
|
"use client";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { CalendarMonthModel } from "./calendarMonthUtils";
|
import { CalendarMonthModel } from "./calendarMonthUtils";
|
||||||
import { DayOfWeek, LocalCourse } from "@/models/local/localCourse";
|
import { DayOfWeek } from "@/models/local/localCourse";
|
||||||
import Day from "./Day";
|
import Day from "./Day";
|
||||||
|
|
||||||
export const CalendarMonth = ({
|
export const CalendarMonth = ({ month }: { month: CalendarMonthModel }) => {
|
||||||
month,
|
|
||||||
localCourse,
|
|
||||||
}: {
|
|
||||||
month: CalendarMonthModel;
|
|
||||||
localCourse: LocalCourse;
|
|
||||||
}) => {
|
|
||||||
const [isCollapsed, setIsCollapsed] = useState(false);
|
const [isCollapsed, setIsCollapsed] = useState(false);
|
||||||
|
|
||||||
const isInPast =
|
const isInPast =
|
||||||
@@ -40,14 +34,7 @@ export const CalendarMonth = ({
|
|||||||
<div id={monthName}>
|
<div id={monthName}>
|
||||||
<div className="grid grid-cols-7 text-center fw-bold">
|
<div className="grid grid-cols-7 text-center fw-bold">
|
||||||
{weekDaysList.map((day) => (
|
{weekDaysList.map((day) => (
|
||||||
<div
|
<div key={day} className={""}>
|
||||||
key={day}
|
|
||||||
className={
|
|
||||||
localCourse?.settings.daysOfWeek.includes(day)
|
|
||||||
? "col"
|
|
||||||
: "col text-secondary"
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{day}
|
{day}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
@@ -63,4 +50,4 @@ export const CalendarMonth = ({
|
|||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -5,27 +5,23 @@ import { getMonthsBetweenDates } from "./calendarMonthUtils";
|
|||||||
import { CalendarMonth } from "./CalendarMonth";
|
import { CalendarMonth } from "./CalendarMonth";
|
||||||
|
|
||||||
export default function CourseCalendar() {
|
export default function CourseCalendar() {
|
||||||
const context = useCourseContext();
|
const {
|
||||||
|
localCourse: {
|
||||||
|
settings: { startDate, endDate },
|
||||||
|
},
|
||||||
|
} = useCourseContext();
|
||||||
|
|
||||||
const startDate = getDateFromStringOrThrow(
|
const startDateTime = getDateFromStringOrThrow(
|
||||||
context.localCourse.settings.startDate,
|
startDate,
|
||||||
"course start date"
|
"course start date"
|
||||||
);
|
);
|
||||||
const endDate = getDateFromStringOrThrow(
|
const endDateTime = getDateFromStringOrThrow(endDate, "course end date");
|
||||||
context.localCourse.settings.endDate,
|
const months = getMonthsBetweenDates(startDateTime, endDateTime);
|
||||||
"course end date"
|
|
||||||
);
|
|
||||||
|
|
||||||
const months = getMonthsBetweenDates(startDate, endDate);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{months.map((month) => (
|
{months.map((month) => (
|
||||||
<CalendarMonth
|
<CalendarMonth key={month.month + "" + month.year} month={month} />
|
||||||
key={month.month + "" + month.year}
|
|
||||||
month={month}
|
|
||||||
localCourse={context.localCourse}
|
|
||||||
/>
|
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ import { useCourseContext } from "../context/courseContext";
|
|||||||
export default function Day({ day, month }: { day: Date; month: number }) {
|
export default function Day({ day, month }: { day: Date; month: number }) {
|
||||||
const context = useCourseContext();
|
const context = useCourseContext();
|
||||||
|
|
||||||
const backgroundClass = day.getMonth() + 1 != month ? "" : "bg-slate-900";
|
|
||||||
|
const isInSameMonth = day.getMonth() + 1 != month
|
||||||
|
const backgroundClass = isInSameMonth ? "" : "bg-slate-900";
|
||||||
|
|
||||||
const todaysAssignments = context.localCourse.modules
|
const todaysAssignments = context.localCourse.modules
|
||||||
.flatMap((m) => m.assignments)
|
.flatMap((m) => m.assignments)
|
||||||
@@ -15,13 +17,11 @@ export default function Day({ day, month }: { day: Date; month: number }) {
|
|||||||
a.dueAt,
|
a.dueAt,
|
||||||
"due at for assignment in day"
|
"due at for assignment in day"
|
||||||
);
|
);
|
||||||
|
return (
|
||||||
const isSame =
|
|
||||||
dueDate.getFullYear() === day.getFullYear() &&
|
dueDate.getFullYear() === day.getFullYear() &&
|
||||||
dueDate.getMonth() === day.getMonth() &&
|
dueDate.getMonth() === day.getMonth() &&
|
||||||
dueDate.getDate() === day.getDate();
|
dueDate.getDate() === day.getDate()
|
||||||
if (a.name === "Chapter 3") console.log(a.name, dueDate, day, isSame);
|
);
|
||||||
return isSame;
|
|
||||||
});
|
});
|
||||||
const todaysQuizzes = context.localCourse.modules
|
const todaysQuizzes = context.localCourse.modules
|
||||||
.flatMap((m) => m.quizzes)
|
.flatMap((m) => m.quizzes)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ function createCalendarMonth(year: number, month: number): CalendarMonthModel {
|
|||||||
return new Date(year, month - 1, currentDay++);
|
return new Date(year, month - 1, currentDay++);
|
||||||
} else {
|
} else {
|
||||||
currentDay++;
|
currentDay++;
|
||||||
return new Date(year, month, currentDay - daysInMonth);
|
return new Date(year, month, currentDay - daysInMonth - 1);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user