diff --git a/src/App.js b/src/App.js index 20af6df..3b19adb 100644 --- a/src/App.js +++ b/src/App.js @@ -16,7 +16,19 @@ import Accordion from 'react-bootstrap/Accordion'; const parse = require('csv-parse/lib/sync') const axios = require('axios'); +const BACKEND_URL = "https://projectdivar.com:4505" + function ItemGroup(p) { + const { data } = p + const [displayData,setDisplayData] = useState([]) + + useEffect(()=>{ + setDisplayData([...data].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} + })) + },[data]) function findIndex(name,arr) { for (var i=0;i {p.name} - {p.data.map((item,i,arr)=> + {displayData.map((item,i,arr)=> {item.name} - {if (f.currentTarget.value>=item.required) {f.currentTarget.blur()} var newData=[...p.data];newData[i].obtained=Math.min(item.required,f.currentTarget.value);p.setData(newData.sort((a,b)=>{ + {var correctedVal=Math.min(item.required,f.currentTarget.value); if (f.currentTarget.value>=item.required) {f.currentTarget.blur()} axios.post(BACKEND_URL+"/updateItem",{obtained:correctedVal,id:item.id,last_modified:new Date()}); var newData=[...displayData];newData[i].obtained=correctedVal;p.setLastModified(new Date());setDisplayData(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} @@ -61,6 +73,31 @@ function App() { const [failed,setFailed] = useState(0) const [total,setTotal] = useState(0) const [listData,setListData] = useState([]) + const [lastModified,setLastModified] = useState(new Date()) + + useEffect(()=>{ + const interval = setInterval(()=>{ + axios.get(BACKEND_URL+"/lastUpdate") + .then((data)=>{ + if (new Date(data.data[0].last_modified)>lastModified) { + console.log("Updating entries... "+[lastModified,data.data[0].last_modified]) + setLastModified(new Date()) + return axios.get("https://projectdivar.com:4505/getData") + .then((data)=>{ + //setData(data.data) + setData(data.data.slice(0,135)) + setData2(data.data.slice(135,250)) + setData3(data.data.slice(250,388)) + setData4(data.data.slice(388,data.data.length)) + }) + } + }) + .catch((err)=>{ + console.log(err.message) + }) + },1000) + return ()=>clearInterval(interval) + },[lastModified]) const disabled=true @@ -82,7 +119,7 @@ function App() { required:d[val].Needed, icon:r.Icon } - return axios.post("https://projectdivar.com:4505/setItem",dataObj) + return axios.post(BACKEND_URL+"/setItem",dataObj) } } if (!found) { @@ -150,10 +187,10 @@ function App() { {data.length>0? <> - - - - + + + + : !disabled&&