From 6ae320c1c4ff864dafcd2e293507c514b612ac53 Mon Sep 17 00:00:00 2001 From: Joshua Sigona Date: Sat, 28 Aug 2021 10:25:29 +0900 Subject: [PATCH] Add in enter functionality --- src/App.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/App.js b/src/App.js index 5a0c5c8..7b94a1b 100644 --- a/src/App.js +++ b/src/App.js @@ -29,6 +29,7 @@ function ItemGroup(p) { const { contributor } = p const { setData1,setData2,setData3,setData4,setLastModified,lastModified } = p const [displayData,setDisplayData] = useState([]) + const [lockout,setLockout] = useState(false) useEffect(()=>{ setDisplayData([...data].sort((a,b)=>{ @@ -57,8 +58,15 @@ function ItemGroup(p) { function updateItem(item,target,contributor) { var correctedVal=Math.min(item.required,target.value); - if (correctedVal===item.obtained) {return;} - axios.post(BACKEND_URL+"/updateItem",{obtained:correctedVal,id:item.id,last_modified:new Date(),item_name:item.name,username:contributor,required:item.required,operation:correctedVal==item.required?"FINISH":correctedVal>item.obtained?"INCREASE":"SET",previous_amt:item.obtained}); + if (correctedVal==item.obtained) {return;} + setLockout(true) + axios.post(BACKEND_URL+"/updateItem",{obtained:correctedVal,id:item.id,last_modified:new Date(),item_name:item.name,username:contributor,required:item.required,operation:correctedVal==item.required?"FINISH":correctedVal>item.obtained?"INCREASE":"SET",previous_amt:item.obtained}) + .then((data)=>{ + setLockout(false) + }) + .catch((err)=>{ + + }) } return @@ -69,7 +77,11 @@ function ItemGroup(p) { {item.name} - { + { + if (k.key==='Enter') {updateItem(item,document.getElementById("field_"+item.id),contributor)} + }} + onChange={(f)=>{ if (f.currentTarget.value>=item.required) {f.currentTarget.blur()} }} onBlur={(f)=>{updateItem(item,f.currentTarget,contributor)}} type="number" min="0" max={item.required}/> / {item.required} {item.required!==item.obtained&&{ updateItem(item,{value:item.required},contributor)