Przeglądaj źródła

mobile nav collections

master
azri 1 tydzień temu
rodzic
commit
7ee37ab1fe

+ 3
- 5
src/components/Navbar/Navbar.jsx Wyświetl plik

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

+ 144
- 30
src/components/Navbar/components/MobileNav/MobileNav.jsx Wyświetl plik

@@ -1,13 +1,68 @@
1 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 6
 import logoSrc from "../../../../assets/images/amberlogo.png";
4 7
 
5 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 62
   return (
7 63
     <Drawer
8 64
       open={open}
9 65
       onClose={onClose}
10
-      onClick={()=>{onClose()}}
11 66
       sx={{
12 67
         "& .MuiDrawer-paper": {
13 68
           backgroundColor: "white",
@@ -17,47 +72,106 @@ const MobileNav = ({ open, onClose, menu = [] }) => {
17 72
       }}
18 73
     >
19 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 114
       </Box>
40 115
 
116
+
41 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 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 128
                 sx={{
49
-                  color: "white",
129
+                  borderTop:"1px solid rgba(0,0,0,0.1)",
50 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 140
               </ListItemButton>
58 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 175
       </Box>
62 176
     </Drawer>
63 177
   );

+ 1
- 1
src/components/PageTitle/PageTitle.jsx Wyświetl plik

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

+ 12
- 6
src/components/ProductList/ProductList.jsx Wyświetl plik

@@ -18,7 +18,7 @@ function getAllCollection(data) {
18 18
   const products = data || [];
19 19
   const allCollection = products.flatMap(product => product.collections);
20 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 23
   return uniqueCollection;
24 24
 }
@@ -77,7 +77,9 @@ const ProductList = ({ size = 99999 }) => {
77 77
         (product) => product.productType === productType
78 78
       );
79 79
 
80
-      setFilteredProducts(newFilteredProducts)
80
+      setTimeout(()=>{
81
+        setFilteredProducts(newFilteredProducts)
82
+      },100)
81 83
 
82 84
       const tagList = getAllTags(newFilteredProducts);
83 85
       setTagFilterOption(tagList);
@@ -126,7 +128,7 @@ const ProductList = ({ size = 99999 }) => {
126 128
           if (collection == 'all') {
127 129
             return product.productType === productType
128 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,7 +143,11 @@ const ProductList = ({ size = 99999 }) => {
141 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,7 +160,7 @@ const ProductList = ({ size = 99999 }) => {
154 160
   const renderProduct = (handle, img_url, title, collection_name, minPrice, minPriceCurrency, maxPrice, maxPriceCurrency, extra_desc) => {
155 161
 
156 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 165
         <a href={`/products/${handle}`} style={{textDecoration:"none",color:"#000"}}>
160 166
           <Box
@@ -314,7 +320,7 @@ const ProductList = ({ size = 99999 }) => {
314 320
             let maxPriceCurrency = maxVariantPrice.currencyCode
315 321
 
316 322
             let img_url = images[0].url
317
-            let collection_name = collections[0].title
323
+            let collection_name = collections[0]?.title
318 324
 
319 325
             if (index < size) {
320 326
               return renderProduct(handle, img_url, title, collection_name, minPrice, minPriceCurrency, maxPrice, maxPriceCurrency, "")

+ 1
- 1
src/components/ProductSelected/ProductSelected.jsx Wyświetl plik

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

Ładowanie…
Anuluj
Zapisz