mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
adding support for empty multiple answer
This commit is contained in:
@@ -1,17 +1,20 @@
|
||||
import { Expandable } from "@/components/Expandable";
|
||||
import TextInput from "@/components/form/TextInput";
|
||||
import { useCreateModuleMutation } from "@/hooks/localCourse/localCourseModuleHooks";
|
||||
import React, { useState } from "react";
|
||||
|
||||
export default function CreateModule() {
|
||||
const createModule = useCreateModuleMutation();
|
||||
const [showForm, setShowForm] = useState(false);
|
||||
const [moduleName, setModuleName] = useState("");
|
||||
return (
|
||||
<>
|
||||
<button onClick={() => setShowForm((v) => !v)}>
|
||||
{showForm ? "Hide Form" : "Create Module"}
|
||||
</button>
|
||||
<div className={"collapsible " + (showForm ? "expand" : "")}>
|
||||
<Expandable
|
||||
ExpandableElement={({ setIsExpanded, isExpanded }) => (
|
||||
<button onClick={() => setIsExpanded((v) => !v)}>
|
||||
{isExpanded ? "Hide Form" : "Create Module"}
|
||||
</button>
|
||||
)}
|
||||
>
|
||||
<form
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
@@ -30,7 +33,7 @@ export default function CreateModule() {
|
||||
/>
|
||||
<button className="mt-auto">Add</button>
|
||||
</form>
|
||||
</div>
|
||||
</Expandable>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,10 +7,12 @@ export default function ModuleList() {
|
||||
const { data: moduleNames } = useModuleNamesQuery();
|
||||
return (
|
||||
<div>
|
||||
<CreateModule />
|
||||
{moduleNames.map((m) => (
|
||||
<ExpandableModule key={m} moduleName={m} />
|
||||
))}
|
||||
<div className="flex flex-col justify-center">
|
||||
<CreateModule />
|
||||
</div>
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
"use client";
|
||||
|
||||
import TextInput from "@/components/form/TextInput";
|
||||
import {
|
||||
useLocalCourseSettingsQuery,
|
||||
useUpdateLocalCourseSettingsMutation,
|
||||
} from "@/hooks/localCourse/localCoursesHooks";
|
||||
import {
|
||||
dateToMarkdownString,
|
||||
getDateFromStringOrThrow,
|
||||
} from "@/models/local/timeUtils";
|
||||
import { useState } from "react";
|
||||
|
||||
const exampleString = `springBreak:
|
||||
- 10/12/2024
|
||||
- 10/13/2024
|
||||
- 10/14/2024
|
||||
laborDay:
|
||||
- 9/1/2024`;
|
||||
|
||||
export default function HolidayConfig() {
|
||||
const { data: settings } = useLocalCourseSettingsQuery();
|
||||
const updateSettings = useUpdateLocalCourseSettingsMutation();
|
||||
|
||||
const [rawText, setRawText] = useState("");
|
||||
|
||||
const parsedText = parseHolidays(rawText);
|
||||
|
||||
return (
|
||||
<div className="flex flex-row gap-3 border w-fit p-3 m-3 rounded-md">
|
||||
<TextInput
|
||||
value={rawText}
|
||||
setValue={setRawText}
|
||||
label={"Holiday Days"}
|
||||
isTextArea={true}
|
||||
/>
|
||||
<div>
|
||||
Format your holidays like so:
|
||||
<pre>
|
||||
<code>{exampleString}</code>
|
||||
</pre>
|
||||
</div>
|
||||
<div>
|
||||
{Object.keys(parsedText).map((k) => (
|
||||
<div key={k}>
|
||||
<div>{k}</div>
|
||||
<div>
|
||||
{parsedText[k].map((day) => {
|
||||
const parsedDate = getDateFromStringOrThrow(
|
||||
day,
|
||||
"holiday preview display"
|
||||
);
|
||||
return <div key={day}>{dateToMarkdownString(parsedDate)}</div>;
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const parseHolidays = (
|
||||
inputText: string
|
||||
): { [holidayName: string]: string[] } => {
|
||||
const holidays: { [holidayName: string]: string[] } = {};
|
||||
|
||||
const lines = inputText.split("\n").filter(line => line.trim() !== "");
|
||||
let currentHoliday: string | null = null;
|
||||
|
||||
lines.forEach(line => {
|
||||
if (line.includes(":")) {
|
||||
// It's a holiday name
|
||||
const holidayName = line.split(":")[0].trim();
|
||||
currentHoliday = holidayName;
|
||||
holidays[currentHoliday] = [];
|
||||
} else if (currentHoliday && line.startsWith("-")) {
|
||||
// It's a date under the current holiday
|
||||
const date = line.replace("-", "").trim();
|
||||
holidays[currentHoliday].push(date);
|
||||
}
|
||||
});
|
||||
|
||||
return holidays;
|
||||
};
|
||||
@@ -7,6 +7,7 @@ import DaysOfWeekSettings from "./DaysOfWeekSettings";
|
||||
import AssignmentGroupManagement from "./AssignmentGroupManagement";
|
||||
import SubmissionDefaults from "./SubmissionDefaults";
|
||||
import DefaultFileUploadTypes from "./DefaultFileUploadTypes";
|
||||
import HolidayConfig from "./HolidayConfig";
|
||||
|
||||
export default function page() {
|
||||
return (
|
||||
@@ -19,6 +20,7 @@ export default function page() {
|
||||
<DefaultFileUploadTypes />
|
||||
<DefaultDueTime />
|
||||
<AssignmentGroupManagement />
|
||||
<HolidayConfig />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
|
||||
Reference in New Issue
Block a user