From e0e1046f5916ac1e2bd81fe435d32eff917178d7 Mon Sep 17 00:00:00 2001 From: Tanisha Dixit Date: Sun, 8 Dec 2024 02:51:09 +0530 Subject: [PATCH] chore: adds comments to frontend --- react_frontend/src/api/GetPastTest.tsx | 3 +++ react_frontend/src/api/GetTest.tsx | 14 +++++++------- react_frontend/src/api/GetUpcomingTest.tsx | 1 + react_frontend/src/api/createIQ.tsx | 1 + react_frontend/src/api/createMCQ.tsx | 1 + react_frontend/src/api/createQRef.tsx | 2 +- react_frontend/src/api/createSCQ.tsx | 1 + react_frontend/src/api/getMCQ.tsx | 12 +++++------- react_frontend/src/api/getQ.tsx | 3 +++ react_frontend/src/context/AuthContext.js | 3 +++ react_frontend/src/pages/Loginpage.tsx | 2 +- react_frontend/src/pages/signuppage.tsx | 2 +- 12 files changed, 28 insertions(+), 17 deletions(-) diff --git a/react_frontend/src/api/GetPastTest.tsx b/react_frontend/src/api/GetPastTest.tsx index fef4a17..0bdebb1 100644 --- a/react_frontend/src/api/GetPastTest.tsx +++ b/react_frontend/src/api/GetPastTest.tsx @@ -20,6 +20,7 @@ const GetUpcomingTests = () => { const fetchUpcomingTests = async () => { + //fetching past tests from backend try { const response = await axios.get( "http://127.0.0.1:8000/test/api/tests/", @@ -44,6 +45,8 @@ const GetUpcomingTests = () => { // fetchUpcomingTests(); const obj = useContext(AuthContext); const testID = useContext(TestContext); + + //fetching marks const fetchmarks = async () => { const userdata = { diff --git a/react_frontend/src/api/GetTest.tsx b/react_frontend/src/api/GetTest.tsx index cbc8717..c14ce85 100644 --- a/react_frontend/src/api/GetTest.tsx +++ b/react_frontend/src/api/GetTest.tsx @@ -33,6 +33,8 @@ const GetTest: React.FC = () => { // const history = useHistory(); const obj=useContext(AuthContext); const { selectedTestPk, setSelectedTestPk } = useContext(TestContext) || { selectedTestPk: null, setSelectedTestPk: () => {} }; + + //fetching the tests from backend useEffect(() => { axios .get("http://127.0.0.1:8000/test/api/tests/", { @@ -58,19 +60,17 @@ const GetTest: React.FC = () => { const handleFinalSubmit = async () => { console.log() - // Assuming you have a mechanism to collect user answers (selectedAnswers) if (!selectedTest) { alert("Please select a test to submit."); return; } console.log(obj.user.user_id,selectedTest.pk); const testData = { - user: obj.user.user_id, // Replace with actual user ID + user: obj.user.user_id, test: selectedTest.pk, - // Add user answers here (replace with your logic) - // answers: selectedAnswers, // Replace with your answer collection logic }; + //handling test submission try { const response = await axios.post( "http://127.0.0.1:8000/test/api/calc_marks/", // Replace with your endpoint @@ -82,8 +82,8 @@ const GetTest: React.FC = () => { } ); - const marks = response.data.marks; // Assuming 'marks' is returned by the API - alert("Test submitted successfully! Your marks are: " + marks); // Display marks + const marks = response.data.marks; + alert("Test submitted successfully! Your marks are: " + marks); navigate("/studentUpcomingTest"); } catch (error) { console.error("Submission error:", error); @@ -107,7 +107,7 @@ const GetTest: React.FC = () => { // testId = {test.pk} /> } - diff --git a/react_frontend/src/api/GetUpcomingTest.tsx b/react_frontend/src/api/GetUpcomingTest.tsx index ea30e23..f406dac 100644 --- a/react_frontend/src/api/GetUpcomingTest.tsx +++ b/react_frontend/src/api/GetUpcomingTest.tsx @@ -17,6 +17,7 @@ const GetUpcomingTests = () => { useEffect(() => { const fetchUpcomingTests = async () => { + //fetching tests from backend try { const response = await axios.get( "http://127.0.0.1:8000/test/api/tests/", diff --git a/react_frontend/src/api/createIQ.tsx b/react_frontend/src/api/createIQ.tsx index a09bf37..32df776 100644 --- a/react_frontend/src/api/createIQ.tsx +++ b/react_frontend/src/api/createIQ.tsx @@ -8,6 +8,7 @@ interface IQ { const CreateIQ =async (IQ : IQ) : Promise => { const { question, correctOption } = IQ; + //Creating a integer type question object try { const response = await axios .post( diff --git a/react_frontend/src/api/createMCQ.tsx b/react_frontend/src/api/createMCQ.tsx index 984f34d..ab5660d 100644 --- a/react_frontend/src/api/createMCQ.tsx +++ b/react_frontend/src/api/createMCQ.tsx @@ -15,6 +15,7 @@ const CreateMCQ= async (MCQ:MCQ):Promise=> { const { question, option1, option2, option3, option4, correctOptions } = MCQ; try { const response = await axios + //Creating a multiple correct question object .post( "http://127.0.0.1:8000/questions/multiple/", { diff --git a/react_frontend/src/api/createQRef.tsx b/react_frontend/src/api/createQRef.tsx index 8f13525..301da86 100644 --- a/react_frontend/src/api/createQRef.tsx +++ b/react_frontend/src/api/createQRef.tsx @@ -13,7 +13,7 @@ interface Response { const CreateQRef = async (props: props): Promise => { const { arrqType } = props; - + //fetching question reference table objects try { const response = await axios.post( "http://127.0.0.1:8000/questions/qref/", diff --git a/react_frontend/src/api/createSCQ.tsx b/react_frontend/src/api/createSCQ.tsx index 9f95d5c..3e3097e 100644 --- a/react_frontend/src/api/createSCQ.tsx +++ b/react_frontend/src/api/createSCQ.tsx @@ -12,6 +12,7 @@ interface SCQ { const CreateSCQ= async (SCQ:SCQ): Promise =>{ const {question,option1,option2,option3,option4,correctOption}=SCQ; + //Creating a single correct question object try { const response = await axios .post( diff --git a/react_frontend/src/api/getMCQ.tsx b/react_frontend/src/api/getMCQ.tsx index 01c2045..7e7f74e 100644 --- a/react_frontend/src/api/getMCQ.tsx +++ b/react_frontend/src/api/getMCQ.tsx @@ -58,16 +58,14 @@ const GetMCQ: React.FC = ({ url, submitUrl }) => { const handleSubmit = () => { if (question && selectedOptions.length > 0) { - // Create a tuple where the first element is the question pk - // and the second element is the array of selected options. const solTuple = [selectedOptions]; const data = { - user: new URLSearchParams({user_id: obj.user.user_id}).toString(), // Placeholder - adjust as necessary - test: testID, // Placeholder - adjust as necessary - qid: question.pk, // You might not need this separately since it's included in the tuple - qt: "MCQ", // Question type - sol: solTuple, // The tuple as the solution + user: new URLSearchParams({user_id: obj.user.user_id}).toString(), + test: testID, + qid: question.pk, + qt: "MCQ", + sol: solTuple, }; axios.post(submitUrl, data, { diff --git a/react_frontend/src/api/getQ.tsx b/react_frontend/src/api/getQ.tsx index 64c4810..aa4824b 100644 --- a/react_frontend/src/api/getQ.tsx +++ b/react_frontend/src/api/getQ.tsx @@ -90,6 +90,7 @@ const GetQ: React.FC = (props) => { const [mcqs, setmcqs]: [MCQ[], (mcqs: MCQ[]) => void] = useState(MCQs); const [iqs, setiqs]: [IQ[], (iqs: IQ[]) => void] = useState(IQs); useEffect(() => { + //fetching single correct questions axios .get("http://127.0.0.1:8000/questions/single/", { headers: { @@ -101,6 +102,7 @@ const GetQ: React.FC = (props) => { }); }, []); useEffect(() => { + //fetching multiple correct questions axios .get("http://127.0.0.1:8000/questions/multiple/", { headers: { @@ -112,6 +114,7 @@ const GetQ: React.FC = (props) => { }); }, []); useEffect(() => { + //fetching integer type questions axios .get("http://127.0.0.1:8000/questions/integer/", { headers: { diff --git a/react_frontend/src/context/AuthContext.js b/react_frontend/src/context/AuthContext.js index 80d7f4e..3fec6b0 100644 --- a/react_frontend/src/context/AuthContext.js +++ b/react_frontend/src/context/AuthContext.js @@ -26,6 +26,7 @@ export const AuthProvider = ({ children }) => { const navigate = useNavigate(); // Use useNavigate instead of useHistory + //sending login credentials to backend const loginUser = async (email, password) => { const response = await fetch("http://127.0.0.1:8000/token/", { method: "POST", @@ -72,6 +73,7 @@ export const AuthProvider = ({ children }) => { } }; + //sending registration credentials to backend const registerUser = async (email, username, password, password2) => { const response = await fetch("http://127.0.0.1:8000/register/", { method: "POST", @@ -108,6 +110,7 @@ export const AuthProvider = ({ children }) => { } } + //implementing logout feature const logoutUser = () => { setAuthTokens(null) setUser(null) diff --git a/react_frontend/src/pages/Loginpage.tsx b/react_frontend/src/pages/Loginpage.tsx index ac1e6b8..3c65ea4 100644 --- a/react_frontend/src/pages/Loginpage.tsx +++ b/react_frontend/src/pages/Loginpage.tsx @@ -11,7 +11,7 @@ const LoginPage: React.FC = () => { const password = e.currentTarget.password.value; if (email.length > 0) { - loginUser(email, password); + loginUser(email, password); //implement login feature } console.log(email); diff --git a/react_frontend/src/pages/signuppage.tsx b/react_frontend/src/pages/signuppage.tsx index b007c1f..23cde41 100644 --- a/react_frontend/src/pages/signuppage.tsx +++ b/react_frontend/src/pages/signuppage.tsx @@ -12,7 +12,7 @@ const SignUpPage: React.FC = () => { const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); - registerUser(email, username, password, password2); + registerUser(email, username, password, password2); //implement registration feature }; return (