Skip to content

Commit 012842a

Browse files
authored
Merge pull request #55 from CS3219-AY2425S1/revert-54-main
Revert "UI changes"
2 parents 1ed9227 + 4485ee6 commit 012842a

File tree

4 files changed

+64
-71
lines changed

4 files changed

+64
-71
lines changed

Frontend/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"@testing-library/jest-dom": "^5.17.0",
88
"@testing-library/react": "^13.4.0",
99
"@testing-library/user-event": "^13.5.0",
10-
"ag-grid-react": "^32.3.2",
1110
"axios": "^1.7.7",
1211
"bootstrap": "^5.3.3",
1312
"jwt-decode": "^4.0.0",

Frontend/src/components/question/Question.jsx

Lines changed: 53 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import EditQn from "./EditQn";
77
import questionService from "../../services/questions"
88
import userService from "../../services/users";
99
import categoryService from "../../services/categories";
10-
import { AgGridReact } from 'ag-grid-react'; // React Data Grid Component
11-
import "ag-grid-community/styles/ag-grid.css"; // Mandatory CSS required by the Data Grid
12-
import "ag-grid-community/styles/ag-theme-quartz.css"; // Optional Theme applied to the Data Grid
10+
1311

1412
function Question() {
1513
const [questions, setQuestions] = useState([]);
@@ -52,6 +50,10 @@ function Question() {
5250
console.log('Error:', e);
5351
});
5452
}, []);
53+
54+
const easyQuestions = questions.filter(q => q.complexity === "Easy")
55+
const mediumQuestions = questions.filter(q => q.complexity === "Medium")
56+
const hardQuestions = questions.filter(q => q.complexity === "Hard")
5557

5658
const addQuestion = (newQuestion) => {
5759
setQuestions((prevQuestions) => [...prevQuestions, newQuestion]);
@@ -126,67 +128,52 @@ function Question() {
126128
};
127129

128130

129-
const renderQuestionsTable = () => {
130-
const CustomButtonComponent = (props) => {
131-
const question = props.data
132-
return <ButtonGroup className="mb-2">
133-
<button
134-
className='btn btn-success'
135-
onClick={() => handleShowEditModal(question)}
136-
>
137-
Edit
138-
</button>
139-
<button className='btn btn-danger' size="sm"
140-
onClick={() => handleShowDelete(question._id)}>
141-
Delete
142-
</button>
143-
</ButtonGroup>
144-
};
145-
146-
const colDefs = [
147-
{ field: "id", flex: 1, wrapText: true, sort: "asc" },
148-
{ field: "title", flex: 2 },
149-
{ field: "description", flex: 5, wrapText: true, autoHeight: true},
150-
{ field: "complexity", flex: 1.5,
151-
comparator: (valueA, valueB, nodeA, nodeB, isDescending) => {
152-
if (valueA == valueB) return 0;
153-
if (valueA == "Easy" || valueB == "Hard") return -1;
154-
if (valueA == "Hard" || valueB == "Easy") return 1;
155-
}
156-
}
157-
];
158-
159-
if (isAdmin) {
160-
colDefs = [
161-
{ field: "id", flex: 1, wrapText: true, sort: "asc" },
162-
{ field: "title", flex: 2 },
163-
{ field: "description", flex: 5, wrapText: true, autoHeight: true},
164-
{ field: "complexity", flex: 1.5,
165-
comparator: (valueA, valueB, nodeA, nodeB, isDescending) => {
166-
if (valueA == valueB) return 0;
167-
if (valueA == "Easy" || valueB == "Hard") return -1;
168-
if (valueA == "Hard" || valueB == "Easy") return 1;
169-
}
170-
},
171-
{ field: "action", width: 200, resizable: false, sortable: false, cellRenderer: CustomButtonComponent }
172-
];
173-
}
131+
const renderQuestionsTable = (questions) => {
132+
const sortedQuestions = [...questions].sort((a, b) => a.id - b.id)
174133

175134
return (
176-
<div
177-
className="container-fluid ag-theme-quartz" // applying the Data Grid theme
178-
style={{ height: 500 }} // the Data Grid will fill the size of the parent container
179-
>
180-
<AgGridReact
181-
rowData={questions}
182-
columnDefs={colDefs}
183-
/>
184-
</div>
135+
<Table>
136+
<thead>
137+
<tr>
138+
<th>ID</th>
139+
<th>Title</th>
140+
<th>Description</th>
141+
<th>Category</th>
142+
{isAdmin && (<th>Action</th>)}
143+
</tr>
144+
</thead>
145+
<tbody>
146+
{sortedQuestions.map((question) => (
147+
<tr key={question.id}>
148+
<td>{question.id}</td>
149+
<td>{question.title}</td>
150+
<td>{question.description}</td>
151+
<td>{question.category ? question.category.join(", ") : ''}</td>
152+
{isAdmin && (
153+
<td>
154+
<ButtonGroup className="mb-2">
155+
<button
156+
className='btn btn-success'
157+
onClick={() => handleShowEditModal(question)}
158+
>
159+
Edit
160+
</button>
161+
<button className='btn btn-danger' size="sm"
162+
onClick={() => handleShowDelete(question._id)}>
163+
Delete
164+
</button>
165+
</ButtonGroup>
166+
</td>
167+
)}
168+
</tr>
169+
))}
170+
</tbody>
171+
</Table>
185172
);
186173
};
187174

188175
return (
189-
<div className="container-fluid">
176+
<div className="d-flex">
190177
<div className='bg-white rounded p-3 m-3'>
191178
<div className="d-flex justify-content-between">
192179
<h1>Questions</h1>
@@ -207,7 +194,14 @@ function Question() {
207194
<hr/>
208195

209196
<div className="container">
210-
{renderQuestionsTable()}
197+
<h2 className="p-2">Easy Questions</h2>
198+
{renderQuestionsTable(easyQuestions)}
199+
200+
<h2 className="p-2">Medium Questions</h2>
201+
{renderQuestionsTable(mediumQuestions)}
202+
203+
<h2 className="p-2">Hard Questions</h2>
204+
{renderQuestionsTable(hardQuestions)}
211205

212206
{/* Edit Modal */}
213207
<Modal show={showEditModal} onHide={handleCloseEditModal} backdrop="static">

Frontend/src/components/user/EditProfilePage.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ function EditProfilePage() {
2727
return(
2828
<div>
2929
<NavigationBar/>
30-
{/* <div className="row"> */}
31-
{/* <div className="Navbar col-2">
30+
<div className="row">
31+
<div className="Navbar col-2">
3232
<ProfileSidebar userID={userID}/>
33-
</div> */}
34-
{/* <div className="col-10"> */}
33+
</div>
34+
<div className="col-10">
3535
<EditProfile/>
36-
{/* </div> */}
37-
{/* </div> */}
36+
</div>
37+
</div>
3838
</div>
3939
);
4040
}

Frontend/src/components/user/HistoryPage.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ function HistoryPage() {
3333
return(
3434
<div>
3535
<NavigationBar/>
36-
{/* <div className="row"> */}
37-
{/* <div className="Navbar col-2">
36+
<div className="row">
37+
<div className="Navbar col-2">
3838
<ProfileSidebar userID={userID}/>
39-
</div> */}
40-
<div className="container-fluid p-5">
39+
</div>
40+
<div className="col-10">
4141
<HistoryTable userID={userID}/>
4242
</div>
43-
{/* </div> */}
43+
</div>
4444
</div>
4545
);
4646
}

0 commit comments

Comments
 (0)