Browse Source

mobile nav collections

master
azri 1 week ago
parent
commit
7ee37ab1fe

+ 3
- 5
src/components/Navbar/Navbar.jsx View File

186
 
186
 
187
   const renderCollectionDisplay = (colletion) => {
187
   const renderCollectionDisplay = (colletion) => {
188
 
188
 
189
-    let { title, image } = colletion
190
-
191
     return (
189
     return (
192
       <SwiperSlide>
190
       <SwiperSlide>
193
         <Box
191
         <Box
194
           className="animate__animated animate__fadeIn animate__fast"
192
           className="animate__animated animate__fadeIn animate__fast"
195
           sx={{
193
           sx={{
196
-            backgroundImage: `url(${image.url})`,
194
+            backgroundImage: `url(${colletion?.image?.url})`,
197
             backgroundSize: "cover",
195
             backgroundSize: "cover",
198
             backgroundRepeat: "no-repeat",
196
             backgroundRepeat: "no-repeat",
199
             backgroundPosition: "center center",
197
             backgroundPosition: "center center",
207
             }
205
             }
208
           }}
206
           }}
209
           onClick={() => {
207
           onClick={() => {
210
-            sessionStorage.setItem('amber-select-collection', title)
208
+            sessionStorage.setItem('amber-select-collection', colletion?.title)
211
             sessionStorage.setItem('amber-select-product-type', displayCollection.productType)
209
             sessionStorage.setItem('amber-select-product-type', displayCollection.productType)
212
             window.location.href = `/products`;
210
             window.location.href = `/products`;
213
           }}
211
           }}
223
               transform: "translate(-50%, -50%)"
221
               transform: "translate(-50%, -50%)"
224
             }}
222
             }}
225
           >
223
           >
226
-            {title.toUpperCase()}
224
+            {colletion?.title?.toUpperCase()}
227
           </Typography>
225
           </Typography>
228
         </Box>
226
         </Box>
229
       </SwiperSlide>
227
       </SwiperSlide>

+ 144
- 30
src/components/Navbar/components/MobileNav/MobileNav.jsx View File

1
 import React from "react";
1
 import React from "react";
2
-import { Drawer, Box, List, ListItem, ListItemButton, ListItemText } from "@mui/material";
2
+import { Drawer, Box, List, ListItem, ListItemButton, ListItemText, Accordion, AccordionSummary, AccordionDetails, AccordionActions, Typography, Button } from "@mui/material";
3
+import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
4
+import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
5
+import Grid from '@mui/material/Grid2';
3
 import logoSrc from "../../../../assets/images/amberlogo.png";
6
 import logoSrc from "../../../../assets/images/amberlogo.png";
4
 
7
 
