Implement adjustments to input system, added global 'Enter' key for submitting.

master
sigonasr2, Sig, Sigo 3 years ago
parent c736d3218e
commit 3adea5c6a2
  1. 5
      package-lock.json
  2. 1
      package.json
  3. 46
      src/App.js
  4. 22
      src/style.css

5
package-lock.json generated

@ -12486,6 +12486,11 @@
"resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.9.tgz", "resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.9.tgz",
"integrity": "sha512-nQTTcUu+ATDbrSD1BZHr5kgSD4oF8OFjxun8uAaL8RwPBacGBNPf/yAuVVdx17N8XNzRDMrZ9XcKZHCjPW+9ew==" "integrity": "sha512-nQTTcUu+ATDbrSD1BZHr5kgSD4oF8OFjxun8uAaL8RwPBacGBNPf/yAuVVdx17N8XNzRDMrZ9XcKZHCjPW+9ew=="
}, },
"react-global-key-down-hook": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/react-global-key-down-hook/-/react-global-key-down-hook-0.2.1.tgz",
"integrity": "sha512-7bi/jJlD6VlRird5VJTKow3q28pWn6H36zhOzBmKGgklAdEjqqwyjX0vxBcHlohd08VcUUBiLxRJ/7oz3IZOiQ=="
},
"react-is": { "react-is": {
"version": "16.13.1", "version": "16.13.1",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",

@ -14,6 +14,7 @@
"react": "^17.0.2", "react": "^17.0.2",
"react-bootstrap-icons": "^1.5.0", "react-bootstrap-icons": "^1.5.0",
"react-dom": "^16.14.0", "react-dom": "^16.14.0",
"react-global-key-down-hook": "^0.2.1",
"react-modal": "^3.14.3", "react-modal": "^3.14.3",
"react-router": "^5.2.0", "react-router": "^5.2.0",
"react-router-dom": "^5.2.0", "react-router-dom": "^5.2.0",

@ -2,9 +2,10 @@
import './reset.css'; // Generic reset import './reset.css'; // Generic reset
import './style.css'; // The new new import './style.css'; // The new new
import React, {useState,useEffect,useRef,useReducer} from 'react'; import React, {useState,useEffect,useRef,useReducer} from 'react';
import useGlobalKeyDown from 'react-global-key-down-hook'
import Modal from 'react-modal' import Modal from 'react-modal'
import {XSquare, XSquareFill} from 'react-bootstrap-icons' import {XSquare, XSquareFill, PlusCircle} from 'react-bootstrap-icons'
import { import {
HashRouter, HashRouter,
@ -375,18 +376,32 @@ function InputBox(p) {
const [failed,setFailed] = useState(false) const [failed,setFailed] = useState(false)
const [sending,setSending] = useState(false) const [sending,setSending] = useState(false)
function changeFunc(f){setValue(f.currentTarget.value)} function changeFunc(f){setValue(f.currentTarget.value)
if (p.callback4) {
p.callback4(f.currentTarget.value)
}}
function blurFunc(f){ function blurFunc(f){
setSending(true) if (p.callback) {
setFailed(false) setSending(true)
p.callback(f.currentTarget.value) setFailed(false)
.then(()=>{setFailed(false)}) p.callback(f.currentTarget.value)
.catch(()=>{setFailed(true)}) .then(()=>{setFailed(false)})
.then(()=>{setSending(false)})} .catch(()=>{setFailed(true)})
.then(()=>{setSending(false)})}
return p.data?<select className={failed?"failedInput":sending?"submitting":""} value={value} onChange={(f)=>{changeFunc(f)}} onBlur={(f)=>{blurFunc(f)}}> else
if (p.callback3) {
p.callback3(f.currentTarget.value)
}}
function keydownFunc(f){
if (p.callback2) {
p.callback2(f,value)
}
}
return p.data?<select className={failed?"failedInput":sending?"submitting":""} value={value} onKeyDown={(f)=>{keydownFunc(f)}} onChange={(f)=>{changeFunc(f)}} onBlur={(f)=>{blurFunc(f)}}>
{p.includeBlankValue&&<option/>}
{p.data.map((item)=><option value={item.id}>{item.id} - {item.name||item.username}</option>)} {p.data.map((item)=><option value={item.id}>{item.id} - {item.name||item.username}</option>)}
</select>:<input className={failed?"failedInput":sending?"submitting":""} value={value} onChange={(f)=>{changeFunc(f)}} onBlur={(f)=>{blurFunc(f)}}/> </select>:<input className={failed?"failedInput":sending?"submitting":""} value={value} onKeyDown={(f)=>{keydownFunc(f)}} onChange={(f)=>{changeFunc(f)}} onBlur={(f)=>{blurFunc(f)}}/>
} }
function TableEditor(p) { function TableEditor(p) {
@ -411,6 +426,7 @@ function TableEditor(p) {
function SubmitBoxes() { function SubmitBoxes() {
axios.post(BACKEND_URL+p.path,submitVals) axios.post(BACKEND_URL+p.path,submitVals)
.then(()=>{ .then(()=>{
setSubmitVal("Clear")
setUpdate(true) setUpdate(true)
}) })
.catch((err)=>{ .catch((err)=>{
@ -418,6 +434,10 @@ function TableEditor(p) {
}) })
} }
useGlobalKeyDown(()=>{
SubmitBoxes()
},['Enter'])
useEffect(()=>{ useEffect(()=>{
setUpdate(true) setUpdate(true)
},[p.path]) },[p.path])
@ -456,7 +476,6 @@ function TableEditor(p) {
{!loading? {!loading?
<div className="table-responsive"> <div className="table-responsive">
<table cellPadding="10" className="table text-light table-padding"> <table cellPadding="10" className="table text-light table-padding">
<caption>{JSON.stringify(dependencies)}</caption>
<thead> <thead>
<tr> <tr>
<th className="table-padding"></th> <th className="table-padding"></th>
@ -464,6 +483,8 @@ function TableEditor(p) {
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{<tr><td></td>{fields.map((col,i)=><td key={i}>{<InputBox includeBlankValue={true} data={dependencies[col.name]} callback4={
(f)=>{setSubmitVal({field:col.name,value:f});}}/>}</td>)}<input style={{position:'absolute',top:"-1000px"}}/><PlusCircle onClick={()=>{SubmitBoxes()}} className="submitbutton"/></tr>}
{data.map((dat)=><tr key={dat.id}> {data.map((dat)=><tr key={dat.id}>
<td><XSquareFill className="webicon" onClick={()=>{axios.delete(BACKEND_URL+p.path,{data:{id:dat.id}}).then(()=>{setUpdate(true)}).catch((err)=>{alert(err.response.data)})}}/></td>{fields.map((col,i)=><td key={dat.id+"_"+i} className="table-padding table"> <td><XSquareFill className="webicon" onClick={()=>{axios.delete(BACKEND_URL+p.path,{data:{id:dat.id}}).then(()=>{setUpdate(true)}).catch((err)=>{alert(err.response.data)})}}/></td>{fields.map((col,i)=><td key={dat.id+"_"+i} className="table-padding table">
<InputBox data={dependencies[col.name]} callback={(value)=>{ <InputBox data={dependencies[col.name]} callback={(value)=>{
@ -472,7 +493,6 @@ function TableEditor(p) {
id:dat.id id:dat.id
}) })
}} value={String(dat[col.name])}/></td>)}</tr>)} }} value={String(dat[col.name])}/></td>)}</tr>)}
{<tr><td></td>{fields.map((col,i)=><td key={i}>{<input id={"submitField"+i} onBlur={(i===fields.length-1)?(f)=>{setSubmitVal({field:col.name,value:f.currentTarget.value});SubmitBoxes();document.getElementById("submitField0").focus()}:(f)=>{setSubmitVal({field:col.name,value:f.currentTarget.value})}}/>}</td>)}</tr>}
</tbody> </tbody>
</table> </table>
</div>:<img src={process.env.PUBLIC_URL+"/spinner.gif"} alt=""/>} </div>:<img src={process.env.PUBLIC_URL+"/spinner.gif"} alt=""/>}

@ -898,19 +898,25 @@ button{
} }
.submitting{ .submitting{
border: 1px solid rgba(0,150,200,1); border: 1px solid rgba(0,150,200,1);
background: linear-gradient(-45deg, #2317c7, #3ce77e, #23a6d5, #23d5ab); background: linear-gradient(-90deg, #124425,#000000, #124425);
background-size: 400% 400%; background-size: 10% 400%;
animation: submitgradient 1s ease infinite; animation: submitgradient 1.5s ease infinite;
} }
@keyframes submitgradient { @keyframes submitgradient {
0% { 0% {
background-position: 0% 50%; background-position: 0% 100%;
}
50% {
background-position: 100% 50%;
} }
100% { 100% {
background-position: 0% 50%; background-position: 100% 0%;
} }
} }
.submitbutton{
width:32px;
height:32px;
}
.submitbutton:hover{
color:rgba(0,200,0,1);
cursor:pointer;
}
Loading…
Cancel
Save