Skip to content

Commit

Permalink
Simplify RenderFoods use
Browse files Browse the repository at this point in the history
  • Loading branch information
aivuk committed Jul 15, 2023
1 parent 40b47ca commit a92c24f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/components/RenderFoods.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import type { FoodList } from "../types/food";
import Item from "./Item";
import { Grid, styled } from "@mui/material";
import { FunctionComponent } from "react"

const StyledGrid = styled(Grid)(() => ({
display: "flex",
Expand All @@ -10,8 +10,13 @@ const StyledGrid = styled(Grid)(() => ({
margin: "0.25em",
}));

interface RenderFoodProps {
foodList: FoodList
}

//render the grid of foods
function RenderFoods(foodList: FoodList) {
const RenderFoods:FunctionComponent<RenderFoodProps> = (props:RenderFoodProps) => {
const foodList = props.foodList
const foodItems = foodList.map((item, key) => {
return (
<Grid item xs={4} key={key}>
Expand Down
8 changes: 2 additions & 6 deletions src/routes/FoodOfTheMonth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ export default function FoodOfTheMonth() {
const fruitsList = filterFoodType(monthFood, "Fruits");
const veggiesList = filterFoodType(monthFood, "Veggies");

//renders the fruits, veggies and others
const RenderFruits = () => RenderFoods(fruitsList);
const RenderVeggies = () => RenderFoods(veggiesList);

//variables to handle the changing tabs
const [foodType, setFoodType] = useState("Fruits" as FoodCategory);
// @ts-ignore
Expand All @@ -48,9 +44,9 @@ export default function FoodOfTheMonth() {
const changeTab = (foodType: FoodCategory) => {
switch (foodType) {
case "Fruits":
return <RenderFruits />;
return <RenderFoods foodList={fruitsList}/>;
case "Veggies":
return <RenderVeggies />;
return <RenderFoods foodList={veggiesList}/>;
}
};

Expand Down

0 comments on commit a92c24f

Please sign in to comment.