From ba914864d22a183339401b8c8599d4045c5cd63e Mon Sep 17 00:00:00 2001 From: Joshua Sigona Date: Fri, 23 Jul 2021 18:20:19 +0900 Subject: [PATCH] Editable Backend boxes --- src/App.js | 108 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 90 insertions(+), 18 deletions(-) diff --git a/src/App.js b/src/App.js index 36f0fc9..ef7a834 100644 --- a/src/App.js +++ b/src/App.js @@ -6,8 +6,7 @@ import 'reactjs-windows/dist/index.css' import { BrowserRouter as Router, Switch, - Route, - useLocation + Route } from "react-router-dom"; import { HashLink as Link } from 'react-router-hash-link'; @@ -15,6 +14,8 @@ import { HashLink as Link } from 'react-router-hash-link'; const axios = require('axios'); +const BACKEND_URL = 'https://projectdivar.com:4504'; + function Col(p) { return
{p.children} @@ -32,16 +33,27 @@ function Box(p) { function EditBox(p) { useEffect(()=>{ - setTimeout(()=>{document.getElementById("editBox").focus()},100) + var timer1 = setTimeout(()=>{document.getElementById("editBox").focus()},100) + return () => { + clearTimeout(timer1); + }; }) return { if (e.key==="Enter") {p.setEdit(false)} + else if (e.key==="Escape") {p.setEdit(false)} }} maxLength={p.maxlength?p.maxlength:20} onBlur={()=>{p.setEdit(false)}} value={p.value} onChange={(f)=>{f.currentTarget.value.length>0?p.setName(f.currentTarget.value):p.setName(p.originalName)}}> } function EditableBox(p) { const [edit,setEdit] = useState(false) + + useEffect(()=>{ + if (p.callback) { + p.callback() + } + },[edit]) + return <>
{setEdit(true)}}> {edit? @@ -355,9 +367,78 @@ function PopupWindow(p) { } + +function EditBackendBox(p) { + useEffect(()=>{ + var timer1 = setTimeout(()=>{document.getElementById("editBox").focus()},100) + return () => { + clearTimeout(timer1); + }; + }) + return { + if (e.key==="Enter") {p.setEdit(false);p.setUpdate(true)} + else if (e.key==="Escape") {p.setEdit(false)} + }} maxLength={p.maxlength?p.maxlength:20} onBlur={()=>{p.setEdit(false);p.setUpdate(true)}} value={p.value} onChange={(f)=>{f.currentTarget.value.length>0?p.setName(f.currentTarget.value):p.setName(p.originalName)}}> + +} + +function EditableBackendBox(p) { + const [update,setUpdate] = useState(false) + const [edit,setEdit] = useState(false) + const [value,setValue] = useState(p.children) + + useEffect(()=>{ + if (p.callback&&update) { + p.callback(value) + setUpdate(false) + } + },[update]) + + return <> +
{setEdit(true)}}> + {edit? + + :<>{value}} +
+ +} + +function TableEditor(p) { + + const [fields,setFields] = useState([]) + const [data,setData] = useState([]) + + useEffect(()=>{ + axios.get(BACKEND_URL+p.path) + .then((data)=>{ + var cols = data.data.fields + var rows = data.data.rows + + setFields(cols.filter((col)=>col.dataTypeID!==23).map((col)=>col.name)) + setData(rows) + }) + },[p.path]) + + return <> +
+ + + + + {fields.map((field,i)=>)} + + + + {data.map((dat)=>{fields.map((col,i)=>)})} + +
List of users
{field}
{console.log(value)}}>{dat[col]}
+
+ +} + function AdminPanel(p) { return
- +
Class
Class Data
@@ -386,25 +467,16 @@ function AdminPanel(p) {
Roles

- Users
- + Users
+
- More Data + -
-} - -function PageLink(p) { - return {p.children} +
+
} function App() { - useEffect(()=>{ - axios.get("https://projectdivar.com:4504/ngsplanner") - .then((data)=>{ - console.log(data.data) - }) - }) const [author,setAuthor] = useState("Dudley") const [buildName,setBuildName] = useState("Fatimah")