diff --git a/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/AssignmentButtons.tsx b/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/AssignmentFooterButtons.tsx similarity index 98% rename from src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/AssignmentButtons.tsx rename to src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/AssignmentFooterButtons.tsx index 9991e56..ceb3a09 100644 --- a/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/AssignmentButtons.tsx +++ b/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/AssignmentFooterButtons.tsx @@ -18,7 +18,7 @@ import Link from "next/link"; import { useRouter } from "next/navigation"; import { useState } from "react"; -export function AssignmentButtons({ +export function AssignmentFooterButtons({ moduleName, assignmentName, toggleHelp, @@ -54,8 +54,6 @@ export function AssignmentButtons({ deleteFromCanvas.isPending || updateAssignment.isPending; - console.log("assignment pending", updateAssignment.isPending); - return (
diff --git a/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/EditAssignment.tsx b/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/EditAssignment.tsx index 2ff7194..92caa09 100644 --- a/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/EditAssignment.tsx +++ b/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/EditAssignment.tsx @@ -11,7 +11,6 @@ import { } from "@/models/local/assignment/localAssignment"; import { useEffect, useState } from "react"; import AssignmentPreview from "./AssignmentPreview"; -import { getModuleItemUrl } from "@/services/urlUtils"; import { useCourseContext } from "@/app/course/[courseName]/context/courseContext"; import { useLocalCourseSettingsQuery } from "@/hooks/localCourse/localCoursesHooks"; import ClientOnly from "@/components/ClientOnly"; @@ -19,9 +18,9 @@ import { SuspenseAndErrorHandling } from "@/components/SuspenseAndErrorHandling" import { AssignmentSubmissionType } from "@/models/local/assignment/assignmentSubmissionType"; import { LocalCourseSettings } from "@/models/local/localCourseSettings"; import { useRouter } from "next/navigation"; -import { AssignmentButtons } from "./AssignmentButtons"; +import { AssignmentFooterButtons } from "./AssignmentFooterButtons"; import { useAuthoritativeUpdates } from "@/app/course/[courseName]/utils/useAuthoritativeUpdates"; -import { extractLabelValue } from "@/models/local/assignment/utils/markdownUtils"; +import EditAssignmentHeader from "./EditAssignmentHeader"; export default function EditAssignment({ moduleName, @@ -65,39 +64,38 @@ export default function EditAssignment({ return; } - const name = extractLabelValue(text, "Name"); + // make separate way to update name? const updatedAssignment: LocalAssignment = - localAssignmentMarkdown.parseMarkdown(text, name); + localAssignmentMarkdown.parseMarkdown(text, assignmentName); if ( localAssignmentMarkdown.toMarkdown(assignment) !== localAssignmentMarkdown.toMarkdown(updatedAssignment) ) { if (clientIsAuthoritative) { console.log("updating assignment, client is authoritative"); - updateAssignment - .mutateAsync({ - assignment: updatedAssignment, - moduleName, - assignmentName: updatedAssignment.name, - previousModuleName: moduleName, - previousAssignmentName: assignmentName, - courseName, - }) - .then(async () => { - // await new Promise(resolve => setTimeout(resolve, 1000)); + updateAssignment.mutateAsync({ + assignment: updatedAssignment, + moduleName, + assignmentName, + previousModuleName: moduleName, + previousAssignmentName: assignmentName, + courseName, + }); + // .then(async () => { + // // await new Promise(resolve => setTimeout(resolve, 1000)); - if (updatedAssignment.name !== assignmentName) - router.replace( - getModuleItemUrl( - courseName, - moduleName, - "assignment", - updatedAssignment.name - ), { - - } - ); - }); + // if (updatedAssignment.name !== assignmentName) + // router.replace( + // getModuleItemUrl( + // courseName, + // moduleName, + // "assignment", + // updatedAssignment.name + // ), { + + // } + // ); + // }); } else { console.log( "client not authoritative, updating client with server assignment", @@ -135,6 +133,10 @@ export default function EditAssignment({ return (
+
{showHelp && (
@@ -158,7 +160,7 @@ export default function EditAssignment({
       
- setShowHelp((h) => !h)} diff --git a/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/EditAssignmentHeader.tsx b/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/EditAssignmentHeader.tsx new file mode 100644 index 0000000..200f01c --- /dev/null +++ b/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/EditAssignmentHeader.tsx @@ -0,0 +1,26 @@ +import { useCourseContext } from "@/app/course/[courseName]/context/courseContext"; +import { UpdateAssignmentName } from "./UpdateAssignmentName"; +import { getCourseUrl } from "@/services/urlUtils"; +import Link from "next/link"; + +export default function EditAssignmentHeader({ + moduleName, + assignmentName, +}: { + assignmentName: string; + moduleName: string; +}) { + const { courseName } = useCourseContext(); + return ( +
+ + {courseName} + + +
{assignmentName}
+
+ ); +} diff --git a/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/UpdateAssignmentName.tsx b/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/UpdateAssignmentName.tsx new file mode 100644 index 0000000..f9d52de --- /dev/null +++ b/src/app/course/[courseName]/modules/[moduleName]/assignment/[assignmentName]/UpdateAssignmentName.tsx @@ -0,0 +1,71 @@ +import { useCourseContext } from "@/app/course/[courseName]/context/courseContext"; +import TextInput from "@/components/form/TextInput"; +import Modal, { useModal } from "@/components/Modal"; +import { Spinner } from "@/components/Spinner"; +import { + useAssignmentQuery, + useUpdateAssignmentMutation, +} from "@/hooks/localCourse/assignmentHooks"; +import { getModuleItemUrl } from "@/services/urlUtils"; +import { useRouter } from "next/navigation"; +import { useState } from "react"; + +export function UpdateAssignmentName({ + moduleName, + assignmentName, +}: { + assignmentName: string; + moduleName: string; +}) { + const modal = useModal(); + const { courseName } = useCourseContext(); + const router = useRouter(); + const [assignment] = useAssignmentQuery(moduleName, assignmentName); + const updateAssignment = useUpdateAssignmentMutation(); + const [name, setName] = useState(assignment.name); + const [isLoading, setIsLoading] = useState(false); + + return ( +
+ + {({ closeModal }) => ( +
{ + e.preventDefault(); + if (name === assignmentName) closeModal(); + + setIsLoading(true); // page refresh resets flag + await updateAssignment.mutateAsync({ + assignment: assignment, + moduleName, + assignmentName: name, + previousModuleName: moduleName, + previousAssignmentName: assignmentName, + courseName, + }); + + // update url (will trigger reload...) + router.replace( + getModuleItemUrl(courseName, moduleName, "assignment", name), + {} + ); + }} + > + + + {isLoading && } + + )} +
+
+ ); +} diff --git a/src/app/globals.css b/src/app/globals.css index e2c1998..a529d6e 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -87,6 +87,10 @@ button, @apply font-bold py-1 px-3 rounded transition-all duration-200; } +.btn-thin { + @apply py-0; +} + button:not(.unstyled):not(.btn-danger), .btn:not(.unstyled):not(.btn-danger) { @apply bg-blue-900 hover:bg-blue-700 text-blue-50; diff --git a/src/models/local/assignment/utils/assignmentMarkdownParser.ts b/src/models/local/assignment/utils/assignmentMarkdownParser.ts index a99b5b9..2e4a6af 100644 --- a/src/models/local/assignment/utils/assignmentMarkdownParser.ts +++ b/src/models/local/assignment/utils/assignmentMarkdownParser.ts @@ -130,7 +130,7 @@ export const assignmentMarkdownParser = { const rubric = parseRubricMarkdown(rubricString); const assignment: LocalAssignment = { - name: name.trim(), + name, localAssignmentGroupName: assignmentGroupName.trim(), submissionTypes: submissionTypes, allowedFileUploadExtensions: fileUploadExtensions, diff --git a/src/models/local/assignment/utils/assignmentMarkdownSerializer.ts b/src/models/local/assignment/utils/assignmentMarkdownSerializer.ts index 8ea2a9b..001f5f8 100644 --- a/src/models/local/assignment/utils/assignmentMarkdownSerializer.ts +++ b/src/models/local/assignment/utils/assignmentMarkdownSerializer.ts @@ -26,7 +26,6 @@ const settingsToMarkdown = (assignment: LocalAssignment) => { .join("\n"); const settingsMarkdown = [ - `Name: ${assignment.name}`, `LockAt: ${printableLockAt}`, `DueAt: ${printableDueDate}`, `AssignmentGroupName: ${assignment.localAssignmentGroupName}`,