mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
pre codemon
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {};
|
const nextConfig = {
|
||||||
|
|
||||||
|
};
|
||||||
|
devServer.fastRefresh = true;
|
||||||
|
|
||||||
export default nextConfig;
|
export default nextConfig;
|
||||||
|
|||||||
63
nextjs/src/app/course/[courseName]/CalendarMonth.tsx
Normal file
63
nextjs/src/app/course/[courseName]/CalendarMonth.tsx
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
"use client"
|
||||||
|
import { FC, useState } from "react";
|
||||||
|
import { CalendarMonthModel } from "./calendarMonthUtils";
|
||||||
|
import { DayOfWeek, LocalCourse } from "@/models/local/localCourse";
|
||||||
|
import { Day } from "./Day";
|
||||||
|
|
||||||
|
export const CalendarMonth: FC<{
|
||||||
|
month: CalendarMonthModel;
|
||||||
|
localCourse: LocalCourse;
|
||||||
|
}> = ({ month, localCourse }) => {
|
||||||
|
const [isCollapsed, setIsCollapsed] = useState(false);
|
||||||
|
|
||||||
|
const isInPast =
|
||||||
|
new Date(month.year, month.month - 1, 1) < new Date(Date.now());
|
||||||
|
const monthName = new Date(month.year, month.month - 1, 1).toLocaleString(
|
||||||
|
"default",
|
||||||
|
{ month: "long" }
|
||||||
|
);
|
||||||
|
const toggleCollapse = () => setIsCollapsed(!isCollapsed);
|
||||||
|
// const collapseClass = isInPast ? "collapse _hide" : "collapse _show";
|
||||||
|
const weekDaysList: DayOfWeek[] = Object.values(DayOfWeek);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h3 className="text-center">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-link"
|
||||||
|
onClick={toggleCollapse}
|
||||||
|
aria-expanded={!isCollapsed}
|
||||||
|
aria-controls={monthName}
|
||||||
|
>
|
||||||
|
{monthName}
|
||||||
|
</button>
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<div id={monthName}>
|
||||||
|
<div className="grid grid-cols-7 text-center fw-bold">
|
||||||
|
{weekDaysList.map((day) => (
|
||||||
|
<div
|
||||||
|
key={day}
|
||||||
|
className={
|
||||||
|
localCourse?.settings.daysOfWeek.includes(day)
|
||||||
|
? "col"
|
||||||
|
: "col text-secondary"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{day}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{month.daysByWeek.map((week, weekIndex) => (
|
||||||
|
<div className="grid grid-cols-7 m-3" key={weekIndex}>
|
||||||
|
{week.map((day, dayIndex) => (
|
||||||
|
<Day key={dayIndex} day={day} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
9
nextjs/src/app/course/[courseName]/Day.tsx
Normal file
9
nextjs/src/app/course/[courseName]/Day.tsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
"use client"
|
||||||
|
import React, { FC } from "react";
|
||||||
|
|
||||||
|
export const Day: FC<{ day?: Date }> = ({ day }) => {
|
||||||
|
const classes = "border rounded rounded-3 p-2 pb-4 m-1 ";
|
||||||
|
if (!day) return <div className={classes + ""}></div>;
|
||||||
|
|
||||||
|
return <div className={classes + " bg-slate-900"}>{day.getDate()}</div>;
|
||||||
|
};
|
||||||
@@ -1,66 +1,80 @@
|
|||||||
interface CalendarMonth {
|
"use client";
|
||||||
|
export interface CalendarMonthModel {
|
||||||
year: number;
|
year: number;
|
||||||
month: number;
|
month: number;
|
||||||
weeks: (number | null)[][];
|
weeks: (number | undefined)[][];
|
||||||
daysByWeek: (Date | null)[][];
|
daysByWeek: (Date | undefined)[][];
|
||||||
}
|
}
|
||||||
|
|
||||||
const calendarMonthUtils = {
|
const weeksInMonth = (year: number, month: number): number => {
|
||||||
weeksInMonth: (year: number, month: number): number => {
|
const firstDayOfMonth = new Date(year, month - 1, 1).getDay();
|
||||||
const firstDayOfMonth = new Date(year, month - 1, 1).getDay();
|
const daysInMonth = new Date(year, month, 0).getDate();
|
||||||
const daysInMonth = new Date(year, month, 0).getDate();
|
const longDaysInMonth = daysInMonth + firstDayOfMonth;
|
||||||
const longDaysInMonth = daysInMonth + firstDayOfMonth;
|
let weeks = Math.floor(longDaysInMonth / 7);
|
||||||
let weeks = Math.floor(longDaysInMonth / 7);
|
if (longDaysInMonth % 7 > 0) {
|
||||||
if (longDaysInMonth % 7 > 0) {
|
weeks += 1;
|
||||||
weeks += 1;
|
}
|
||||||
}
|
return weeks;
|
||||||
return weeks;
|
};
|
||||||
},
|
|
||||||
|
|
||||||
createCalendarMonth: (year: number, month: number): CalendarMonth => {
|
export const createCalendarMonth = (
|
||||||
const daysByWeek: (Date | null)[][] = [];
|
year: number,
|
||||||
const weeksInMonth = calendarMonthUtils.weeksInMonth(year, month);
|
month: number
|
||||||
const daysInMonth = new Date(year, month, 0).getDate();
|
): CalendarMonthModel => {
|
||||||
|
const daysByWeek: (Date | undefined)[][] = [];
|
||||||
|
const weeksNumber = weeksInMonth(year, month);
|
||||||
|
const daysInMonth = new Date(year, month, 0).getDate();
|
||||||
|
|
||||||
let currentDay = 1;
|
let currentDay = 1;
|
||||||
const firstDayOfMonth = new Date(year, month - 1, 1).getDay();
|
const firstDayOfMonth = new Date(year, month - 1, 1).getDay();
|
||||||
|
|
||||||
for (let i = 0; i < weeksInMonth; i++) {
|
for (let i = 0; i < weeksNumber; i++) {
|
||||||
const thisWeek: (Date | null)[] = [];
|
const thisWeek: (Date | undefined)[] = [];
|
||||||
if (i === 0 && firstDayOfMonth !== 0) { // 0 is Sunday in JavaScript
|
if (i === 0 && firstDayOfMonth !== 0) {
|
||||||
for (let j = 0; j < 7; j++) {
|
// 0 is Sunday in JavaScript
|
||||||
if (j < firstDayOfMonth) {
|
for (let j = 0; j < 7; j++) {
|
||||||
thisWeek.push(null);
|
if (j < firstDayOfMonth) {
|
||||||
} else {
|
thisWeek.push(undefined);
|
||||||
thisWeek.push(new Date(year, month - 1, currentDay));
|
} else {
|
||||||
currentDay++;
|
thisWeek.push(new Date(year, month - 1, currentDay));
|
||||||
}
|
currentDay++;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
for (let j = 0; j < 7; j++) {
|
} else {
|
||||||
if (currentDay <= daysInMonth) {
|
for (let j = 0; j < 7; j++) {
|
||||||
thisWeek.push(new Date(year, month - 1, currentDay));
|
if (currentDay <= daysInMonth) {
|
||||||
currentDay++;
|
thisWeek.push(new Date(year, month - 1, currentDay));
|
||||||
} else {
|
currentDay++;
|
||||||
thisWeek.push(null);
|
} else {
|
||||||
}
|
thisWeek.push(undefined);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
daysByWeek.push(thisWeek);
|
|
||||||
}
|
}
|
||||||
|
daysByWeek.push(thisWeek);
|
||||||
const weeks = daysByWeek.map(week => week.map(day => day ? day.getDate() : null));
|
|
||||||
|
|
||||||
return { year, month, weeks, daysByWeek };
|
|
||||||
},
|
|
||||||
|
|
||||||
getMonthsBetweenDates: (startDate: Date, endDate: Date): CalendarMonth[] => {
|
|
||||||
const monthsInTerm = 1 + (endDate.getFullYear() - startDate.getFullYear()) * 12 + endDate.getMonth() - startDate.getMonth();
|
|
||||||
|
|
||||||
return Array.from({ length: monthsInTerm }, (_, monthDiff) => {
|
|
||||||
const month = ((startDate.getMonth() + monthDiff) % 12) + 1;
|
|
||||||
const year = startDate.getFullYear() + Math.floor((startDate.getMonth() + monthDiff) / 12);
|
|
||||||
return calendarMonthUtils.createCalendarMonth(year, month);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const weeks = daysByWeek.map((week) =>
|
||||||
|
week.map((day) => (day ? day.getDate() : undefined))
|
||||||
|
);
|
||||||
|
|
||||||
|
return { year, month, weeks, daysByWeek };
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getMonthsBetweenDates = (
|
||||||
|
startDate: Date,
|
||||||
|
endDate: Date
|
||||||
|
): CalendarMonthModel[] => {
|
||||||
|
const monthsInTerm =
|
||||||
|
1 +
|
||||||
|
(endDate.getFullYear() - startDate.getFullYear()) * 12 +
|
||||||
|
endDate.getMonth() -
|
||||||
|
startDate.getMonth();
|
||||||
|
|
||||||
|
return Array.from({ length: monthsInTerm }, (_, monthDiff) => {
|
||||||
|
const month = ((startDate.getMonth() + monthDiff) % 12) + 1;
|
||||||
|
const year =
|
||||||
|
startDate.getFullYear() +
|
||||||
|
Math.floor((startDate.getMonth() + monthDiff) / 12);
|
||||||
|
return createCalendarMonth(year, month);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { useLocalCourseDetailsQuery } from "@/hooks/localCoursesHooks";
|
import { useLocalCourseDetailsQuery } from "@/hooks/localCoursesHooks";
|
||||||
import { getDateFromStringOrThrow } from "@/models/local/timeUtils";
|
import { getDateFromStringOrThrow } from "@/models/local/timeUtils";
|
||||||
|
import { getMonthsBetweenDates } from "./calendarMonthUtils";
|
||||||
|
import { CalendarMonth } from "./CalendarMonth";
|
||||||
|
|
||||||
export default function Page({
|
export default function Page({
|
||||||
params: { courseName },
|
params: { courseName },
|
||||||
@@ -8,18 +10,17 @@ export default function Page({
|
|||||||
params: { courseName: string };
|
params: { courseName: string };
|
||||||
}) {
|
}) {
|
||||||
const { data: course } = useLocalCourseDetailsQuery(courseName);
|
const { data: course } = useLocalCourseDetailsQuery(courseName);
|
||||||
console.log(course);
|
|
||||||
|
|
||||||
const startDate = getDateFromStringOrThrow(course.settings.startDate);
|
const startDate = getDateFromStringOrThrow(course.settings.startDate);
|
||||||
const endDate = getDateFromStringOrThrow(course.settings.endDate);
|
const endDate = getDateFromStringOrThrow(course.settings.endDate);
|
||||||
|
|
||||||
const months = calendarMonthUtils.getMonthsBetweenDates(startDate, endDate);
|
const months = getMonthsBetweenDates(startDate, endDate);
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{course.settings.name}
|
{course.settings.name}
|
||||||
<div>
|
<div>
|
||||||
{months.map((month) => (
|
{months.map((month) => (
|
||||||
<div key={month.month + "" + month.year}>{month.month}</div>
|
<CalendarMonth key={month.month + "" + month.year} month={month} localCourse={course} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -73,7 +73,6 @@ export const courseMarkdownLoader = {
|
|||||||
|
|
||||||
const settingsString = await fs.readFile(settingsPath, "utf-8");
|
const settingsString = await fs.readFile(settingsPath, "utf-8");
|
||||||
const settings = localCourseYamlUtils.parseSettingYaml(settingsString);
|
const settings = localCourseYamlUtils.parseSettingYaml(settingsString);
|
||||||
console.log(settingsString, settings);
|
|
||||||
|
|
||||||
const folderName = path.basename(courseDirectory);
|
const folderName = path.basename(courseDirectory);
|
||||||
return { ...settings, name: folderName };
|
return { ...settings, name: folderName };
|
||||||
|
|||||||
@@ -6,15 +6,7 @@ const config: Config = {
|
|||||||
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
|
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
|
||||||
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
|
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
|
||||||
],
|
],
|
||||||
theme: {
|
theme: {},
|
||||||
extend: {
|
|
||||||
backgroundImage: {
|
|
||||||
"gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
|
|
||||||
"gradient-conic":
|
|
||||||
"conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
plugins: [],
|
plugins: [],
|
||||||
};
|
};
|
||||||
export default config;
|
export default config;
|
||||||
|
|||||||
Reference in New Issue
Block a user