Category.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import styles from "styles/Category.module.scss";
  2. import Card from "components/Card";
  3. import Title from "components/Title";
  4. import useMakeRequest from "hooks/useMakeRequest";
  5. import { useParams } from "react-router-dom";
  6. import _ from 'lodash';
  7. import { CATEGORY_FIND_ONE, GOOD_FIND_ONE } from "apollo/queries";
  8. import { useQuery } from "@apollo/client";
  9. const Category = () => {
  10. const { _id } = useParams();
  11. const {data, loading, error} = useQuery(CATEGORY_FIND_ONE, {variables: {query: `[{\"_id\" : \"${_id}\"}]`}});
  12. const category = _.get(data,'CategoryFindOne', null);
  13. const product = _.get(category,'goods', null);
  14. const categoryName = _.get(category,'name', null);
  15. if (!product) {
  16. return (
  17. <div style={{ width: "100%", display: "flex", justifyContent: "center", marginTop: "30px" }}>
  18. <Title txt="Loading..." size={25} transform="uppercase" />
  19. </div>
  20. );
  21. } else {
  22. return (
  23. <section className={styles.category}>
  24. <div className={styles.container}>
  25. <div className={styles.row}>
  26. {product && (
  27. <div className={styles.title}>
  28. <Title txt={categoryName} color="#171717" size={22} transform="uppercase" />
  29. </div>
  30. )}
  31. </div>
  32. <div className={styles.row}>
  33. {product ? (
  34. product.map((product, key) => <Card product={product} key={key} />)
  35. ) : (
  36. <div style={{ width: "100%", display: "flex", justifyContent: "center" }}>
  37. <Title txt={product.error} size={25} transform="uppercase" />
  38. </div>
  39. )}
  40. </div>
  41. </div>
  42. </section>
  43. );
  44. }
  45. };
  46. export default Category;