This repository has been archived by the owner on Feb 9, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 767
London-10 | Iryna Lypnyk | React | cyf-hotel-react #608
Open
IrynaLypnyk
wants to merge
9
commits into
CodeYourFuture:master
Choose a base branch
from
IrynaLypnyk:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b983f6f
Extract the search button in its own component
IrynaLypnyk ecf7599
Extract the header in its own component, add logo to heading
IrynaLypnyk f7886a3
Create and use a new component to show info cards
IrynaLypnyk aa1845a
Create a Footer component
IrynaLypnyk abe3f4b
lesson 1
IrynaLypnyk 0a501b0
lesson 2
IrynaLypnyk 68c488b
lesson 3
IrynaLypnyk e918a41
lesson 3 fix table overflow
IrynaLypnyk 21c4320
update README.md with link to netlify
IrynaLypnyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,27 @@ | ||
import React from "react"; | ||
import "./App.css"; | ||
|
||
import Bookings from "./Bookings"; | ||
import "./App.css"; | ||
import Footer from "./Footer"; | ||
import Heading from "./Heading"; | ||
import Restaurant from "./Restaurant"; | ||
import TouristInfoCards from "./TouristInfoCards"; | ||
|
||
const data = ["123 Fake Street, London, E1 4UD", "[email protected]", "0123 456789"]; | ||
|
||
const App = () => { | ||
|
||
return ( | ||
<div className="App"> | ||
<header className="App-header">CYF Hotel</header> | ||
<Bookings /> | ||
<Heading /> | ||
<div className="App-content"> | ||
<div className="container"> | ||
<TouristInfoCards /> | ||
<Bookings /> | ||
<Restaurant /> | ||
</div> | ||
</div> | ||
<Footer data={data} /> | ||
</div> | ||
); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,61 @@ | ||
import React from "react"; | ||
import React, { useEffect, useState } 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 [bookings, setBookings] = useState([]); | ||
const [filteredBookings, setFilteredBookings] = useState([]); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [error, setError] = useState(false); | ||
|
||
useEffect(() => { | ||
setIsLoading(true); | ||
fetch("https://cyf-react.glitch.me") | ||
.then(res => { | ||
if(res.status >= 400) { | ||
throw new Error("Server responds with error!"); | ||
} else { | ||
return res.json() | ||
}}) | ||
.then(data => { | ||
setBookings(data); | ||
setIsLoading(false); | ||
}, | ||
err => { | ||
setError(err) | ||
setIsLoading(false); | ||
}); | ||
}, []); | ||
|
||
useEffect(()=> { | ||
setFilteredBookings(bookings) | ||
}, [bookings]) | ||
|
||
|
||
const search = searchVal => { | ||
console.info("TO DO!", searchVal); | ||
if(searchVal) { | ||
const filteredBookings = bookings.filter(booking => { | ||
const {firstName, surname} = booking; | ||
const preparedSearchVal = searchVal.toLowerCase(); | ||
const preparedFirstName = firstName.toLowerCase(); | ||
const preparedSurname = surname.toLowerCase(); | ||
return preparedFirstName.includes(preparedSearchVal) || preparedSurname.includes(preparedSearchVal) | ||
}); | ||
setFilteredBookings(filteredBookings); | ||
} else { | ||
setFilteredBookings(bookings); | ||
} | ||
}; | ||
|
||
|
||
return ( | ||
<div className="App-content"> | ||
<div className="container"> | ||
<Search search={search} /> | ||
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. Can you think how you'd modify this code so that the search function lives in the search component? Some questions that might help you think about a way you could are:
|
||
{/* <SearchResults results={FakeBookings} /> */} | ||
{isLoading && <div>Loading...</div>} | ||
{!isLoading && error && <div>{error.message} </div>} | ||
{!isLoading && bookings && <SearchResults results={filteredBookings} />} | ||
</div> | ||
</div> | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React, { useEffect, useState } from "react"; | ||
|
||
function CustomerProfile({id}) { | ||
const [profile, setProfile] = useState(id) | ||
|
||
useEffect(()=>{ | ||
fetch(`https://cyf-react.glitch.me/customers/${id}`) | ||
.then(res=>res.json()) | ||
.then(data=>setProfile(data)); | ||
},[id]) | ||
|
||
return ( | ||
<> | ||
{profile ? ( | ||
<div className="App-content"> | ||
<h4>Customer profile</h4> | ||
<ul> | ||
<li>Customer ID: {profile.id}</li> | ||
<li>VIP: {profile.vip ? "Yes" : "No"}</li> | ||
<li>Email: {profile.email}</li> | ||
<li>Tel: {profile.phoneNumber}</li> | ||
</ul> | ||
</div> | ||
) : null} | ||
</> | ||
|
||
); | ||
} | ||
|
||
export default CustomerProfile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from "react"; | ||
|
||
const Footer = ({data}) => { | ||
return ( | ||
<footer className="footer bg-light"> | ||
<ul> | ||
{data.map(item => (<ul key={item}>{item}</ul>))} | ||
</ul> | ||
</footer> | ||
); | ||
}; | ||
|
||
export default Footer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from "react"; | ||
|
||
const Heading = () => { | ||
return ( | ||
<header className="App-header bg-dark"> | ||
<img src="/images/logo.png" alt="logo" className="App-logo"/> | ||
<h1 className="App-logo-text">CYF Hotel</h1> | ||
</header> | ||
); | ||
}; | ||
|
||
export default Heading; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
|
||
function InfoCard({img, title, descr, link}) { | ||
return ( | ||
<div className="card"> | ||
<img src={img} className="card-img-top" /> | ||
<div className="card-body"> | ||
<h3 className="card-title">{title}</h3> | ||
<p className="card-text">{descr}</p> | ||
</div> | ||
<div className="card-footer"><a href={link} className="btn btn-outline-primary">More Information</a></div> | ||
</div> | ||
); | ||
} | ||
|
||
export default InfoCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, { useState } from "react"; | ||
|
||
function Order({orderType}) { | ||
const [orders, setOrders] = useState(0); | ||
|
||
const orderOne = () => { | ||
setOrders(orders + 1); | ||
} | ||
|
||
return ( | ||
<li> | ||
{orderType}: {orders} <button className="btn btn-primary" onClick={orderOne}>Add</button> | ||
</li> | ||
); | ||
} | ||
|
||
export default Order; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nicely done, everything that follows has nothing to do with functionality as they are the exact same but want to talk about coding style. Do take these with a pinch of salt as styling varies from developer to developer, but worth sharing as it's always nice to know someone else's style.
I, personally, find that having too many variables can sometimes make the code harder to follow. So for example there are quite a few temporary variables within your filter that are reassigned. Sometimes that makes it easier to read but sometimes it can make it harder and is a balancing act to be aware of.
The second comment is that as your else branch is the case where you do nothing to the original bookings, it can be done in a different way to having two different calls to the setter.