Browse Source

sort

master
azri 4 weeks ago
parent
commit
f92ab0f30d

+ 33
- 13
src/components/ProductList/ProductList.jsx View File

48
 
48
 
49
   //filter
49
   //filter
50
   const [category, setCategory] = useState('all');
50
   const [category, setCategory] = useState('all');
51
-  const [sort, setSort] = useState('all')
51
+  const [sort, setSort] = useState('title')
52
 
52
 
53
   useEffect(() => {
53
   useEffect(() => {
54
 
54
 
97
         }
97
         }
98
       );
98
       );
99
 
99
 
100
+      if (sort === "title") {
101
+        newFilteredProducts = newFilteredProducts.sort((a, b) => a.title.localeCompare(b.title));
102
+      } else if (sort === "new") {
103
+        newFilteredProducts = newFilteredProducts.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt));
104
+      } else if (sort === "old") {
105
+        newFilteredProducts = newFilteredProducts.sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt));
106
+      }
107
+
100
       setFilteredProducts(newFilteredProducts)
108
       setFilteredProducts(newFilteredProducts)
101
 
109
 
102
     }
110
     }
103
 
111
 
104
-  }, [category])
105
-
106
-
112
+  }, [category, sort])
107
 
113
 
108
   useEffect(() => {
114
   useEffect(() => {
109
     if (products) console.log(products)
115
     if (products) console.log(products)
171
         sx={{
177
         sx={{
172
           display: "flex",
178
           display: "flex",
173
           justifyContent: "space-between",
179
           justifyContent: "space-between",
180
+          py:1,
181
+          flexDirection:{
182
+            xs:"column",
183
+            sm:"row",
184
+            md:"row",
185
+            lg:"row"
186
+          },
174
           alignItems: "center",
187
           alignItems: "center",
175
           backgroundColor: "background.black",
188
           backgroundColor: "background.black",
176
           color: "white",
189
           color: "white",
179
         }}
192
         }}
180
       >
193
       >
181
         {/* Left Side: Page Title */}
194
         {/* Left Side: Page Title */}
182
-        <Typography variant="body2">
195
+        <Typography variant="body2" sx={{fontSize:10}}>
183
           {`${filteredProducts.length} Item`}
196
           {`${filteredProducts.length} Item`}
184
         </Typography>
197
         </Typography>
185
 
198
 
186
         {/* Right Side: Option Inputs */}
199
         {/* Right Side: Option Inputs */}
187
-        <Box sx={{ display: "flex", gap: 2 }}>
200
+        <Box sx={{ display: "flex", gap: 2, flexDirection:{
201
+            xs:"column",
202
+            sm:"row",
203
+            md:"row",
204
+            lg:"row"
205
+          }, }}>
188
 
206
 
189
           <FormControl sx={{ m: 1, display: "flex", flexDirection: "row" }} variant="standard">
207
           <FormControl sx={{ m: 1, display: "flex", flexDirection: "row" }} variant="standard">
190
-            <Typography variant="body2" sx={{ mr: 1, my: "auto" }}>Filter By Category</Typography>
208
+            <Typography variant="body2" sx={{ mr: 1, my: "auto" }}>Category</Typography>
191
             <Select
209
             <Select
192
               value={category}
210
               value={category}
193
               onChange={(event) => {
211
               onChange={(event) => {
201
             </Select>
219
             </Select>
202
           </FormControl>
220
           </FormControl>
203
 
221
 
204
-          <FormControl sx={{ m: 1, display: { xs: "none", sm: "none", md: "flex" }, flexDirection: "row" }} variant="standard">
205
-            <Typography variant="body2" sx={{ mr: 1, my: "auto" }}>Sort By</Typography>
222
+          <FormControl sx={{ m: 1, display: "flex", flexDirection: "row" }} variant="standard">
223
+            <Typography variant="body2" sx={{ mr: 1, my: "auto" }}>Sort</Typography>
206
             <Select
224
             <Select
207
               value={sort}
225
               value={sort}
208
-              onChange={handleChange}
226
+              onChange={(event) => {
227
+                setSort(event.target.value);
228
+              }}
209
               input={<BootstrapInput />}
229
               input={<BootstrapInput />}
210
               name="sort"
230
               name="sort"
211
             >
231
             >
212
-              <MenuItem defaultValue value={''}>All</MenuItem>
213
-              <MenuItem defaultValue value={'all'}>Newest</MenuItem>
214
-
232
+              <MenuItem defaultValue value={'title'}>Title</MenuItem>
233
+              <MenuItem defaultValue value={'new'}>Newest</MenuItem>
234
+              <MenuItem defaultValue value={'old'}>Oldest</MenuItem>
215
             </Select>
235
             </Select>
216
           </FormControl>
236
           </FormControl>
217
 
237
 

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

32
         }
32
         }
33
       }}>
33
       }}>
34
       </Box>
34
       </Box>
35
+      <SocialMedia />
36
+      <Feature />
35
     </>
37
     </>
36
   )
38
   )
37
 }
39
 }

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

134
         nodes {
134
         nodes {
135
           id
135
           id
136
           title
136
           title
137
+          createdAt
137
           productType
138
           productType
138
           tags
139
           tags
139
           compareAtPriceRange {
140
           compareAtPriceRange {

Loading…
Cancel
Save