-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
69 lines (65 loc) · 1.89 KB
/
App.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React, { Component } from 'react';
import './App.css';
import AppointmentForm from './AppointmentForm';
import SearchForm from './SearchForm';
import AppointmentList from './AppointmentList';
import axios from 'axios';
class App extends Component {
constructor (props) {
super(props)
this.state = {
appointments: [],
filteredAppointments: []
};
this.loadAppointments = this.loadAppointments.bind(this);
this.updateAppointments = this.updateAppointments.bind(this);
this.filterAppoinments = this.filterAppoinments.bind(this);
}
loadAppointments() {
axios.get('api/appointments')
.then(res => {
console.log(res.data)
this.setState({
appointments: res.data,
filteredAppointments: res.data
});
})
}
componentDidMount () {
window.scrollTo(0, 0);
this.loadAppointments();
}
updateAppointments(newAppointment) {
var newAppointmentList = [...this.state.appointments];
newAppointmentList.push(newAppointment);
newAppointmentList.sort((a,b) => {
return new Date(a.appointmentDate) - new Date(b.appointmentDate);
});
this.setState({
appointments: newAppointmentList,
filteredAppointments: newAppointmentList
});
}
filterAppoinments(input) {
let filtered = this.state.appointments.filter(appointment => {
return JSON.stringify(appointment).includes(input);
});
this.setState({
filteredAppointments: filtered
})
}
render() {
return (
<div className="App">
<AppointmentForm
addAppointment = {this.updateAppointments} />
<SearchForm
filterAppoinments = {this.filterAppoinments}
filteredAppointments = {this.state.filteredAppointments} />
<AppointmentList
appointments = {this.state.filteredAppointments} />
</div>
);
}
}
export default App;