From 6d006532a617e5045f42063e8d8e96dbf532fa3b Mon Sep 17 00:00:00 2001 From: Keith Stevens Date: Mon, 19 Dec 2022 19:50:31 +0900 Subject: [PATCH] Updating the grading view to use a few Chakra components and a custom radio group for the rating scale --- website/src/components/RatingRadioGroup.tsx | 53 ++++++ website/src/pages/grading/grade-output.tsx | 179 +++++++++----------- 2 files changed, 129 insertions(+), 103 deletions(-) create mode 100644 website/src/components/RatingRadioGroup.tsx diff --git a/website/src/components/RatingRadioGroup.tsx b/website/src/components/RatingRadioGroup.tsx new file mode 100644 index 00000000..33043883 --- /dev/null +++ b/website/src/components/RatingRadioGroup.tsx @@ -0,0 +1,53 @@ +import { chakra, Box, HStack, useRadio, useRadioGroup } from "@chakra-ui/react"; + +const RatingRadioButton = (props) => { + const { option, ...radioProps } = props; + const { getInputProps, getCheckboxProps } = useRadio(radioProps); + + const input = getInputProps(); + const checkbox = getCheckboxProps(); + + return ( + + + + {option} + + + ); +}; + +const RatingRadioGroup = (props) => { + const { min, max, onChange, ...rest } = props; + const { value, getRadioProps, getRootProps } = useRadioGroup({ + defaultValue: min, + onChange: onChange, + }); + const options = Array.from(new Array(1 + max - min), (x, i) => i + min); + + return ( + + {options.map((option) => ( + + ))} + + ); +}; + +export default RatingRadioGroup; diff --git a/website/src/pages/grading/grade-output.tsx b/website/src/pages/grading/grade-output.tsx index 792212f0..5fabe7ba 100644 --- a/website/src/pages/grading/grade-output.tsx +++ b/website/src/pages/grading/grade-output.tsx @@ -1,9 +1,11 @@ +import { HStack, Textarea } from "@chakra-ui/react"; import { QuestionMarkCircleIcon } from "@heroicons/react/20/solid"; import { useSession, signIn, signOut } from "next-auth/react"; import { useEffect, useRef, useState } from "react"; -import useSWRImmutable from "swr/immutable"; import useSWRMutation from "swr/mutation"; +import useSWRImmutable from "swr/immutable"; +import RatingRadioGroup from "src/components/RatingRadioGroup"; import fetcher from "src/lib/fetcher"; import poster from "src/lib/poster"; @@ -11,6 +13,7 @@ const GradeOutput = () => { // Use an array of tasks that record the sequence of steps until a task is // deemed complete. const [tasks, setTasks] = useState([]); + const [rating, setRating] = useState(0); // A quick reference to the input element. This should be factored into the // component doing the actual task rendering. @@ -42,7 +45,7 @@ const GradeOutput = () => { trigger({ id: t.id, content: { - rating: 2, + rating: rating, }, }); }; @@ -51,128 +54,98 @@ const GradeOutput = () => { * TODO: Make this a nicer loading screen. */ if (tasks.length == 0) { - return ( - <> -
- - ); + return
; } return ( - <> -
- {/* Instrunction and Output panels */} -
-
- {/* Instruction panel */} -
-
-
Instruction
-
- {tasks[0].task.full_text} -
+
+ {/* Instrunction and Output panels */} +
+
+ {/* Instruction panel */} +
+
+
Instruction
+
+ {tasks[0].task.full_text}
+
- {/* Output panel */} -
-
-
Output
-
- {tasks[0].task.summary} -
-
- {/* Form wrap*/} -
-

Rating

-

(1 = worst, 7 = best)

+ {/* Output panel */} +
+
+
Output
+
{tasks[0].task.summary}
+
+ {/* Form wrap*/} +
+

Rating

+

+ ({tasks[0].task.scale.min} = worst, {tasks[0].task.scale.max} = best) +

- {/* Rating buttons */} -
- - - - - - - -
-
- - {/* Annotation checkboxes */} -
-
    - {ANNOTATION_FLAGS.map((option, i) => { - return ; - })} -
-
+ {/* Rating buttons */}
-