refactor categories container

This commit is contained in:
Ruidy 2021-03-28 15:48:41 +02:00
parent 681c281d51
commit 760d54c07c
9 changed files with 43 additions and 45 deletions

View file

@ -1,33 +1,26 @@
import React from "react"; import { FC } from "react";
import { Link, useRouteMatch } from "react-router-dom"; import { Link, useRouteMatch } from "react-router-dom";
const CategoryEntry = ({ category }) => { type Props = {
strCategory: string;
strCategoryThumb: string;
};
const CategoriesEntry: FC<Props> = ({ strCategory, strCategoryThumb }) => {
const { url } = useRouteMatch(); const { url } = useRouteMatch();
const {
strCategory,
strCategoryThumb,
// strCategoryDescription
} = category;
return ( return (
// <CardEntry item={meal} />
<Link to={`${url}/${strCategory}`}> <Link to={`${url}/${strCategory}`}>
<li> <li>
<div className="row"> <div className="row">
<div className="col s12"> <div className="col s12">
<div className="card horizontal hoverable"> <div className="card horizontal hoverable">
<div className="card-image valign-wrapper"> <div className="card-image valign-wrapper">
<img <img src={strCategoryThumb} alt={strCategory} />
// className="responsive-img"
src={strCategoryThumb}
alt={strCategory}
/>
</div> </div>
<div className="card-stacked"> <div className="card-stacked">
<div className="card-content black-text"> <div className="card-content black-text">
<h2 className="logo">{strCategory}</h2> <h2 className="logo">{strCategory}</h2>
{/* <p>{strCategoryDescription}</p> */}
</div> </div>
</div> </div>
</div> </div>
@ -38,4 +31,4 @@ const CategoryEntry = ({ category }) => {
); );
}; };
export default CategoryEntry; export default CategoriesEntry;

View file

@ -0,0 +1,21 @@
import { FC } from "react";
import PageLayout from "../../../layouts/PageLayout";
import CategoriesEntry from "./CategoriesEntry";
type Props = {
categories: { strCategory: string; strCategoryThumb: string }[];
};
export const CategoriesPage: FC<Props> = ({ categories }) => (
<PageLayout title="Chef's Categories">
<ul>
{categories.map(({ strCategory, strCategoryThumb }, i) => (
<CategoriesEntry
key={i}
strCategory={strCategory}
strCategoryThumb={strCategoryThumb}
/>
))}
</ul>
</PageLayout>
);

View file

@ -1,9 +1,9 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { PreLoader } from "../components/PreLoader"; import { PreLoader } from "../../components/PreLoader";
import { CategoryListPage } from "../pages/CategoryListPage"; import { getData } from "../../services/api";
import { getData } from "../services/api"; import { CategoriesPage } from "./components/CategoriesPage";
export const CategoryListController = () => { export const Categories = () => {
const [categories, setCategories] = useState({ categories: [] }); const [categories, setCategories] = useState({ categories: [] });
const getCategories = () => { const getCategories = () => {
@ -12,12 +12,11 @@ export const CategoryListController = () => {
useEffect(() => { useEffect(() => {
getCategories(); getCategories();
// eslint-disable-next-line
}, []); }, []);
return categories.categories.length === 0 ? ( return categories.categories.length === 0 ? (
<PreLoader /> <PreLoader />
) : ( ) : (
<CategoryListPage categories={categories.categories} /> <CategoriesPage categories={categories.categories} />
); );
}; };

View file

@ -1,8 +1,8 @@
import { FC } from "react"; import { FC } from "react";
import Meal from "../../types/Meal"; import Meal from "../../../types/meal";
import { MealIngredientList } from "./components/MealIngredientList"; import { MealIngredientList } from "./MealIngredientList";
import { MealPresentation } from "./components/MealPresentation"; import { MealPresentation } from "./MealPresentation";
import { MealRecipe } from "./components/MealRecipe"; import { MealRecipe } from "./MealRecipe";
type Props = { type Props = {
ingredients: string[]; ingredients: string[];

View file

@ -1,6 +1,6 @@
import { FC } from "react"; import { FC } from "react";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import Meal from "../../../types/Meal"; import Meal from "../../../types/meal";
type Props = { type Props = {
meal: Meal; meal: Meal;

View file

@ -3,7 +3,7 @@ import { useParams } from "react-router-dom";
import { NotFoundPage } from "../../pages/NotFoundPage"; import { NotFoundPage } from "../../pages/NotFoundPage";
import { useFirebase } from "../../services/Firebase"; import { useFirebase } from "../../services/Firebase";
import { useAuth0 } from "../../utils/auth0-spa"; import { useAuth0 } from "../../utils/auth0-spa";
import { MealPage } from "./MealPage"; import { MealPage } from "./components/MealPage";
import { getMeal, getRandomMeal } from "./service"; import { getMeal, getRandomMeal } from "./service";
export const Meal: FC = () => { export const Meal: FC = () => {

View file

@ -1,15 +0,0 @@
import React from "react";
import PageLayout from "../layouts/PageLayout";
import CategoryEntry from "../components/CategoryEntry";
export const CategoryListPage = ({ categories }) => {
return (
<PageLayout title="Chef's Categories">
<ul>
{categories.map((category, i) => (
<CategoryEntry key={i} category={category} />
))}
</ul>
</PageLayout>
);
};

View file

@ -1,6 +1,6 @@
import { Redirect, Route, Switch } from "react-router-dom"; import { Redirect, Route, Switch } from "react-router-dom";
import { CategoryController } from "../containers/CategoryController"; import { CategoryController } from "../containers/CategoryController";
import { CategoryListController } from "../containers/CategoryListController"; import { Categories } from "../containers/Categories";
import { Home } from "../containers/Home"; import { Home } from "../containers/Home";
import { Meal } from "../containers/Meal"; import { Meal } from "../containers/Meal";
import { ProfileController } from "../containers/ProfileController"; import { ProfileController } from "../containers/ProfileController";
@ -29,7 +29,7 @@ const AppRouter = ({
</Route> </Route>
<Route exact path="/categories"> <Route exact path="/categories">
<CategoryListController /> <Categories />
</Route> </Route>
<Route path="/categories/:strCategory/"> <Route path="/categories/:strCategory/">