This repository was archived by the owner on Feb 9, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 753
Expand file tree
/
Copy pathBookings.js
More file actions
47 lines (40 loc) · 1.19 KB
/
Bookings.js
File metadata and controls
47 lines (40 loc) · 1.19 KB
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
import React, { useCallback, useEffect, useState } from "react";
import Axios from "axios";
import Search from "./Search.js";
import SearchResults from "./SearchResults.js";
// import FakeBookings from "./data/fakeBookings.json";
const Bookings = () => {
const [bookings, setBookings] = useState([]);
const [searchVal, setSearchVal] = useState("");
const [loading, setLoading] = useState(false);
const search = (searchVal) => {
console.info("TO DO!", searchVal);
setSearchVal(searchVal);
};
useEffect(() => {
const fetchData = async () => {
try {
const res = await Axios.get("https://cyf-react.glitch.me/delayed");
setBookings(res.data);
} catch (error) {
console.log(error);
}
setLoading(true);
}
fetchData();
}, []);
const searchOutCome = bookings.filter(
(el) => el.firstName.includes(searchVal) || el.surname.includes(searchVal)
);
return (
<div className="App-content">
<div className="container">
<Search search={search} />
{!loading ? (<h1>Loading...</h1>) : (
<SearchResults results={searchOutCome} /> )
}
</div>
</div>
);
};
export default Bookings;