azri пре 4 недеља
родитељ
комит
07158d9eb5

+ 1
- 6
src/App.js Прегледај датотеку

@@ -63,12 +63,7 @@ function App() {
63 63
           <Route path='/cart' element={<Cart />} />
64 64
           <Route path='/checkout' element={<Checkout />} />
65 65
 
66
-          <Route path='collection'>
67
-            {/* All Products */}
68
-            <Route index element={<Products />} />
69
-            {/* Single Product */}
70
-            <Route path=':pid' element={<Collection />} />
71
-          </Route>
66
+          <Route path='/collection/:pid' element={<Collection />}/>
72 67
 
73 68
         </Routes>
74 69
       </BrowserRouter>

+ 51
- 0
src/components/CategoryList/CategoryList.jsx Прегледај датотеку

@@ -0,0 +1,51 @@
1
+import { useEffect, useState } from "react";
2
+import { Box, Typography, Button } from "@mui/material";
3
+import ProductService from "../../services/ProductService";
4
+import Grid from '@mui/material/Grid2';
5
+
6
+const CategoryList = ({ productType }) => {
7
+
8
+  const [categorys, setCategorys] = useState(['all'])
9
+
10
+  useEffect(() => {
11
+
12
+    ProductService.getTags(productType).then((data) => {
13
+      
14
+      setCategorys([...categorys, ...data])
15
+    })
16
+
17
+
18
+
19
+  }, [])
20
+
21
+
22
+  return (
23
+    <Box sx={{ flexGrow: 1, mt: 10 }}>
24
+
25
+      {categorys.length > 0 && <Typography variant="h4" sx={{ textAlign: "center", mb: 5, fontWeight: "bolder" }}>SHOP BY CATEGORY</Typography>}
26
+
27
+      <Box
28
+        display="flex"
29
+        flexWrap="wrap"
30
+        gap={2} // Spacing between buttons
31
+        justifyContent="center" // Center align buttons
32
+        p={2} // Padding inside the container
33
+      >
34
+        {categorys.map((label, index) => (
35
+          <Button 
36
+            onClick={()=>{
37
+              sessionStorage.removeItem('amber-select-collection')
38
+              sessionStorage.setItem('amber-select-category', label)
39
+              window.location.href = "/products" 
40
+            }}
41
+            key={index} variant="contained" color="primary">
42
+            {label}
43
+          </Button>
44
+        ))}
45
+        
46
+      </Box>
47
+    </Box>
48
+  );
49
+};
50
+
51
+export default CategoryList;

+ 1
- 0
src/components/CategoryList/index.js Прегледај датотеку

@@ -0,0 +1 @@
1
+export { default } from "./CategoryList"

+ 5
- 2
src/components/CollectionList/CollectionList.jsx Прегледај датотеку

@@ -3,13 +3,13 @@ import { Box, Typography, Button } from "@mui/material";
3 3
 import ProductService from "../../services/ProductService";
4 4
 import Grid from '@mui/material/Grid2';
5 5
 
6
-const CollectionList = ({ collectionName }) => {
6
+const CollectionList = ({ productType }) => {
7 7
 
8 8
   const [collections, setCollections] = useState([])
9 9
 
10 10
   useEffect(() => {
11 11
 
12
-    ProductService.getCollections(collectionName).then((data) => {
12
+    ProductService.getCollections(productType).then((data) => {
13 13
       setCollections(data)
14 14
     })
15 15
 
@@ -19,6 +19,9 @@ const CollectionList = ({ collectionName }) => {
19 19
 
20 20
   return (
21 21
     <Box sx={{ flexGrow: 1, mt: 10 }}>
22
+
23
+      { collections.length > 0 && <Typography variant="h4" sx={{textAlign:"center", mb:5, fontWeight:"bolder"}}>COLLECTIONS</Typography>}
24
+
22 25
       <Grid container spacing={2}>
23 26
 
24 27
         {collections.map(({id, name, src}) => {

+ 1
- 1
src/components/Header/Header.jsx Прегледај датотеку

@@ -29,7 +29,7 @@ const headerStyle = createStyles({
29 29
 const Header = () => {
30 30
 
31 31
     return (
32
-        <Container>
32
+        <Container sx={{display:"none"}}>
33 33
             <Box sx={{color:"white", px:23}}>
34 34
                 <Box sx={{display:"flex", gap:1}}>
35 35
                     <InstagramIcon style={headerStyle.icon} />

+ 6
- 4
src/components/PageTitle/PageTitle.jsx Прегледај датотеку

@@ -3,7 +3,7 @@ import Box from "@mui/material/Box";
3 3
 
4 4
 import Typography from "@mui/material/Typography";
5 5
 
6
-const PageTitle = ({title = "", image = ""}) => {
6
+const PageTitle = ({title = "", image = null}) => {
7 7
 
8 8
   return (
9 9
     <Box
@@ -16,7 +16,8 @@ const PageTitle = ({title = "", image = ""}) => {
16 16
         color: "white",
17 17
         textAlign: "center",
18 18
         overflow: "hidden", // Ensures the dim layer stays inside the box
19
-        display:"flex"
19
+        display:"flex",
20
+        mt:5
20 21
       }}
21 22
     >
22 23
       {/* Overlay */}
@@ -27,7 +28,7 @@ const PageTitle = ({title = "", image = ""}) => {
27 28
           left: 0,
28 29
           right: 0,
29 30
           bottom: 0,
30
-          backgroundColor: "rgba(0, 0, 0, 0.5)", // Adjust opacity to control dimness
31
+          backgroundColor: image ? "rgba(0, 0, 0, 0.5)" : "rgba(0, 0, 0, 0)", // Adjust opacity to control dimness
31 32
           zIndex: 1,
32 33
         }}
33 34
       />
@@ -38,7 +39,8 @@ const PageTitle = ({title = "", image = ""}) => {
38 39
         sx={{
39 40
           position: "relative",
40 41
           zIndex: 2,
41
-          margin:"auto auto"
42
+          margin:"auto auto",
43
+          color: image ? "white" : "black"
42 44
         }}
43 45
       >
44 46
         {title.toUpperCase() || " "}

+ 7
- 1
src/pages/Cart.jsx Прегледај датотеку

@@ -109,6 +109,10 @@ const Cart = () => {
109 109
                 let { amount, currencyCode } = cost.totalAmount
110 110
                 let { image, product, title } = merchandise
111 111
 
112
+                // ID
113
+                const parts = product?.id?.split('/');
114
+                let prodID = parts[parts.length - 1];
115
+
112 116
                 return (
113 117
                   <TableRow
114 118
                     key={id}
@@ -121,12 +125,14 @@ const Cart = () => {
121 125
                       <img
122 126
                         src={image.src}
123 127
                         alt={image.src}
128
+                        onClick={()=>{ window.location.href = `/products/${prodID}`}}
124 129
                         style={{
125 130
                           width: 100,
126 131
                           height: 100,
127 132
                           aspectRatio: '4 / 4',
128 133
                           objectFit: 'cover',
129
-                          objectPosition: "top center"
134
+                          objectPosition: "top center",
135
+                          cursor:"pointer"
130 136
                         }}
131 137
                       />
132 138
                     </TableCell>

+ 4
- 2
src/pages/Collection.jsx Прегледај датотеку

@@ -9,6 +9,7 @@ import Feature from '../components/Feature'
9 9
 import { useSelector, useDispatch } from 'react-redux'
10 10
 import { fetchProducts } from '../redux/slices/productSlice'
11 11
 import image from "../assets/images/titleBg.jpg"
12
+import CategoryList from '../components/CategoryList'
12 13
 import CollectionList from '../components/CollectionList/CollectionList'
13 14
 
14 15
 const Collection = () => {
@@ -17,8 +18,9 @@ const Collection = () => {
17 18
 
18 19
   return (
19 20
     <>
20
-      <PageTitle title={`${pid} COLLECTIONS`} image={image} />
21
-      <CollectionList collectionName={pid}/>
21
+      <PageTitle title={`AMBER ${pid}`} image={image} />
22
+      <CategoryList productType={pid}/>
23
+      <CollectionList productType={pid}/>
22 24
       <Box sx={{
23 25
         px: {
24 26
           xs: 2,

+ 2
- 1
src/pages/Products/index.jsx Прегледај датотеку

@@ -22,7 +22,8 @@ const Products = () => {
22 22
 
23 23
     }else if(sessionStorage.getItem('amber-select-category')){
24 24
 
25
-      let categoryData = JSON.parse(sessionStorage.getItem('amber-select-category'))
25
+      let category = sessionStorage.getItem('amber-select-category')
26
+      setTitle(category)
26 27
 
27 28
     }else{
28 29
       window.location.href = '/'

+ 9
- 0
src/services/CartService.js Прегледај датотеку

@@ -56,6 +56,9 @@ const addItemToCart = async (cartId, lines) => {
56 56
                 ... on ProductVariant {
57 57
                   id
58 58
                   title
59
+                  product {
60
+                    id
61
+                  }
59 62
                   selectedOptions {
60 63
                     name
61 64
                     value
@@ -129,6 +132,9 @@ const getCart = async (cartId) => {
129 132
               ... on ProductVariant {
130 133
                 id
131 134
                 title
135
+                product {
136
+                  id
137
+                }
132 138
                 selectedOptions {
133 139
                   name
134 140
                   value
@@ -198,6 +204,9 @@ const updateItemQuantity = async (cartId, lineId, quantity) => {
198 204
                 ... on ProductVariant {
199 205
                   id
200 206
                   title
207
+                  product {
208
+                    id
209
+                  }
201 210
                   selectedOptions {
202 211
                     name
203 212
                     value

+ 30
- 1
src/services/ProductService.js Прегледај датотеку

@@ -233,6 +233,34 @@ const getCollections = async (name) => {
233 233
 
234 234
 }
235 235
 
236
+const getTags = async (productType) => {
237
+
238
+  const query = `{
239
+  products(first: 250, query: "product_type:${productType}") {
240
+      nodes {
241
+        createdAt
242
+        tags
243
+      }
244
+    }
245
+  }`
246
+
247
+  const { data, errors, extensions } = await client.request(query, {
248
+    variables: {},
249
+  });
250
+
251
+  const tagSet = new Set();
252
+
253
+  // Iterate through each item in the data
254
+  data.products.nodes.forEach(item => {
255
+    if (item.tags && Array.isArray(item.tags)) {
256
+      item.tags.forEach(tag => tagSet.add(tag));
257
+    }
258
+  });
259
+
260
+  // Convert the Set back into an array and return
261
+  return Array.from(tagSet);
262
+
263
+}
236 264
 
237 265
 
238 266
 const ProductService = {
@@ -240,7 +268,8 @@ const ProductService = {
240 268
   getProduct,
241 269
   getProductsByCollection,
242 270
   getProductTypes,
243
-  getCollections
271
+  getCollections,
272
+  getTags
244 273
 }
245 274
 
246 275
 export default ProductService

Loading…
Откажи
Сачувај