From d1f31a279bc56d53076c533f5c979c52c52cb334 Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Mon, 16 Aug 2021 00:11:32 +0000 Subject: [PATCH] Fix up sort cases --- src/App.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/App.js b/src/App.js index b84a318..be44fec 100644 --- a/src/App.js +++ b/src/App.js @@ -30,21 +30,16 @@ function ItemGroup(p) { return {p.name} - {p.data.sort((a,b)=>{ - if (b.required===b.obtained&&a.required===a.obtained) { - return a.id-b.id - } else - if (b.required===b.obtained) { - return -1 - } else { - return 0 - } - }).map((item,i,arr)=> + {p.data.map((item,i,arr)=> {item.name} - {var newData=[...p.data];newData[i].obtained=Math.min(item.required,f.currentTarget.value);p.setData(newData);}} type="number" min="0" max={item.required}/> / {item.required} + {var newData=[...p.data];newData[i].obtained=Math.min(item.required,f.currentTarget.value);p.setData(newData.sort((a,b)=>{ + if (b.required===b.obtained&&a.required!==a.obtained) {return -1} + if (b.required===b.obtained&&a.required===a.obtained) {return a.id-b.id} + if (b.required!==b.obtained&&a.required!==a.obtained) {return a.id-b.id} + }));}} type="number" min="0" max={item.required}/> / {item.required} View Item Info @@ -109,6 +104,13 @@ function App() { }) .catch((err)=>{ console.log(err.message) + setData([ + {id:1726,itemid:2,name:"Fire Shard",icon:"/i/020000/020001.png",obtained:694,required:4124}, + {id:1727,itemid:3,name:"Ice Shard",icon:"/i/020000/020003.png",obtained:0,required:1226}, + {id:1728,itemid:4,name:"Wind Shard",icon:"/i/020000/020004.png",obtained:4719,required:4719}, + {id:1729,itemid:5,name:"Earth Shard",icon:"/i/020000/020006.png",obtained:15,required:1764}, + {id:1730,itemid:6,name:"Lightning Shard",icon:"/i/020000/020005.png",obtained:0,required:2374}, + ]) }) setUpdate(false) }