import React, {useEffect, useState} from "react"; import AddRubric from "./AddRubric"; import Modal from "./Modal"; import "../styles/rubric.css"; const Rubric = ({rubric_id, getRubrics}) => { // IMPORTANT: rubricData contains rubric name, levels, and criterions const [duplicatedRubricData, setDuplicatedRubricData] = useState({}); const [criterions, setCriterions] = useState({}) // Contains the criterions const [levels, setLevels] = useState({}) // Contains the levels const [rubricName, setRubricName] = useState("") // Contains the rubric name const [showDuplicateRubricModal, setShowDuplicateRubricModal] = useState(false); // Show Duplicate Rubric Modal /** * Toggles the visibility of the duplicate rubric modal. */ const handleDuplicateRubricModal = () => { setShowDuplicateRubricModal(prevState => !prevState); } /** * Fetches the rubric info from the API. * @param filename */ const fetchRubricInfo = (filename) => { fetch( process.env.REACT_APP_API_URL + filename, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded", }, body: new URLSearchParams({ "rubric-id": rubric_id, }), } ) .then((res) => res.json()) .then((result) => { if (filename === "getInstructorRubrics.php") { // Initial Rubric Info setRubricName(result.data.name) setLevels(Object.values(result.data.levels)) setCriterions(result.data.topics) } else if (filename === "rubricDuplicate.php") { // Duplicate Rubric Info setDuplicatedRubricData(result.data) } }) .catch((err) => { console.log(err); }); }; // Fetch rubric info when the component mounts useEffect(() => { fetchRubricInfo("getInstructorRubrics.php") // Displaying Rubric for Library Page fetchRubricInfo("rubricDuplicate.php") // Duplicating Rubric }, []); /** * The Rubric component renders a rubric with the specified name, levels, and criterions. */ return ( <>

{rubricName}

{Object.entries(levels).length > 0 ? (
{Object.values(levels).map((level) => ( ))} {Object.values(criterions).map((criterion) => {Object.values(criterion.responses).map((response) => )} )}
Criterion{level.name + " (" + level.score + " pts)"}
{criterion.question}{response}
) :
No Rubric Data Found
}
) } export default Rubric;