Home.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import styles from "styles/Home.module.scss";
  2. import Card from "components/Card";
  3. import Title from "components/Title";
  4. import { GOOD_FIND } from "apollo/queries";
  5. import { useQuery } from "@apollo/client";
  6. import _ from 'lodash';
  7. const Home = () => {
  8. const {data, loading, error} = useQuery(GOOD_FIND, {variables: {query: "[{}]"}});
  9. console.log(data);
  10. if (!data) {
  11. if (error) {
  12. return (
  13. <div style={{ width: "100%", display: "flex", justifyContent: "center", marginTop: "30px" }}>
  14. <Title txt={error} size={25} transform="uppercase" />
  15. </div>
  16. );
  17. } else if (loading) {
  18. return (
  19. <div style={{ width: "100%", display: "flex", justifyContent: "center", marginTop: "30px" }}>
  20. <Title txt="Loading..." size={25} transform="uppercase" />
  21. </div>
  22. );
  23. }
  24. } else {
  25. return (
  26. <section className={styles.home}>
  27. <div className={styles.container}>
  28. <div className={styles.row}>
  29. <div className={styles.title}>
  30. <Title txt="all products" color="#171717" size={22} transform="uppercase" />
  31. </div>
  32. </div>
  33. <div className={styles.row}>
  34. {
  35. _.get(data, 'GoodFind').filter(({name}) => name).map((product, key) => <Card product={product} key={key} />)
  36. }
  37. </div>
  38. </div>
  39. </section>
  40. );
  41. }
  42. };
  43. export default Home;