From dc1673c053cf87263418a217b954ddef1b3f62fa Mon Sep 17 00:00:00 2001 From: swve Date: Thu, 8 Aug 2024 21:07:29 +0200 Subject: [PATCH] fix: UI bugs --- .../activity/[activityid]/activity.tsx | 16 +++++++++------- .../app/orgs/[orgslug]/dash/assignments/page.tsx | 7 +++---- .../Activities/Assignment/AssignmentBoxUI.tsx | 13 ++++++++----- apps/web/services/courses/assignments.ts | 2 +- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/apps/web/app/orgs/[orgslug]/(withmenu)/course/[courseuuid]/activity/[activityid]/activity.tsx b/apps/web/app/orgs/[orgslug]/(withmenu)/course/[courseuuid]/activity/[activityid]/activity.tsx index 45ea5944..91e0aac7 100644 --- a/apps/web/app/orgs/[orgslug]/(withmenu)/course/[courseuuid]/activity/[activityid]/activity.tsx +++ b/apps/web/app/orgs/[orgslug]/(withmenu)/course/[courseuuid]/activity/[activityid]/activity.tsx @@ -21,7 +21,7 @@ import { getAssignmentFromActivityUUID, getFinalGrade, submitAssignmentForGradin import AssignmentStudentActivity from '@components/Objects/Activities/Assignment/AssignmentStudentActivity' import { AssignmentProvider } from '@components/Contexts/Assignments/AssignmentContext' import { AssignmentsTaskProvider } from '@components/Contexts/Assignments/AssignmentsTaskContext' -import AssignmentSubmissionProvider, { AssignmentSubmissionContext, useAssignmentSubmission } from '@components/Contexts/Assignments/AssignmentSubmissionContext' +import AssignmentSubmissionProvider, { useAssignmentSubmission } from '@components/Contexts/Assignments/AssignmentSubmissionContext' import toast from 'react-hot-toast' import { mutate } from 'swr' import ConfirmationModal from '@components/StyledElements/ConfirmationModal/ConfirmationModal' @@ -303,11 +303,11 @@ function AssignmentTools(props: { props.assignment?.assignment_uuid, session.data?.tokens?.access_token ); - + if (res.success) { const { grade, max_grade, grading_type } = res.data; let displayGrade; - + switch (grading_type) { case 'ALPHABET': displayGrade = convertNumericToAlphabet(grade, max_grade); @@ -322,15 +322,15 @@ function AssignmentTools(props: { default: displayGrade = 'Unknown grading type'; } - + // Use displayGrade here, e.g., update state or display it setFinalGrade(displayGrade); } else { } }; - + // Helper function to convert numeric grade to alphabet grade - function convertNumericToAlphabet(grade : any, maxGrade : any) { + function convertNumericToAlphabet(grade: any, maxGrade: any) { const percentage = (grade / maxGrade) * 100; if (percentage >= 90) return 'A'; if (percentage >= 80) return 'B'; @@ -340,7 +340,9 @@ function AssignmentTools(props: { } useEffect(() => { - getGradingBasedOnMethod(); + if ( submission && submission.length > 0 && submission[0].submission_status === 'GRADED') { + getGradingBasedOnMethod(); + } } , [submission, props.assignment]) diff --git a/apps/web/app/orgs/[orgslug]/dash/assignments/page.tsx b/apps/web/app/orgs/[orgslug]/dash/assignments/page.tsx index 67500c6b..020fb5ce 100644 --- a/apps/web/app/orgs/[orgslug]/dash/assignments/page.tsx +++ b/apps/web/app/orgs/[orgslug]/dash/assignments/page.tsx @@ -59,10 +59,9 @@ function AssignmentsHome() {
-

Course

+

Course

{courses[index].name}

-
Assignment

{assignment.title}
-
{assignment.description}
+
{assignment.description}
@@ -121,7 +120,7 @@ function AssignmentsHome() {

No assignments available for this course, create course assignments from the course editor

- )} + )} ))} diff --git a/apps/web/components/Objects/Activities/Assignment/AssignmentBoxUI.tsx b/apps/web/components/Objects/Activities/Assignment/AssignmentBoxUI.tsx index efd842ba..73070c8a 100644 --- a/apps/web/components/Objects/Activities/Assignment/AssignmentBoxUI.tsx +++ b/apps/web/components/Objects/Activities/Assignment/AssignmentBoxUI.tsx @@ -20,9 +20,10 @@ function AssignmentBoxUI({ type, view, currentPoints, maxPoints, saveFC, submitF const [customGrade, setCustomGrade] = React.useState(0) const submission = useAssignmentSubmission() as any useEffect(() => { + console.log(submission) } , [submission]) - + return (
@@ -88,10 +89,11 @@ function AssignmentBoxUI({ type, view, currentPoints, maxPoints, saveFC, submitF {/* Grading button */} {view === 'grading' &&
gradeFC && gradeFC()} className='flex px-0.5 py-0.5 cursor-pointer rounded-md space-x-2 items-center bg-gradient-to-bl hover:outline-offset-4 active:outline-offset-1 linear transition-all outline-offset-2 outline-dashed outline-orange-500/60'>

Current points : {currentPoints}

-
+
gradeFC && gradeFC()} + className='bg-gradient-to-bl text-orange-700 bg-orange-300/20 hover:bg-orange-300/10 items-center flex rounded-md px-2 py-1 space-x-2'>

Grade

@@ -101,13 +103,14 @@ function AssignmentBoxUI({ type, view, currentPoints, maxPoints, saveFC, submitF {/* CustomGrading button */} {view === 'custom-grading' && maxPoints &&
gradeCustomFC && gradeCustomFC(customGrade)} className='flex px-0.5 py-0.5 cursor-pointer rounded-md space-x-2 items-center bg-gradient-to-bl hover:outline-offset-4 active:outline-offset-1 linear transition-all outline-offset-2 outline-dashed outline-orange-500/60'>

Current points : {currentPoints}

setCustomGrade(parseInt(e.target.value))} placeholder={maxPoints.toString()} className='w-[100px] light-shadow text-sm py-0.5 outline outline-gray-200 rounded-lg px-2' type="number" /> -
+
gradeCustomFC && gradeCustomFC(customGrade)} + className='bg-gradient-to-bl text-orange-700 bg-orange-300/20 hover:bg-orange-300/10 items-center flex rounded-md px-2 py-1 space-x-2'>

Grade

diff --git a/apps/web/services/courses/assignments.ts b/apps/web/services/courses/assignments.ts index 0d301036..432adf50 100644 --- a/apps/web/services/courses/assignments.ts +++ b/apps/web/services/courses/assignments.ts @@ -7,7 +7,7 @@ import { export async function createAssignment(body: any, access_token: string) { const result: any = await fetch( - `${getAPIUrl()}assignments`, + `${getAPIUrl()}assignments/`, RequestBodyWithAuthHeader('POST', body, null, access_token) ) const res = await getResponseMetadata(result)