Browse Source

sorting

master
azri 4 weeks ago
parent
commit
07158d9eb5

+ 1
- 6
src/App.js View File

63
           <Route path='/cart' element={<Cart />} />
63
           <Route path='/cart' element={<Cart />} />
64
           <Route path='/checkout' element={<Checkout />} />
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
         </Routes>
68
         </Routes>
74
       </BrowserRouter>
69
       </BrowserRouter>

+ 51
- 0
src/components/CategoryList/CategoryList.jsx View File

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 View File

1
+export { default } from "./CategoryList"

+ 5
- 2
src/components/CollectionList/CollectionList.jsx View File

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

+ 1
- 1
src/components/Header/Header.jsx View File

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

+ 6
- 4
src/components/PageTitle/PageTitle.jsx View File

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

+ 7
- 1
src/pages/Cart.jsx View File

109
                 let { amount, currencyCode } = cost.totalAmount
109
                 let { amount, currencyCode } = cost.totalAmount
110
                 let { image, product, title } = merchandise
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
                 return (
116
                 return (
113
                   <TableRow
117
                   <TableRow
114
                     key={id}
118
                     key={id}
121
                       <img
125
                       <img
122
                         src={image.src}
126
                         src={image.src}
123
                         alt={image.src}
127
                         alt={image.src}
128
+                        onClick={()=>{ window.location.href = `/products/${prodID}`}}
124
                         style={{
129
                         style={{
125
                           width: 100,
130
                           width: 100,
126
                           height: 100,
131
                           height: 100,
127
                           aspectRatio: '4 / 4',
132
                           aspectRatio: '4 / 4',
128
                           objectFit: 'cover',
133
                           objectFit: 'cover',
129
-                          objectPosition: "top center"
134
+                          objectPosition: "top center",
135
+                          cursor:"pointer"
130
                         }}
136
                         }}
131
                       />
137
                       />
132
                     </TableCell>
138
                     </TableCell>

+ 4
- 2
src/pages/Collection.jsx View File

9
 import { useSelector, useDispatch } from 'react-redux'
9
 import { useSelector, useDispatch } from 'react-redux'
10
 import { fetchProducts } from '../redux/slices/productSlice'
10
 import { fetchProducts } from '../redux/slices/productSlice'
11
 import image from "../assets/images/titleBg.jpg"
11
 import image from "../assets/images/titleBg.jpg"
12
+import CategoryList from '../components/CategoryList'
12
 import CollectionList from '../components/CollectionList/CollectionList'
13
 import CollectionList from '../components/CollectionList/CollectionList'
13
 
14
 
14
 const Collection = () => {
15
 const Collection = () => {
17
 
18
 
18
   return (
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
       <Box sx={{
24
       <Box sx={{
23
         px: {
25
         px: {
24
           xs: 2,
26
           xs: 2,

+ 2
- 1
src/pages/Products/index.jsx View File

22
 
22
 
23
     }else if(sessionStorage.getItem('amber-select-category')){
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
     }else{
28
     }else{
28
       window.location.href = '/'
29
       window.location.href = '/'

+ 9
- 0
src/services/CartService.js View File

56
                 ... on ProductVariant {
56
                 ... on ProductVariant {
57
                   id
57
                   id
58
                   title
58
                   title
59
+                  product {
60
+                    id
61
+                  }
59
                   selectedOptions {
62
                   selectedOptions {
60
                     name
63
                     name
61
                     value
64
                     value
129
               ... on ProductVariant {
132
               ... on ProductVariant {
130
                 id
133
                 id
131
                 title
134
                 title
135
+                product {
136
+                  id
137
+                }
132
                 selectedOptions {
138
                 selectedOptions {
133
                   name
139
                   name
134
                   value
140
                   value
198
                 ... on ProductVariant {
204
                 ... on ProductVariant {
199
                   id
205
                   id
200
                   title
206
                   title
207
+                  product {
208
+                    id
209
+                  }
201
                   selectedOptions {
210
                   selectedOptions {
202
                     name
211
                     name
203
                     value
212
                     value

+ 30
- 1
src/services/ProductService.js View File

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
 const ProductService = {
266
 const ProductService = {
240
   getProduct,
268
   getProduct,
241
   getProductsByCollection,
269
   getProductsByCollection,
242
   getProductTypes,
270
   getProductTypes,
243
-  getCollections
271
+  getCollections,
272
+  getTags
244
 }
273
 }
245
 
274
 
246
 export default ProductService
275
 export default ProductService

Loading…
Cancel
Save