diff --git a/src/App.js b/src/App.js index 83eb68b..b9bb689 100644 --- a/src/App.js +++ b/src/App.js @@ -11,6 +11,8 @@ import Navbar from 'react-bootstrap/Navbar'; import Button from 'react-bootstrap/Button'; import ProgressBar from 'react-bootstrap/ProgressBar'; import Accordion from 'react-bootstrap/Accordion'; +import ToastContainer from 'react-bootstrap/ToastContainer' +import Toast from 'react-bootstrap/Toast' import { FaCheckCircle } from 'react-icons/fa'; @@ -24,6 +26,7 @@ const BACKEND_URL = "https://projectdivar.com:4505" function ItemGroup(p) { const { data } = p + const { contributor } = p const { setData1,setData2,setData3,setData4,setLastModified,lastModified } = p const [displayData,setDisplayData] = useState([]) @@ -51,6 +54,12 @@ function ItemGroup(p) { } }) },[displayData]) + + 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}); + } return {p.name} @@ -61,14 +70,10 @@ function ItemGroup(p) { { - 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()}); - }} type="number" min="0" max={item.required}/> / {item.required} {item.required!==item.obtained&&{ - var correctedVal=item.required; 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} - }));}}/>} + 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) + }}/>} View Item Info @@ -91,6 +96,8 @@ function App() { const [total,setTotal] = useState(0) const [listData,setListData] = useState([]) const [lastModified,setLastModified] = useState(new Date()) + + const [contributor,setContributor] = useState("") useEffect(()=>{ const interval = setInterval(()=>{ @@ -198,40 +205,56 @@ function App() { BUN logo BUN Collab App + {contributor.length>0&&Signed in as {contributor}} - - {data.length>0? - <> - - - - - - - : - !disabled&& - - - {total===0?{ - const reader = new FileReader() - reader.onload=(ev)=>{ - setFileData(ev.target.result) - } - reader.readAsText(f.target.files[0]) - }} style={{opacity:0}} id="uploads" type="file" accept=".txt,.csv"/>: - <> - - - - -
{Math.round(((failed+succeeded)/total)*100)+"%"}
- - } - -
- } -
+ + {contributor.length===0?<> + {if (k.key==='Enter') {setContributor(document.getElementById("username").value)}}} id="username"/> + + : + data.length>0? + <> + + + + + + + : + !disabled&& + + + {total===0?{ + const reader = new FileReader() + reader.onload=(ev)=>{ + setFileData(ev.target.result) + } + reader.readAsText(f.target.files[0]) + }} style={{opacity:0}} id="uploads" type="file" accept=".txt,.csv"/>: + <> + + + + +
{Math.round(((failed+succeeded)/total)*100)+"%"}
+ + } + +
+ + } +
+ + {console.log("closing")}} bg="primary"> + + Testing + 11 mins ago + + + +
+
); }