fer202
fer202
`FER202_Assignment.docx` file and the data in `database.json`. I will write JavaScript/React code
snippets that will work with Node.js and Visual Studio Code. You can copy the necessary parts for each
section.
---
In the `Home` component, create a basic layout. I'll assume a simple layout with a list of students and
their majors.
```jsx
useEffect(() => {
fetch('/path/to/database.json')
.then((data) => {
setStudents(studentData);
setMajors(uniqueMajors);
});
}, []);
return (
<div className="home">
<h1>Student List</h1>
<div>
<h2>Majors</h2>
<ul>
<li key={index}>{major}</li>
))}
</ul>
</div>
<div>
<ul>
{students.map((student) => (
<li key={student.id}>
{student.fullName} - {student.major}
</li>
))}
</ul>
</div>
</div>
);
};
The code above ensures no duplicate majors by using `Set` to filter unique majors.
---
This is handled by the `students.map()` method, which displays all students in the list.
---
---
Add an event handler to filter students by major when clicking on a major from the list.
```jsx
fetch('/path/to/database.json')
.then((data) => {
const filteredStudents = data.students.filter((student) => student.major === major);
setStudents(filteredStudents);
});
};
```
```jsx
<ul>
{major}
</li>
))}
</ul>
```
---
```jsx
function App() {
return (
<Router>
<Switch>
</Switch>
</Router>
);
```
Add a "Detail" button in the student list to navigate to the student’s details page:
```jsx
<li key={student.id}>
{student.fullName} - {student.major}
<Link to={`/student/${student.code}`}>Detail</Link>
</li>
```
---
#### **Câu 7, 8 - Design student detail page, show CPA (1 điểm)**
```jsx
useEffect(() => {
fetch('/path/to/database.json')
.then((data) => {
setStudent(studentDetail);
});
}, [code]);
return (
<div>
<h1>{student.fullName}</h1>
<h2>CPA: {student.cpa}</h2>
</div>
);
};
```
---
```jsx
useEffect(() => {
fetch('/path/to/database.json')
.then((data) => {
if (studentDetail) {
});
setSubjects(subjectNames);
});
}, [code]);
// In JSX:
<ul>
<li key={index}>{subject}</li>
))}
</ul>
```
---
```jsx
// Inside JSX:
<input
type="text"
placeholder="Search subjects"
/>
<ul>
{subjects
))}
</ul>
```
---
Add a form to input new subject details and add them to the database (this would typically require
backend work, but here is the frontend part):
```jsx
};
// JSX:
<input
type="text"
placeholder="New Subject"
value={newSubject}
/>
```
---
These code snippets should help you complete the assignment step-by-step. Let me know if you need
any further adjustments!