浏览代码

auto sort to latest on selected product

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

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

20
   useEffect(() => {
20
   useEffect(() => {
21
 
21
 
22
     if (products.length > 0) {
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
   }, [products])
32
   }, [products])
68
             />
74
             />
69
 
75
 
70
             <Button sx={{ position: "absolute", top: 20, left: 20, boxShadow: 0 }} variant="contained">
76
             <Button sx={{ position: "absolute", top: 20, left: 20, boxShadow: 0 }} variant="contained">
71
-            NEW
72
-          </Button>
77
+              NEW
78
+            </Button>
73
 
79
 
74
             <Box sx={{ pb: 5, pt: 3 }}>
80
             <Box sx={{ pb: 5, pt: 3 }}>
75
               <Typography variant="body1" sx={{ fontWeight: "400", mb: 1 }}>
81
               <Typography variant="body1" sx={{ fontWeight: "400", mb: 1 }}>

正在加载...
取消
保存