-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCourse Listing User Interface.txt
51 lines (42 loc) · 1.49 KB
/
Course Listing User Interface.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React, { useState, useEffect } from 'react';
import axios from 'axios';
function CourseList() {
const [courses, setCourses] = useState([]);
const [instances, setInstances] = useState([]);
useEffect(() => {
axios.get('http://localhost:8080/api/courses')
.then(response => {
setCourses(response.data);
})
.catch(error => {
console.error(error);
});
}, []);
const handleCreateCourse = (course) => {
axios.post('http://localhost:8080/api/courses', course)
.then(response => {
setCourses([...courses, response.data]);
})
.catch(error => {
console.error(error);
});
};
const handleCreateInstance = (instance) => {
axios.post('http://localhost:8080/api/instances', instance)
.then(response => {
setInstances([...instances, response.data]);
})
.catch(error => {
console.error(error);
});
};
const handleDeleteCourse = (id) => {
axios.delete(`http://localhost:8080/api/courses/${id}`)
.then(() => {
setCourses(courses.filter(course => course.id !== id));
})
.catch(error => {
console.error(error);
});
};
const handleDeleteInstance = (year, semester)