fihockey / react-project-5

0 stars 0 forks source link

Feedback #3

Open Charlie-robin opened 9 months ago

Charlie-robin commented 9 months ago

Feedback

Requirements:

  1. A deployed website (using GitHub Pages): NOT DONE
  2. A public GitHub repository for your codebase: DONE
  3. Using Punk API: DONE
  4. Tests where possible RTL: N/A

Plan

Score

MARKING-SCHEME

Category Score
Functionality 30 / 55
Testing 0 / 10
React Use 15 / 20
Design 15 / 15
Total Score 60 / 100

Positive

Constructive

type NavBarProps = {
  handleSearchQuery: (event: FormEvent<HTMLInputElement>) => void;
};
<Navbar
  handleHighABVFilter={handleHighABVFilter}
  handleAcidicFilter={handleAcidicFilter}
  handleClassicRangeFilter={handleClassicRangeFilter}
  handleSearchQuery={handleSearchQuery}
  searchQuery={searchQuery}
/>
const CardList = ({ highABV, acidic, classicRange, searchQuery }: CardListProps) => {
  const [text] = useState(""); // REMOVE THIS

  // SET THIS TO AN EMPTY ARRAY AS THE DEFAULT STATE
  // - THIS WILL STOP YOUR STATE BEING THIS UNION TYPE  Beer[] | undefined
  const [beers, setBeers] = useState<Beer[]>([]);

  const getBeers = async () => {
    // WHY IS THIS SET UP page=1?
    const url = `https://api.punkapi.com/v2/beers?page=1&per_page=80`;
    const res = await fetch(url);
    const data: Beer[] = await res.json();
    setBeers(data);
  };

  useEffect(() => {
    getBeers();
  }, []);

  // YOU CAN REMOVE THE beers? AS THE TYPE WILL NOT BE UNDEFINED NOW
  const filterBeers = (beers: Beer[]) => {
    // ONE LOOP WHERE YOU CHECK EACH OF YOUR CONDITIONS & THE SEARCH QUERY
    const filteredBeers = beers.filter(beer => {
      // EACH OF THESE RELATES TO EACH FILTER
      const hasSearchQuery = beer.name.toLowerCase().includes(searchQuery);
      // HERE THE CONDITION IS NEGATED SO IF THE highABV IS TRUE THE SECOND CONDITION WILL NEED TO BE TRUE
      // IF THE highABV IS FALSE THE CONDITION IS IGNORED
      const passesABVFilter = !highABV || beer.abv > 6;
      const passesAcidityFilter = !acidic || beer.ph < 4;
      // IF YOU HAVE MULTIPLE CONDITIONS YOU CAN USE VARIABLES AS LABELS TO MAKE ALL OF THE CONDITIONS EASIER TO UNDERSTAND
      // WITH THE YEAR RANGE YOU CAN GET THE YEAR AND COMPARE IT
      const firstBrewedYear = Number(beer.first_brewed.slice(3));
      const passesClassicFilter = !classicRange || firstBrewedYear < 2010;

      // THEN YOU CAN RETURN ALL OF THEM
      // THEY ALL NEED TO BE TRUE FOR THE BEER TO GET ADDED TO THE NEW ARRAY THAT WILL BE DISPLAYED
      return hasSearchQuery && passesABVFilter && passesClassicFilter && passesAcidityFilter;
    });

    return filteredBeers;
  };

  return (
    <div className="cardlist_container">
      {filterBeers(beers).map(beer => {
        return <Card beer={beer} />;
      })}
    </div>
  );
};

export default CardList;
- components/
  - NavBar/
    - NavBar.tsx
    - NavBar.scss

  - FilterList/
    - FilterList.tsx
    - FilterList.scss

  - FilterItem/
    - FilterItem.tsx
    - FilterItem.scss

  - SearchBox/
    - SearchBox.tsx
    - SearchBox.scss

  - Card/
    - Card.tsx
    - Card.scss

  - CardList/
    - CardList.tsx
    - CardList.scss

- data
    - beers.ts
    - types.ts

Charlie-robin commented 9 months ago

Hey @fihockey thanks for making some of the fixes requested.

I have updated the score to 70 which is in the green 👍.

Category Score
Functionality 40 / 55
Testing 0 / 10
React Use 15 / 20
Design 15 / 15
Total Score 70 / 100