From 6290d51d75bfc546fa33232d108e1042cb02a303 Mon Sep 17 00:00:00 2001 From: Anton Gundermann Date: Tue, 8 Aug 2023 16:49:47 +0200 Subject: [PATCH 1/8] fixed: issue #1 --- package-lock.json | 1 + src/Components/NavBar.jsx | 24 +++++--- src/Components/ProductFilters.jsx | 68 ++++++++++++++++------ src/Components/ProductTable.jsx | 96 +++++++++++++++++++------------ 4 files changed, 128 insertions(+), 61 deletions(-) diff --git a/package-lock.json b/package-lock.json index d01ddfa..bbd664e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "react-ecommerce", "version": "0.0.1", "dependencies": { "@headlessui/react": "^1.6.0", diff --git a/src/Components/NavBar.jsx b/src/Components/NavBar.jsx index b1d0db9..3f7cb4f 100644 --- a/src/Components/NavBar.jsx +++ b/src/Components/NavBar.jsx @@ -1,5 +1,5 @@ -import { ShoppingBagIcon } from "@heroicons/react/outline"; -import React from "react"; +import { ShoppingBagIcon } from '@heroicons/react/outline' +import React from 'react' export default function NavBar({ setOpen }) { return ( @@ -23,7 +23,10 @@ export default function NavBar({ setOpen }) { {/* Logo (lg-) */} - + Workflow {/* Cart Icon */}
-
@@ -54,5 +64,5 @@ export default function NavBar({ setOpen }) { - ); + ) } diff --git a/src/Components/ProductFilters.jsx b/src/Components/ProductFilters.jsx index 0f3262a..806779b 100644 --- a/src/Components/ProductFilters.jsx +++ b/src/Components/ProductFilters.jsx @@ -1,19 +1,27 @@ -import { Disclosure, Menu, Transition } from "@headlessui/react"; -import { ChevronDownIcon, FilterIcon } from "@heroicons/react/solid"; -import React, { Fragment } from "react"; +import { Disclosure, Menu, Transition } from '@headlessui/react' +import { ChevronDownIcon, FilterIcon } from '@heroicons/react/solid' +import React, { Fragment } from 'react' function classNames(...classes) { - return classes.filter(Boolean).join(" "); + return classes.filter(Boolean).join(' ') } -export default function ProductFilters({ filterOptions, setFilterOptions, sortOptions, setSortOptions }) { +export default function ProductFilters({ + filterOptions, + setFilterOptions, + sortOptions, + setSortOptions, +}) { return ( -

+

Filters

@@ -28,7 +36,10 @@ export default function ProductFilters({ filterOptions, setFilterOptions, sortOp
-
@@ -41,7 +52,10 @@ export default function ProductFilters({ filterOptions, setFilterOptions, sortOp Price
{filterOptions.price.map((option, optionIdx) => ( -
+
-
@@ -61,7 +78,10 @@ export default function ProductFilters({ filterOptions, setFilterOptions, sortOp Color
{filterOptions.color.map((option, optionIdx) => ( -
+
-
@@ -82,7 +105,10 @@ export default function ProductFilters({ filterOptions, setFilterOptions, sortOp
- +
Sort @@ -110,11 +136,21 @@ export default function ProductFilters({ filterOptions, setFilterOptions, sortOp
- ); + ) } diff --git a/src/Components/ProductTable.jsx b/src/Components/ProductTable.jsx index ea76621..37f4151 100644 --- a/src/Components/ProductTable.jsx +++ b/src/Components/ProductTable.jsx @@ -1,57 +1,75 @@ -import React, { useEffect, useState } from "react"; -import ProductFilters from "./ProductFilters"; +import React, { useEffect, useState } from 'react' +import ProductFilters from './ProductFilters' const getDefaultFilterOptions = () => { return { price: [ - { minValue: 0, maxValue: 25, label: "$0 - $25", checked: false }, - { minValue: 25, maxValue: 50, label: "$25 - $50", checked: false }, - { minValue: 50, maxValue: 75, label: "$50 - $75", checked: false }, - { minValue: 75, maxValue: Number.MAX_VALUE, label: "$75+", checked: false }, + { minValue: 0, maxValue: 25, label: '$0 - $25', checked: false }, + { minValue: 25, maxValue: 50, label: '$25 - $50', checked: false }, + { minValue: 50, maxValue: 75, label: '$50 - $75', checked: false }, + { + minValue: 75, + maxValue: Number.MAX_VALUE, + label: '$75+', + checked: false, + }, ], color: [ - { value: "beige", label: "Beige", checked: false }, - { value: "green", label: "Green", checked: false }, - { value: "white", label: "White", checked: false }, - { value: "black", label: "Black", checked: false }, - { value: "gray", label: "Gray", checked: false }, - { value: "teal", label: "Teal", checked: false }, + { value: 'beige', label: 'Beige', checked: false }, + { value: 'green', label: 'Green', checked: false }, + { value: 'white', label: 'White', checked: false }, + { value: 'black', label: 'Black', checked: false }, + { value: 'gray', label: 'Gray', checked: false }, + { value: 'teal', label: 'Teal', checked: false }, ], - }; -}; + } +} const getDefaultSortOptions = () => { return [ - { name: "Price", current: false }, - { name: "Newest", current: false }, - ]; -}; + { name: 'Price', current: false }, + { name: 'Newest', current: false }, + ] +} export default function ProductTable({ cart, updateCart }) { - let [products, setProducts] = useState([]); + let [products, setProducts] = useState([]) - const [filterOptions, setFilterOptions] = useState(getDefaultFilterOptions()); - const [sortOptions, setSortOptions] = useState(getDefaultSortOptions()); + const [filterOptions, setFilterOptions] = useState(getDefaultFilterOptions()) + const [sortOptions, setSortOptions] = useState(getDefaultSortOptions()) useEffect(() => { let fetchProducts = async () => { - console.info("Fetching Products..."); - let res = await fetch("http://localhost:3001/products"); - let body = await res.json(); - setProducts(body); - }; - fetchProducts(); - }); + console.info('Fetching Products...') + let res = await fetch('http://localhost:3001/products') + let body = await res.json() + let sortedProducts = [] + if (sortOptions[0].current) { + sortedProducts = body.sort((a, b) => a.price - b.price) + } else if (sortOptions[1].current) { + sortedProducts = body.sort((a, b) => a.releaseDate - b.releaseDate) + } else { + sortedProducts = body + } + setProducts(sortedProducts) + } + fetchProducts() + }, [sortOptions]) return (
- ); + ) } From 3cc10e9709a97f4ee71162149184baafcde2e15a Mon Sep 17 00:00:00 2001 From: Anton Gundermann Date: Tue, 8 Aug 2023 18:32:41 +0200 Subject: [PATCH 2/8] fixed: issue #2 --- src/Components/Cart.jsx | 61 +++++++++++++++++++++++++++++------------ src/Pages/Home.jsx | 28 +++++++++++++------ todo.md | 1 + 3 files changed, 64 insertions(+), 26 deletions(-) diff --git a/src/Components/Cart.jsx b/src/Components/Cart.jsx index 917b7a1..9fc9d91 100644 --- a/src/Components/Cart.jsx +++ b/src/Components/Cart.jsx @@ -1,15 +1,18 @@ -import { Dialog, Transition } from "@headlessui/react"; -import { XIcon } from "@heroicons/react/outline"; -import React, { Fragment } from "react"; +import { Dialog, Transition } from '@headlessui/react' +import { XIcon } from '@heroicons/react/outline' +import React, { Fragment } from 'react' export default function Cart({ open, setOpen, cart, updateCart }) { return ( - + { - setOpen; + setOpen }} >
@@ -39,7 +42,10 @@ export default function Cart({ open, setOpen, cart, updateCart }) {
- Shopping cart + + {' '} + Shopping cart{' '} +
-