Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions src/Bookings.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
import React, { useState, useEffect } from "react";
import Search from "./Search.js";
import SearchResults from "./SearchResults.js";
import LoadingWait from "./LoadingWait.js";
import FakeBookings from "./data/fakeBookings.json";

const Bookings = () => {
let [dataAvailable, setDataAvailable] = useState(false);
const [loading, setLoading] = useState(true);
const [bookings, setBookings] = useState([]);
const [masterBookings, setMasterBookings] = useState([]);
const [error, setError] = useState(null);

useEffect(() => {
// fetch(`https://cyf-react.glitch.me`)
fetch(`https://cyf-react.glitch.me/delayed`)
.then((res) => res.json())
// fetch("https://cyf-react.glitch.me/error")
fetch("https://cyf-react.glitch.me/delayed")
.then((res) => {
if (!res.ok) {
throw new Error("Error occurred while fetching data");
}
return res.json();
})
.then((data) => {
setBookings(data);
setMasterBookings(data);
setDataAvailable(true);
setLoading(false);
})
.catch((error) => {
setError(error.message);
setLoading(false);
});
}, []);

let [bookings, setBookings] = useState([]);
let [masterBookings, setMasterBookings] = useState([]);

const search = (searchVal) => {
let filteredBookings = masterBookings.filter((abooking) => {
console.log(abooking);
Expand All @@ -36,7 +44,14 @@ const Bookings = () => {
<div className="App-content">
<div className="container">
<Search search={search} />
{dataAvailable ? <SearchResults results={bookings} /> : <LoadingWait />}

{error ? (
<p>{error}</p>
) : loading ? (
<p>Please wait while the data is loading...</p>
) : (
<SearchResults results={bookings} />
)}
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/TableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const TableRow = (props) => {
</td>
<td>
<button
className="btn-primary"
className="btn btn-primary"
onClick={() => {
handleProfileClick(props.aBooking.id);
}}
Expand Down