浏览代码

auto sort to latest on selected product

master
azri 1周前
父节点
当前提交
ef1dc073e7
共有 1 个文件被更改,包括 9 次插入3 次删除
  1. 9
    3
      src/components/ProductSelected/ProductSelected.jsx

+ 9
- 3
src/components/ProductSelected/ProductSelected.jsx 查看文件

@@ -20,7 +20,13 @@ const ProductSelected = () => {
20 20
   useEffect(() => {
21 21
 
22 22
     if (products.length > 0) {
23
-      setFilterProducts(products.filter(({ selected }) => selected))
23
+
24
+      let selectedProducts = products.filter(({ selected }) => selected) || []
25
+      
26
+      //sort
27
+      selectedProducts = selectedProducts.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt));
28
+      setFilterProducts(selectedProducts)
29
+      
24 30
     }
25 31
 
26 32
   }, [products])
@@ -68,8 +74,8 @@ const ProductSelected = () => {
68 74
             />
69 75
 
70 76
             <Button sx={{ position: "absolute", top: 20, left: 20, boxShadow: 0 }} variant="contained">
71
-            NEW
72
-          </Button>
77
+              NEW
78
+            </Button>
73 79
 
74 80
             <Box sx={{ pb: 5, pt: 3 }}>
75 81
               <Typography variant="body1" sx={{ fontWeight: "400", mb: 1 }}>

正在加载...
取消
保存