Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

London-10 | Iryna Lypnyk | React | cyf-hotel-react #608

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

IrynaLypnyk
Copy link

No description provided.

@sonarcloud
Copy link

sonarcloud bot commented Jun 26, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link

@ryankav ryankav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a lot to comment on all looks good a couple of styling comments

Comment on lines +37 to +47
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);
Copy link

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.

const search = (searchVal) => {
  let searchQuery = searchVal.toLowerCase();
  let bookingResults = bookings;
  
  if (searchQuery) {
    bookingResults = bookings.filter({ firstName, surname } => {
      return firstName.toLowerCase().includes(searchQuery) || surname.toLowerCase().includes(searchQuery);
    });
  }
  
  setFilteredBookings(bookingResults)
}

/>
<button className="btn btn-primary">Search</button>
<SearchButton/>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a space

<SearchButton />

Comment on lines +5 to +6
const SearchResults = (props) => {
const { results } = props;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can do this in place:

const SearchResults = ({ results }) => {...}

};


return (
<div className="App-content">
<div className="container">
<Search search={search} />
Copy link

Choose a reason for hiding this comment

The 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:

  1. Is the bookings state needed anywhere else other than the search?
  2. Which setState functions would you need to pass down into the search component

@migmow migmow added the reviewed A volunteer has reviewed this PR label Jul 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
reviewed A volunteer has reviewed this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants