-
-
Notifications
You must be signed in to change notification settings - Fork 767
London10-Olha_Danylevska-React_Module-CYF_hotel_react #601
base: master
Are you sure you want to change the base?
Changes from 5 commits
3581900
78fb4d9
057ab1c
7c2b4bf
ef039c6
ce92699
ed998ab
f41cb5b
957ab81
a70d7ec
2b19045
84178b4
eb88df7
137ec5d
55aacac
7172439
cfb1ce6
ec85e58
1bb34eb
913993e
f7e3e60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,71 @@ | ||
import React from "react"; | ||
|
||
import Search from "./Search.js"; | ||
import Restaurant from "./Restaurant.js" | ||
import Bookings from "./Bookings"; | ||
import "./App.css"; | ||
|
||
const Heading = () => { | ||
return ( | ||
<div> | ||
<header className="App-header">CYF Hotel</header> | ||
</div> | ||
) | ||
} | ||
|
||
const Footer = (props) => { | ||
let data = props.address | ||
return ( | ||
<div className="footer"> | ||
<ul> | ||
{ | ||
data.map(line => { | ||
return <li>{line}</li> | ||
}) | ||
} | ||
</ul> | ||
</div> | ||
) | ||
|
||
|
||
} | ||
|
||
const TouristInfoCards = (props) => { | ||
return ( | ||
<div className="card"> | ||
<img src={props.src} className="card-img-top" /> | ||
<div className="card-body"> | ||
<h2>{props.name}</h2> | ||
<p>{props.description}</p> | ||
<a href={props.link} className="btn btn-primary">Go somewhere</a> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
const App = () => { | ||
return ( | ||
<div className="App"> | ||
<header className="App-header">CYF Hotel</header> | ||
<Heading /> | ||
<div className="AllCards"> | ||
|
||
<TouristInfoCards name="Manchester" src="https://cdn.britannica.com/42/116342-050-5AC41785/Manchester-Eng.jpg" | ||
link="https://www.visitmanchester.com/" description="Manchester is the only UK city to feature in Lonely Planet's Best in Travel 2023 list and the only | ||
UK city in National Geographic's influential ‘Best of the World’ list which annually sets out 25 of the must-see places to visit around the globe." /> | ||
|
||
<TouristInfoCards name="London" src="https://images.musement.com/cover/0002/49/london-jpeg_header-148518.jpeg" | ||
link="https://www.visitlondon.com/" description="Welcome to London! Discover the best of London with Visit London, the official guide to England’s | ||
exciting capital. Find things to do in London, from iconic sightseeing spots and fun-filled days out to top restaurants, theatre and unmissable London events. If you’re not able to visit just yet, plan ahead to make the most of your next visit." /> | ||
|
||
<TouristInfoCards name={"Glasgow"} src="https://www.visitscotland.com/blog/wp-content/uploads/2021/10/Park_Circus_and_Kelvingrove_Park.jpg.jpg" | ||
link="https://peoplemakeglasgow.com/" description="You’re guaranteed to find accommodation in Glasgow which suits your taste and budget. Whether you’re looking for something uniquely Glaswegian, a trendy hotel, a vibrant hostel or | ||
a comfortable city centre apartment, you can be assured of a warm welcome." /> | ||
|
||
</div> | ||
Comment on lines
+43
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The TouristInfoCards component represents one card, yet it's plural (i.e. Cards not Card). I think it's better to have two components, first is TouristInfoCards which uses multiple TouristInfoCard components. For example: TouristInfoCards () => You can also take the TouristInfoCards component to a new file to keep the App.js file simple and clean. |
||
<Bookings /> | ||
<Restaurant /> | ||
<Footer address={["123 Fake Street, London, E1 4UD", "[email protected]", "0123 456789"]} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default App; | ||
export default App; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,47 @@ | ||
import React from "react"; | ||
import React, { useState, useEffect } from "react"; | ||
import Search from "./Search.js"; | ||
// import SearchResults from "./SearchResults.js"; | ||
// import FakeBookings from "./data/fakeBookings.json"; | ||
import SearchResults from "./SearchResults.js"; | ||
import FakeBookings from "./data/fakeBookings.json"; | ||
|
||
|
||
|
||
const Bookings = () => { | ||
const search = searchVal => { | ||
console.info("TO DO!", searchVal); | ||
}; | ||
const [bookings, setBookings] = useState([]) | ||
|
||
function doingFetch() { | ||
fetch("https://cyf-react.glitch.me") | ||
.then((response) => { | ||
if (!response.ok) { | ||
throw new Error(response.status) | ||
} else { | ||
return response.json() | ||
} | ||
|
||
}) | ||
.then((data) => { | ||
console.log("data----->", data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: It's usually better to remove the debugging statements before you send your code for review. |
||
if (data) setBookings(data) | ||
}) | ||
} | ||
useEffect(() => { | ||
doingFetch() | ||
}, []); | ||
|
||
|
||
return ( | ||
<div className="App-content"> | ||
<div className="container"> | ||
<Search search={search} /> | ||
{/* <SearchResults results={FakeBookings} /> */} | ||
<SearchResults results={bookings} /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Bookings; | ||
|
||
|
||
|
||
export default Bookings; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import moment from "moment" | ||
import React, { useState } from "react" | ||
|
||
|
||
const SearchResults = (props) => { | ||
let allData = props.results | ||
return ( | ||
<table class="table table-striped"> | ||
|
||
<thead> | ||
|
||
<tr className="title-table"> | ||
<th scope="col">ID</th> | ||
<th scope="col">Title</th> | ||
<th scope="col">First Name</th> | ||
<th scope="col">Surname</th> | ||
<th scope="col">Email</th> | ||
<th scope="col">Room ID</th> | ||
<th scope="col">Check In Date</th> | ||
<th scope="col">Check Out Date</th> | ||
<th scope="col">Nights</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{ | ||
|
||
allData.map(client => { | ||
let a = moment(client.checkOutDate) | ||
let b = moment(client.checkInDate) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: it's better to have a more descriptive variable names. let checkOutDate = moment(client.checkOutDate) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks will do) |
||
const [active, setActive] = useState(false) | ||
const handleClick = () => { | ||
setActive(!active) | ||
} | ||
return ( | ||
<tr onClick={handleClick} style={{ backgroundColor: active ? "#607042" : "#797979" }}> | ||
<th scope="row">{client.id}</th> | ||
<td>{client.title}</td> | ||
<td>{client.firstName}</td> | ||
<td>{client.surname}</td> | ||
<td>{client.email}</td> | ||
<td>{client.roomId}</td> | ||
<td>{client.checkInDate}</td> | ||
<td>{client.checkOutDate}</td> | ||
<td>{a.diff(b, 'days')}</td> | ||
</tr> | ||
) | ||
}) | ||
} | ||
</tbody> | ||
</table> | ||
) | ||
} | ||
|
||
export default SearchResults; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of moving the Heading and Footer components in two separate files, Heading.js and Footer.js. It'll be more future proof in case the components get larger and require more work.