generated from CS3219-AY2324S1/course-assessment-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'test-updated-merge' of https://github.com/CS3219-AY2324…
…S1/ay2324s1-course-assessment-g16 into test-updated-merge
- Loading branch information
Showing
8 changed files
with
254 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,28 @@ | ||
import React from "react"; | ||
import React, {useEffect, useState} from "react"; | ||
import "./Attempt.css"; | ||
import Utility from "../../Utility/Utility"; | ||
|
||
export const Attempt = ({ i, attempt, setSelectedAttempt, setIsList }) => { | ||
let tagClass = Utility.setDifficultyTag("user-q-tag", attempt.complexity); | ||
|
||
console.log(attempt); | ||
return ( | ||
<div | ||
className="attempt-container" | ||
onClick={() => { | ||
setSelectedAttempt(attempt); | ||
setIsList(false); | ||
}} | ||
> | ||
<div className="attempt-name"> | ||
<div className="attempt-id"> #{i + 1} </div> | ||
<div className="attempt-title">{attempt.title}</div> | ||
</div> | ||
<div className="attempt-tags"> | ||
{/* to be replaced with date passed as component parameter */} | ||
<div className="user-q-tag attempt-date">31/10/2023</div> | ||
<div className={tagClass}>{attempt.complexity}</div> | ||
<div className="user-q-tag">{attempt.category}</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
export const Attempt = ({i, attempt, setSelectedAttempt, setIsList}) => { | ||
let tagClass = Utility.setDifficultyTag("user-q-tag", question.complexity); | ||
|
||
return ( | ||
<div | ||
className="attempt-container" | ||
onClick={() => { | ||
setSelectedAttempt(attempt); | ||
setIsList(false); | ||
}} | ||
> | ||
<div className="attempt-name"> | ||
<div className="attempt-id"> #{i + 1} </div> | ||
<div className="attempt-title">{attempt.title}</div> | ||
</div> | ||
<div className="attempt-tags"> | ||
<div className="user-q-tag attempt-date">{question.attempt_time}</div> | ||
<div className={tagClass}>{question.complexity}</div> | ||
<div className="user-q-tag">{question.category}</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,41 @@ | ||
import React, {useState, useEffect} from 'react' | ||
import {Attempt} from "./Attempt" | ||
import {AttemptView} from "./AttemptView" | ||
import './AttemptHistory.css' | ||
import { getUserAttempts } from '../../History/HistoryServiceAPI' | ||
import {getUserId} from "../../User/UserState" | ||
import React, {useState, useEffect} from "react"; | ||
import {Attempt} from "./Attempt"; | ||
import {AttemptView} from "./AttemptView"; | ||
import "./AttemptHistory.css"; | ||
import {getUserAttempts} from "../../History/HistoryServiceAPI"; | ||
import {getUserId} from "../../User/UserState"; | ||
|
||
export const AttemptHistory = ({isList, setIsList}) => { | ||
const [attempts, setAttempts] = useState([]); | ||
const [selectedAttempt, setSelectedAttempt] = useState(null); | ||
const [attempts, setAttempts] = useState([]); | ||
const [selectedAttempt, setSelectedAttempt] = useState(null); | ||
|
||
// to be replaced with actual attempt fetch | ||
const fetchAttempts = async () => { | ||
setAttempts(getUserAttempts(getUserId())); | ||
console.log(attempts); | ||
}; | ||
|
||
useEffect(() => { | ||
fetchAttempts(); | ||
}, []); | ||
const fetchAttempts = async () => { | ||
const results = await getUserAttempts(getUserId()); | ||
setAttempts(results); | ||
}; | ||
|
||
return ( | ||
<div className="attempt-history-container"> | ||
{isList? | ||
<div className="attempt-list-container"> | ||
{/* to be replaced by mapping over actual stored attempts */} | ||
{/* {attempts.map((a, index) => ( | ||
<Attempt key = {index} attempt = {a} i = {index} | ||
setSelectedAttempt = {setSelectedAttempt} setIsList = {setIsList}/>))} */} | ||
</div>: | ||
<AttemptView attempt = {selectedAttempt} setIsList = {setIsList}/> | ||
} | ||
</div> | ||
) | ||
} | ||
useEffect(() => { | ||
fetchAttempts(); | ||
}, []); | ||
|
||
return ( | ||
<div className="attempt-history-container"> | ||
{isList ? ( | ||
<div className="attempt-list-container"> | ||
{/* to be replaced by mapping over actual stored attempts */} | ||
{attempts.map((a, index) => ( | ||
<Attempt | ||
key={index} | ||
attempt={a} | ||
i={index} | ||
setSelectedAttempt={setSelectedAttempt} | ||
setIsList={setIsList} | ||
/> | ||
))} | ||
</div> | ||
) : ( | ||
<AttemptView attempt={selectedAttempt} setIsList={setIsList} /> | ||
)} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import './Output.css'; | ||
import error_icon from '../Assets/cross.png'; | ||
|
||
export const NotSuccessOutput = ({ isOpen, isClose }) => { | ||
if (isOpen) { | ||
return ( | ||
<div className="output-overlay"> | ||
<div className="output-popup"> | ||
<h3>Not Match Found!</h3> | ||
<img src={error_icon} className="image" alt="Error icon" /> | ||
<p>Try Again!</p> | ||
<div> | ||
<button onClick={isClose} className="complete-matching">Okay</button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
return null; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
import { | ||
getUserAttemptsFromHistoryDatabase, | ||
addUserAttemptToHistoryDatabase, | ||
getUserAttemptsFromHistoryDatabase, | ||
addUserAttemptToHistoryDatabase, | ||
} from "./HistoryServiceController"; | ||
|
||
async function getUserAttempts(userId) { | ||
const result = await getUserAttemptsFromHistoryDatabase(userId); | ||
const result = await getUserAttemptsFromHistoryDatabase(userId); | ||
console.log(result); | ||
if (result !== null && result.status === 200) { | ||
return result.data.result; | ||
} | ||
|
||
if (result !== null && result.status === 200) { | ||
return result.data.result; | ||
} | ||
|
||
return null; | ||
return null; | ||
} | ||
|
||
async function addUserAttempt(userId1, userId2, sessionId, questionId) { | ||
const result = await addUserAttemptToHistoryDatabase( | ||
userId1, | ||
userId2, | ||
sessionId, | ||
questionId | ||
); | ||
const result = await addUserAttemptToHistoryDatabase( | ||
userId1, | ||
userId2, | ||
sessionId, | ||
questionId | ||
); | ||
|
||
if (result !== null && result.status === 201) { | ||
return true; | ||
} | ||
if (result !== null && result.status === 201) { | ||
return true; | ||
} | ||
|
||
return false; | ||
return false; | ||
} | ||
|
||
export { addUserAttempt, getUserAttempts }; | ||
export {addUserAttempt, getUserAttempts}; |
Oops, something went wrong.