5
 const MobileNav = ({ open, onClose, menu = [] }) => {
8
 const MobileNav = ({ open, onClose, menu = [] }) => {
9
+
10
+  // React.useEffect(()=>{
11
+
12
+  //   console.log(menu)
13
+  //   debugger
14
+
15
+  // },[menu])
16
+
17
+  const renderCollectionDisplay = (colletion) => {
18
+
19
+    return (
20
+      <Grid
21
+        size={6}
22
+        className="animate__animated animate__fadeIn animate__fast"
23
+        sx={{
24
+          padding:5,
25
+          backgroundImage: `url(${colletion?.image?.url})`,
26
+          backgroundSize: "cover",
27
+          backgroundRepeat: "no-repeat",
28
+          backgroundPosition: "center center",
29
+          height: "100%",
30
+          paddingTop: "45%",
31
+          position: "relative",
32
+          cursor: "pointer",
33
+          transition: "transform 0.3s ease",
34
+          ":hover": {
35
+            transform: "scale(1.1)"
36
+          }
37
+        }}
38
+        onClick={() => {
39
+          // sessionStorage.setItem('amber-select-collection', colletion?.title)
40
+          // sessionStorage.setItem('amber-select-product-type', displayCollection.productType)
41
+          window.location.href = `/products`;
42
+        }}
43
+      >
44
+        <Typography
45
+          variant="body1"
46
+          sx={{
47
+            color: "white",
48
+            fontWeight: "bolder",
49
+            position: "absolute",
50
+            top: "50%",
51
+            left: "50%",
52
+            transform: "translate(-50%, -50%)"
53
+          }}
54
+        >
55
+          {colletion?.title?.toUpperCase()}
56
+        </Typography>
57
+      </Grid>
58
+    )
59
+
60
+  }
61
+
6
   return (
62
   return (
7
     <Drawer
63
     <Drawer
8
       open={open}
64
       open={open}
9
       onClose={onClose}
65
       onClose={onClose}
10
-      onClick={()=>{onClose()}}
11
       sx={{
66
       sx={{
12
         "& .MuiDrawer-paper": {
67
         "& .MuiDrawer-paper": {
13
           backgroundColor: "white",
68
           backgroundColor: "white",
17
       }}
72
       }}
18
     >
73
     >
19
       {/* Logo Section */}
74
       {/* Logo Section */}
20
-      <Box
21
-        sx={{
22
-          display: "flex",
23
-          justifyContent: "center",
24
-          alignItems: "center",
25
-          height: 80,
26
-        }}
27
-      >
28
-        <a href="/">
29
-          <img
30
-            src={logoSrc}
31
-            alt="Logo"
32
-            style={{
33
-              width: 150,
34
-              height: 25,
35
-            }}
36
-          />
37
-        </a>
75
+      <Box sx={{ height: 80, px: 2 }}>
76
+        <Grid
77
+          container
78
+          alignItems="center"
79
+          justifyContent="space-between"
80
+          sx={{ height: "100%" }}
81
+        >
82
+          {/* Left Spacer */}
83
+          <Grid item xs={3} />
84
+
85
+          {/* Centered Logo */}
86
+          <Grid item xs={6} container justifyContent="center">
87
+            <a href="/">
88
+              <img
89
+                src={logoSrc}
90
+                alt="Logo"
91
+                style={{
92
+                  width: 150,
93
+                  height: 25,
94
+                }}
95
+              />
96
+            </a>
97
+          </Grid>
38
 
98
 
99
+          {/* Right 'X' Button */}
100
+          <Grid item xs={3} container justifyContent="flex-end">
101
+            <button
102
+              onClick={() => { onClose() }}
103
+              style={{
104
+                background: "none",
105
+                border: "none",
106
+                fontSize: 24,
107
+                cursor: "pointer",
108
+              }}
109
+            >
110
+              &#x2715; {/* Unicode for "X" symbol */}
111
+            </button>
112
+          </Grid>
113
+        </Grid>
39
       </Box>
114
       </Box>
40
 
115
 
116
+
41
       {/* Main Navigation */}
117
       {/* Main Navigation */}
42
-      <Box sx={{ width: 250 }} role="presentation">
43
-        <List>
44
-          {menu.map(({ title, link }) => (
45
-            <ListItem key={title} disablePadding>
118
+      <Box sx={{ width: "100%" }} role="presentation">
119
+        {/* <List>
120
+          {menu.map(({ productType, collection }) => (
121
+            <ListItem key={productType} disablePadding>
46
               <ListItemButton
122
               <ListItemButton
47
-                onClick={() => { window.location.href = link }}
123
+                onClick={() => { 
124
+                  sessionStorage.setItem('amber-select-collection', productType)
125
+                  sessionStorage.removeItem('amber-select-collection')
126
+                  if(collection?.length == 0) window.location.href = `/products`;
127
+                }}
48
                 sx={{
128
                 sx={{
49
-                  color: "white",
129
+                  borderTop:"1px solid rgba(0,0,0,0.1)",
50
                   "&:hover": {
130
                   "&:hover": {
51
-                    backgroundColor: "white",
52
-                    color: "black",
131
+                    backgroundColor: "#95AAC5",
53
                   },
132
                   },
54
                 }}
133
                 }}
55
               >
134
               >
56
-                <ListItemText sx={{ ml: 2 }} primary={title} />
135
+                <ListItemText sx={{ 
136
+                  ml: 2, 
137
+                  color: "black",
138
+                }} primary={productType?.toUpperCase()} />
139
+                {(collection?.length > 0) && <ArrowDropDownIcon fontSize="small" sx={{color:"black"}} /> }
57
               </ListItemButton>
140
               </ListItemButton>
58
             </ListItem>
141
             </ListItem>
59
           ))}
142
           ))}
60
-        </List>
143
+        </List> */}
144
+        {menu.map(({ productType, collection }) => (
145
+          <Accordion
146
+            disableGutters={true}
147
+            onClick={() => {
148
+              sessionStorage.setItem('amber-select-collection', productType)
149
+              sessionStorage.removeItem('amber-select-collection')
150
+              if (collection?.length == 0) window.location.href = `/products`;
151
+            }}
152
+            sx={{
153
+              backgroundColor: "rgba(0,0,0,0)",
154
+              boxShadow: "none"
155
+            }}>
156
+            <AccordionSummary
157
+              expandIcon={(collection?.length > 0) ? <ExpandMoreIcon /> : ""}
158
+              aria-controls="panel1-content"
159
+              id="panel1-header"
160
+            >
161
+              <Typography variant="body1" sx={{ fontWeight: "500" }} >{productType?.toUpperCase()}</Typography>
162
+            </AccordionSummary>
163
+            <AccordionDetails>
164
+              {(collection?.length > 0) &&
165
+                <Grid container sx={{maxHeight:"1000px", overflow:"scroll", overflowX:"hidden"}}>
166
+                  {collection?.map((colletion) => {
167
+                    return renderCollectionDisplay(colletion)
168
+                  })}
169
+                </Grid>
170
+              }
171
+            </AccordionDetails>
172
+          </Accordion>
173
+        ))}
174
+
61
       </Box>
175
       </Box>
62
     </Drawer>
176
     </Drawer>
63
   );
177
   );

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

43
           color: image ? "white" : "black"
43
           color: image ? "white" : "black"
44
         }}
44
         }}
45
       >
45
       >
46
-        {title.toUpperCase() || " "}
46
+        {title?.toUpperCase() || " "}
47
       </Typography>
47
       </Typography>
48
     </Box>
48
     </Box>
49
   );
49
   );

+ 12
- 6
src/components/ProductList/ProductList.jsx View File

18
   const products = data || [];
18
   const products = data || [];
19
   const allCollection = products.flatMap(product => product.collections);
19
   const allCollection = products.flatMap(product => product.collections);
20
   const uniqueCollection = Array.from(
20
   const uniqueCollection = Array.from(
21
-    new Map(allCollection.map(item => [item.title, item])).values()
21
+    new Map(allCollection.map(item => [item?.title, item])).values()
22
   );
22
   );
23
   return uniqueCollection;
23
   return uniqueCollection;
24
 }
