mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
holiday data update
This commit is contained in:
@@ -26,7 +26,7 @@ export const CalendarMonth = ({ month }: { month: CalendarMonthModel }) => {
|
|||||||
<h3
|
<h3
|
||||||
className={
|
className={
|
||||||
"text-2xl transition-all duration-500 " +
|
"text-2xl transition-all duration-500 " +
|
||||||
"hover:text-slate-50 underline hover:scale-105 `"
|
"hover:text-slate-50 underline hover:scale-105 "
|
||||||
}
|
}
|
||||||
onClick={() => setIsExpanded((e) => !e)}
|
onClick={() => setIsExpanded((e) => !e)}
|
||||||
role="button"
|
role="button"
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export function CalendarWeek({
|
|||||||
const weekNumber = getWeekNumber(startDate, firstDateString);
|
const weekNumber = getWeekNumber(startDate, firstDateString);
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-row">
|
<div className="flex flex-row">
|
||||||
<div className="my-auto text-gray-400 w-5">
|
<div className="my-auto text-gray-400 w-6">
|
||||||
{weekNumber.toString().padStart(2, "0")}
|
{weekNumber.toString().padStart(2, "0")}
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-7 grow">
|
<div className="grid grid-cols-7 grow">
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import {
|
import {
|
||||||
|
dateToMarkdownString,
|
||||||
getDateFromStringOrThrow,
|
getDateFromStringOrThrow,
|
||||||
getDateOnlyMarkdownString,
|
getDateOnlyMarkdownString,
|
||||||
} from "@/models/local/timeUtils";
|
} from "@/models/local/timeUtils";
|
||||||
@@ -30,6 +31,23 @@ export default function Day({ day, month }: { day: string; month: number }) {
|
|||||||
const isInSameMonth = dayAsDate.getMonth() + 1 == month;
|
const isInSameMonth = dayAsDate.getMonth() + 1 == month;
|
||||||
const classOnThisDay = settings.daysOfWeek.includes(getDayOfWeek(dayAsDate));
|
const classOnThisDay = settings.daysOfWeek.includes(getDayOfWeek(dayAsDate));
|
||||||
|
|
||||||
|
// maybe this is slow?
|
||||||
|
const holidayNameToday = settings.holidays.reduce(
|
||||||
|
(holidaysHappeningToday, holiday) => {
|
||||||
|
const holidayDates = holiday.days.map((d) =>
|
||||||
|
getDateOnlyMarkdownString(
|
||||||
|
getDateFromStringOrThrow(d, "holiday date in day component")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
const today = getDateOnlyMarkdownString(dayAsDate);
|
||||||
|
|
||||||
|
if (holidayDates.includes(today))
|
||||||
|
return [...holidaysHappeningToday, holiday.name];
|
||||||
|
return holidaysHappeningToday;
|
||||||
|
},
|
||||||
|
[] as string[]
|
||||||
|
);
|
||||||
|
|
||||||
const semesterStart = getDateFromStringOrThrow(
|
const semesterStart = getDateFromStringOrThrow(
|
||||||
settings.startDate,
|
settings.startDate,
|
||||||
"comparing start date in day"
|
"comparing start date in day"
|
||||||
@@ -42,7 +60,9 @@ export default function Day({ day, month }: { day: string; month: number }) {
|
|||||||
const isInSemester = semesterStart < dayAsDate && semesterEnd > dayAsDate;
|
const isInSemester = semesterStart < dayAsDate && semesterEnd > dayAsDate;
|
||||||
|
|
||||||
const meetingClasses =
|
const meetingClasses =
|
||||||
classOnThisDay && isInSemester ? " bg-slate-900 " : " ";
|
classOnThisDay && isInSemester && holidayNameToday.length === 0
|
||||||
|
? " bg-slate-900 "
|
||||||
|
: " ";
|
||||||
|
|
||||||
const todayClasses = isToday
|
const todayClasses = isToday
|
||||||
? " border border-blue-700 shadow-[0_0px_10px_0px] shadow-blue-500/50 "
|
? " border border-blue-700 shadow-[0_0px_10px_0px] shadow-blue-500/50 "
|
||||||
@@ -53,13 +73,15 @@ export default function Day({ day, month }: { day: string; month: number }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={" rounded-lg m-1 min-h-10 " + meetingClasses + monthClass + todayClasses}
|
className={
|
||||||
|
" rounded-lg m-1 min-h-10 " + meetingClasses + monthClass + todayClasses
|
||||||
|
}
|
||||||
onDrop={(e) => itemDropOnDay(e, day)}
|
onDrop={(e) => itemDropOnDay(e, day)}
|
||||||
onDragOver={(e) => e.preventDefault()}
|
onDragOver={(e) => e.preventDefault()}
|
||||||
>
|
>
|
||||||
<div className="draggingDay">
|
<div className="draggingDay flex flex-col">
|
||||||
<DayTitle day={day} dayAsDate={dayAsDate} />
|
<DayTitle day={day} dayAsDate={dayAsDate} />
|
||||||
<div>
|
<div className="flex-grow">
|
||||||
{todaysAssignments.map(
|
{todaysAssignments.map(
|
||||||
({ assignment, moduleName, status, message }) => (
|
({ assignment, moduleName, status, message }) => (
|
||||||
<ItemInDay
|
<ItemInDay
|
||||||
@@ -93,6 +115,13 @@ export default function Day({ day, month }: { day: string; month: number }) {
|
|||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
{holidayNameToday.map((n) => (
|
||||||
|
<div key={n} className="font-extrabold text-blue-100 text-center">
|
||||||
|
{n}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,12 +6,7 @@ import {
|
|||||||
useLocalCourseSettingsQuery,
|
useLocalCourseSettingsQuery,
|
||||||
useUpdateLocalCourseSettingsMutation,
|
useUpdateLocalCourseSettingsMutation,
|
||||||
} from "@/hooks/localCourse/localCoursesHooks";
|
} from "@/hooks/localCourse/localCoursesHooks";
|
||||||
import {
|
import { getDateFromString } from "@/models/local/timeUtils";
|
||||||
dateToMarkdownString,
|
|
||||||
getDateFromString,
|
|
||||||
getDateFromStringOrThrow,
|
|
||||||
getDateOnlyMarkdownString,
|
|
||||||
} from "@/models/local/timeUtils";
|
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import {
|
import {
|
||||||
holidaysToString,
|
holidaysToString,
|
||||||
@@ -26,27 +21,33 @@ laborDay:
|
|||||||
- 9/1/2024`;
|
- 9/1/2024`;
|
||||||
|
|
||||||
export const holidaysAreEqual = (
|
export const holidaysAreEqual = (
|
||||||
obj1: { [key: string]: string[] },
|
obj1: {
|
||||||
obj2: { [key: string]: string[] }
|
name: string;
|
||||||
|
days: string[];
|
||||||
|
}[],
|
||||||
|
obj2: {
|
||||||
|
name: string;
|
||||||
|
days: string[];
|
||||||
|
}[]
|
||||||
): boolean => {
|
): boolean => {
|
||||||
const keys1 = Object.keys(obj1);
|
if (obj1.length !== obj2.length) return false;
|
||||||
const keys2 = Object.keys(obj2);
|
|
||||||
|
|
||||||
if (keys1.length !== keys2.length) return false;
|
const sortedObj1 = [...obj1].sort((a, b) => a.name.localeCompare(b.name));
|
||||||
|
const sortedObj2 = [...obj2].sort((a, b) => a.name.localeCompare(b.name));
|
||||||
|
|
||||||
for (const key of keys1) {
|
for (let i = 0; i < sortedObj1.length; i++) {
|
||||||
if (!obj2.hasOwnProperty(key)) return false;
|
const holiday1 = sortedObj1[i];
|
||||||
|
const holiday2 = sortedObj2[i];
|
||||||
|
|
||||||
const arr1 = obj1[key];
|
if (holiday1.name !== holiday2.name) return false;
|
||||||
const arr2 = obj2[key];
|
|
||||||
|
|
||||||
if (arr1.length !== arr2.length) return false;
|
const sortedDays1 = [...holiday1.days].sort();
|
||||||
|
const sortedDays2 = [...holiday2.days].sort();
|
||||||
|
|
||||||
const sortedArr1 = [...arr1].sort();
|
if (sortedDays1.length !== sortedDays2.length) return false;
|
||||||
const sortedArr2 = [...arr2].sort();
|
|
||||||
|
|
||||||
for (let i = 0; i < sortedArr1.length; i++) {
|
for (let j = 0; j < sortedDays1.length; j++) {
|
||||||
if (sortedArr1[i] !== sortedArr2[i]) return false;
|
if (sortedDays1[j] !== sortedDays2[j]) return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,6 +63,7 @@ export default function HolidayConfig() {
|
|||||||
}
|
}
|
||||||
function InnerHolidayConfig() {
|
function InnerHolidayConfig() {
|
||||||
const { data: settings } = useLocalCourseSettingsQuery();
|
const { data: settings } = useLocalCourseSettingsQuery();
|
||||||
|
console.log(settings.holidays);
|
||||||
const updateSettings = useUpdateLocalCourseSettingsMutation();
|
const updateSettings = useUpdateLocalCourseSettingsMutation();
|
||||||
|
|
||||||
const [rawText, setRawText] = useState(holidaysToString(settings.holidays));
|
const [rawText, setRawText] = useState(holidaysToString(settings.holidays));
|
||||||
@@ -71,15 +73,17 @@ function InnerHolidayConfig() {
|
|||||||
try {
|
try {
|
||||||
const parsed = parseHolidays(rawText);
|
const parsed = parseHolidays(rawText);
|
||||||
|
|
||||||
if (!holidaysAreEqual(settings.holidays, parsed))
|
if (!holidaysAreEqual(settings.holidays, parsed)) {
|
||||||
|
console.log("different holiday configs", settings.holidays, parsed);
|
||||||
updateSettings.mutate({
|
updateSettings.mutate({
|
||||||
...settings,
|
...settings,
|
||||||
holidays: parsed,
|
holidays: parsed,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
} catch (error: any) {}
|
} catch (error: any) {}
|
||||||
}, 500);
|
}, 500);
|
||||||
return () => clearTimeout(id);
|
return () => clearTimeout(id);
|
||||||
}, [rawText, settings, updateSettings]);
|
}, [rawText, settings.holidays, settings, updateSettings]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className=" border w-fit p-3 m-3 rounded-md">
|
<div className=" border w-fit p-3 m-3 rounded-md">
|
||||||
@@ -107,9 +111,12 @@ function InnerHolidayConfig() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ParsedHolidaysDisplay({ value }: { value: string }) {
|
function ParsedHolidaysDisplay({ value }: { value: string }) {
|
||||||
const [parsedHolidays, setParsedHolidays] = useState<{
|
const [parsedHolidays, setParsedHolidays] = useState<
|
||||||
[holidayName: string]: string[];
|
{
|
||||||
}>({});
|
name: string;
|
||||||
|
days: string[];
|
||||||
|
}[]
|
||||||
|
>([]);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -125,11 +132,11 @@ function ParsedHolidaysDisplay({ value }: { value: string }) {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="text-rose-500">{error}</div>
|
<div className="text-rose-500">{error}</div>
|
||||||
{Object.keys(parsedHolidays).map((k) => (
|
{parsedHolidays.map((holiday) => (
|
||||||
<div key={k}>
|
<div key={holiday.name}>
|
||||||
<div>{k}</div>
|
<div>{holiday.name}</div>
|
||||||
<div>
|
<div>
|
||||||
{parsedHolidays[k].map((day) => {
|
{holiday.days.map((day) => {
|
||||||
const date = getDateFromString(day);
|
const date = getDateFromString(day);
|
||||||
return (
|
return (
|
||||||
<div key={day}>
|
<div key={day}>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { hydrateCourses } from "@/hooks/hookHydration";
|
|||||||
import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
|
import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
|
||||||
import { MyToaster } from "./MyToaster";
|
import { MyToaster } from "./MyToaster";
|
||||||
import { cookies } from "next/headers";
|
import { cookies } from "next/headers";
|
||||||
|
export const dynamic = 'force-dynamic'
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Canvas Manager 2.0",
|
title: "Canvas Manager 2.0",
|
||||||
|
|||||||
@@ -23,10 +23,11 @@ export const useLocalCoursesSettingsQuery = () =>
|
|||||||
|
|
||||||
export const useLocalCourseSettingsQuery = () => {
|
export const useLocalCourseSettingsQuery = () => {
|
||||||
const { courseName } = useCourseContext();
|
const { courseName } = useCourseContext();
|
||||||
const { data: settingsList } = useLocalCoursesSettingsQuery();
|
// const { data: settingsList } = useLocalCoursesSettingsQuery();
|
||||||
return useSuspenseQuery({
|
return useSuspenseQuery({
|
||||||
queryKey: localCourseKeys.settings(courseName),
|
queryKey: localCourseKeys.settings(courseName),
|
||||||
queryFn: () => {
|
queryFn: async () => {
|
||||||
|
const settingsList = await getAllCoursesSettingsFromServer();
|
||||||
const s = settingsList.find((s) => s.name === courseName);
|
const s = settingsList.find((s) => s.name === courseName);
|
||||||
if (!s) {
|
if (!s) {
|
||||||
console.log(courseName, settingsList);
|
console.log(courseName, settingsList);
|
||||||
@@ -56,19 +57,22 @@ export const useUpdateLocalCourseSettingsMutation = () => {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async (updatedSettings: LocalCourseSettings) => {
|
mutationFn: async (updatedSettings: LocalCourseSettings) => {
|
||||||
queryClient.setQueryData(
|
// queryClient.setQueryData(
|
||||||
localCourseKeys.settings(courseName),
|
// localCourseKeys.settings(courseName),
|
||||||
updatedSettings
|
// updatedSettings
|
||||||
);
|
// );
|
||||||
await updateCourseSettingsOnServer({ courseName, settings: updatedSettings });
|
await updateCourseSettingsOnServer({
|
||||||
},
|
courseName,
|
||||||
onSuccess: () => {
|
settings: updatedSettings,
|
||||||
queryClient.invalidateQueries({
|
|
||||||
queryKey: localCourseKeys.settings(courseName),
|
|
||||||
});
|
});
|
||||||
queryClient.invalidateQueries({
|
},
|
||||||
|
onSuccess: async () => {
|
||||||
|
await queryClient.invalidateQueries({
|
||||||
queryKey: localCourseKeys.allCoursesSettings,
|
queryKey: localCourseKeys.allCoursesSettings,
|
||||||
});
|
});
|
||||||
|
await queryClient.invalidateQueries({
|
||||||
|
queryKey: localCourseKeys.settings(courseName),
|
||||||
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,8 +25,9 @@ export interface LocalCourseSettings {
|
|||||||
defaultAssignmentSubmissionTypes: AssignmentSubmissionType[];
|
defaultAssignmentSubmissionTypes: AssignmentSubmissionType[];
|
||||||
defaultFileUploadTypes: string[];
|
defaultFileUploadTypes: string[];
|
||||||
holidays: {
|
holidays: {
|
||||||
[key: string]: string[]; // e.g. "spring break": ["datestring", "datestring", "datestring", "datestring"]
|
name: string;
|
||||||
};
|
days: string[];
|
||||||
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum DayOfWeek {
|
export enum DayOfWeek {
|
||||||
@@ -46,7 +47,7 @@ export function getDayOfWeek(date: Date): DayOfWeek {
|
|||||||
|
|
||||||
export const localCourseYamlUtils = {
|
export const localCourseYamlUtils = {
|
||||||
parseSettingYaml: (settingsString: string): LocalCourseSettings => {
|
parseSettingYaml: (settingsString: string): LocalCourseSettings => {
|
||||||
const settings = parse(settingsString);
|
const settings = parse(settingsString, {});
|
||||||
return lowercaseFirstLetter(settings);
|
return lowercaseFirstLetter(settings);
|
||||||
},
|
},
|
||||||
settingsToYaml: (settings: Omit<LocalCourseSettings, "name">) => {
|
settingsToYaml: (settings: Omit<LocalCourseSettings, "name">) => {
|
||||||
|
|||||||
@@ -7,8 +7,14 @@ import {
|
|||||||
|
|
||||||
export const parseHolidays = (
|
export const parseHolidays = (
|
||||||
inputText: string
|
inputText: string
|
||||||
): { [holidayName: string]: string[] } => {
|
): {
|
||||||
const holidays: { [holidayName: string]: string[] } = {};
|
name: string;
|
||||||
|
days: string[];
|
||||||
|
}[] => {
|
||||||
|
let holidays: {
|
||||||
|
name: string;
|
||||||
|
days: string[];
|
||||||
|
}[] = [];
|
||||||
|
|
||||||
const lines = inputText.split("\n").filter((line) => line.trim() !== "");
|
const lines = inputText.split("\n").filter((line) => line.trim() !== "");
|
||||||
let currentHoliday: string | null = null;
|
let currentHoliday: string | null = null;
|
||||||
@@ -17,24 +23,30 @@ export const parseHolidays = (
|
|||||||
if (line.includes(":")) {
|
if (line.includes(":")) {
|
||||||
const holidayName = line.split(":")[0].trim();
|
const holidayName = line.split(":")[0].trim();
|
||||||
currentHoliday = holidayName;
|
currentHoliday = holidayName;
|
||||||
holidays[currentHoliday] = [];
|
holidays = [...holidays, { name: holidayName, days: [] }];
|
||||||
} else if (currentHoliday && line.startsWith("-")) {
|
} else if (currentHoliday && line.startsWith("-")) {
|
||||||
const date = line.replace("-", "").trim();
|
const date = line.replace("-", "").trim();
|
||||||
const dateObject = getDateFromStringOrThrow(date, "parsing holiday text");
|
const dateObject = getDateFromStringOrThrow(date, "parsing holiday text");
|
||||||
holidays[currentHoliday].push(getDateOnlyMarkdownString(dateObject));
|
|
||||||
|
const holiday = holidays.find((h) => h.name == currentHoliday);
|
||||||
|
holiday?.days.push(getDateOnlyMarkdownString(dateObject));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return holidays;
|
return holidays;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const holidaysToString = (
|
||||||
|
holidays: {
|
||||||
|
name: string;
|
||||||
|
days: string[];
|
||||||
|
}[]
|
||||||
|
) => {
|
||||||
|
const entries = holidays.map((holiday) => {
|
||||||
|
const title = holiday.name + ":\n";
|
||||||
|
const days = holiday.days.map((d) => `- ${d}\n`);
|
||||||
|
return title + days.join("");
|
||||||
|
});
|
||||||
|
|
||||||
export const holidaysToString = (holidays: { [holidayName: string]: string[] })=> {
|
return entries.join("");
|
||||||
const entries = Object.keys(holidays).map(holiday => {
|
};
|
||||||
const title = holiday + ":\n"
|
|
||||||
const days = holidays[holiday].map(d => `- ${d}\n`)
|
|
||||||
return title + days.join("")
|
|
||||||
})
|
|
||||||
|
|
||||||
return entries.join("")
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ const populateDefaultValues = (settingsFromFile: LocalCourseSettings) => {
|
|||||||
defaultSubmissionType,
|
defaultSubmissionType,
|
||||||
defaultFileUploadTypes:
|
defaultFileUploadTypes:
|
||||||
settingsFromFile.defaultFileUploadTypes || defaultFileUploadTypes,
|
settingsFromFile.defaultFileUploadTypes || defaultFileUploadTypes,
|
||||||
holidays: !!settingsFromFile.holidays ? settingsFromFile.holidays : {},
|
holidays: !!settingsFromFile.holidays ? settingsFromFile.holidays : [],
|
||||||
};
|
};
|
||||||
return settings;
|
return settings;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user