24
 }
77
         (product) => product.productType === productType
77
         (product) => product.productType === productType
78
       );
78
       );
79
 
79
 
80
-      setFilteredProducts(newFilteredProducts)
80
+      setTimeout(()=>{
81
+        setFilteredProducts(newFilteredProducts)
82
+      },100)
81
 
83
 
82
       const tagList = getAllTags(newFilteredProducts);
84
       const tagList = getAllTags(newFilteredProducts);
83
       setTagFilterOption(tagList);
85
       setTagFilterOption(tagList);
126
           if (collection == 'all') {
128
           if (collection == 'all') {
127
             return product.productType === productType
129
             return product.productType === productType
128
           } else {
130
           } else {
129
-            return product.productType === productType && product.collections.some(data => data.title === collection)
131
+            return product.productType === productType && product.collections.some(data => data?.title === collection)
130
           }
132
           }
131
 
133
 
132
         }
134
         }
141
         newFilteredProducts = newFilteredProducts.sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt));
143
         newFilteredProducts = newFilteredProducts.sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt));
142
       }
144
       }
143
 
145
 
144
-      setFilteredProducts(newFilteredProducts)
146
+      
147
+      setFilteredProducts([]) //cause I want those fadeIn animation
148
+      setTimeout(()=>{
149
+        setFilteredProducts(newFilteredProducts)
150
+      },100)
145
 
151
 
146
     }
152
     }
147
 
153
 
154
   const renderProduct = (handle, img_url, title, collection_name, minPrice, minPriceCurrency, maxPrice, maxPriceCurrency, extra_desc) => {
160
   const renderProduct = (handle, img_url, title, collection_name, minPrice, minPriceCurrency, maxPrice, maxPriceCurrency, extra_desc) => {
155
 
161
 
156
     return (
162
     return (
157
-      <Grid className="animate__animated animate__fadeIn" item size={{ xs: 6, sm: 6, md: 3 }}>
163
+      <Grid className="animate__animated animate__fadeIn" de item size={{ xs: 6, sm: 6, md: 3 }}>
158
 
164
 
159
         <a href={`/products/${handle}`} style={{textDecoration:"none",color:"#000"}}>
165
         <a href={`/products/${handle}`} style={{textDecoration:"none",color:"#000"}}>
160
           <Box
166
           <Box
314
             let maxPriceCurrency = maxVariantPrice.currencyCode
320
             let maxPriceCurrency = maxVariantPrice.currencyCode
315
 
321
 
316
             let img_url = images[0].url
322
             let img_url = images[0].url
317
-            let collection_name = collections[0].title
323
+            let collection_name = collections[0]?.title
318
 
324
 
319
             if (index < size) {
325
             if (index < size) {
320
               return renderProduct(handle, img_url, title, collection_name, minPrice, minPriceCurrency, maxPrice, maxPriceCurrency, "")
326
               return renderProduct(handle, img_url, title, collection_name, minPrice, minPriceCurrency, maxPrice, maxPriceCurrency, "")

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

137
           let maxPriceCurrency = maxVariantPrice.currencyCode
137
           let maxPriceCurrency = maxVariantPrice.currencyCode
138
 
138
 
139
           let img_url = images[0].url
139
           let img_url = images[0].url
140
-          let collection_name = collections[0].title
140
+          let collection_name = collections[0]?.title
141
 
141
 
142
           // ID
142
           // ID
143
           const parts = id.split('/');
143
           const parts = id.split('/');

Loading…
Cancel
Save