improved speed and response to change in frontend

This commit is contained in:
linoe97
2022-06-15 16:18:19 +02:00
committed by DomySh
parent 8eb3403a79
commit b699eb4269
4 changed files with 31 additions and 14 deletions

View File

@@ -74,7 +74,7 @@ function Header() {
const {srv_id} = useParams() const {srv_id} = useParams()
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const closeModal = () => {setOpen(false);} const closeModal = () => {setOpen(false);updateInfo();}
return <div id="header-page" className={style.header}> return <div id="header-page" className={style.header}>
<FloatingTooltip zIndex={0} label="Home" transition="pop" transitionDuration={200} openDelay={1000} transitionTimingFunction="ease" color="dark" position="right" > <FloatingTooltip zIndex={0} label="Home" transition="pop" transitionDuration={200} openDelay={1000} transitionTimingFunction="ease" color="dark" position="right" >

View File

@@ -5,7 +5,7 @@ import { Service } from '../../js/models';
import { MdOutlineArrowForwardIos } from "react-icons/md" import { MdOutlineArrowForwardIos } from "react-icons/md"
import style from "./ServiceRow.module.scss"; import style from "./ServiceRow.module.scss";
import YesNoModal from '../YesNoModal'; import YesNoModal from '../YesNoModal';
import { errorNotify, okNotify, pauseservice, startservice, stopservice } from '../../js/utils'; import { errorNotify, okNotify, pauseservice, startservice, stopservice, servicelist } from '../../js/utils';
//"status":"stop"/"wait"/"active"/"pause", //"status":"stop"/"wait"/"active"/"pause",
function ServiceRow({ service, onClick, additional_buttons }:{ service:Service, onClick?:()=>void, additional_buttons?:any }) { function ServiceRow({ service, onClick, additional_buttons }:{ service:Service, onClick?:()=>void, additional_buttons?:any }) {
@@ -18,6 +18,18 @@ function ServiceRow({ service, onClick, additional_buttons }:{ service:Service,
case "pause": status_color = "cyan"; break; case "pause": status_color = "cyan"; break;
} }
const [services, setServices] = useState<Service[]>([]);
const [loader, setLoader] = useState(true);
const updateInfo = async () => {
await servicelist().then(res => {
setServices(res)
}).catch(err => {
errorNotify("Home Page Auto-Update failed!", err.toString())
})
setLoader(false)
}
const [stopModal, setStopModal] = useState(false); const [stopModal, setStopModal] = useState(false);
const [buttonLoading, setButtonLoading] = useState(false) const [buttonLoading, setButtonLoading] = useState(false)
@@ -32,7 +44,8 @@ function ServiceRow({ service, onClick, additional_buttons }:{ service:Service,
}).catch(err => { }).catch(err => {
errorNotify(`An error as occurred during the stopping of the service ${service.id}`,`Error: ${err}`) errorNotify(`An error as occurred during the stopping of the service ${service.id}`,`Error: ${err}`)
}) })
setButtonLoading(false) setButtonLoading(false);
updateInfo();
} }
const startService = async () => { const startService = async () => {
@@ -47,6 +60,7 @@ function ServiceRow({ service, onClick, additional_buttons }:{ service:Service,
errorNotify(`An error as occurred during the starting of the service ${service.id}`,`Error: ${err}`) errorNotify(`An error as occurred during the starting of the service ${service.id}`,`Error: ${err}`)
}) })
setButtonLoading(false) setButtonLoading(false)
updateInfo();
} }
const pauseService = async () => { const pauseService = async () => {
@@ -61,6 +75,7 @@ function ServiceRow({ service, onClick, additional_buttons }:{ service:Service,
errorNotify(`An error as occurred during the pausing of the service ${service.id}`,`Error: ${err}`) errorNotify(`An error as occurred during the pausing of the service ${service.id}`,`Error: ${err}`)
}) })
setButtonLoading(false) setButtonLoading(false)
updateInfo();
} }
return <> return <>
@@ -146,7 +161,7 @@ function ServiceRow({ service, onClick, additional_buttons }:{ service:Service,
<YesNoModal <YesNoModal
title='Are you sure to stop this service?' title='Are you sure to stop this service?'
description={`You are going to delete the service '${service.id}', causing the firewall to stop. This will cause the shutdown of your service ⚠️!`} description={`You are going to delete the service '${service.id}', causing the firewall to stop. This will cause the shutdown of your service ⚠️!`}
onClose={()=>setStopModal(false)} onClose={()=>{setStopModal(false);updateInfo();}}
action={stopService} action={stopService}
opened={stopModal} opened={stopModal}
/> />

View File

@@ -14,7 +14,6 @@ function HomePage() {
const [loader, setLoader] = useState(true); const [loader, setLoader] = useState(true);
const navigator = useNavigate() const navigator = useNavigate()
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const closeModal = () => {setOpen(false);}
const updateInfo = async () => { const updateInfo = async () => {
await servicelist().then(res => { await servicelist().then(res => {
@@ -31,7 +30,7 @@ function HomePage() {
return () => { clearInterval(updater) } return () => { clearInterval(updater) }
}, []); }, []);
const closeModal = () => {setOpen(false);updateInfo();}
return <div id="service-list" className="center-flex-row"> return <div id="service-list" className="center-flex-row">
<LoadingOverlay visible={loader} /> <LoadingOverlay visible={loader} />

View File

@@ -24,13 +24,6 @@ function ServiceDetails() {
status:"🤔" status:"🤔"
}) })
const [regexesList, setRegexesList] = useState<RegexFilter[]>([])
const [loader, setLoader] = useState(true);
const [open, setOpen] = useState(false);
const closeModal = () => {setOpen(false);}
const navigator = useNavigate()
const updateInfo = async () => { const updateInfo = async () => {
if (!srv_id) return if (!srv_id) return
let error = false; let error = false;
@@ -50,6 +43,14 @@ function ServiceDetails() {
setLoader(false) setLoader(false)
} }
const [regexesList, setRegexesList] = useState<RegexFilter[]>([])
const [loader, setLoader] = useState(true);
const [open, setOpen] = useState(false);
const closeModal = () => {setOpen(false);updateInfo();}
const navigator = useNavigate()
useEffect(()=>{ useEffect(()=>{
updateInfo() updateInfo()
const updater = setInterval(updateInfo, update_freq) const updater = setInterval(updateInfo, update_freq)
@@ -68,6 +69,7 @@ function ServiceDetails() {
}).catch(err => { }).catch(err => {
errorNotify("An error occurred while deleting a service",`Error: ${err}`) errorNotify("An error occurred while deleting a service",`Error: ${err}`)
}) })
updateInfo();
} }
const changePort = () => { const changePort = () => {
@@ -79,6 +81,7 @@ function ServiceDetails() {
}).catch(err => { }).catch(err => {
errorNotify("An error occurred while changing the internal service port",`Error: ${err}`) errorNotify("An error occurred while changing the internal service port",`Error: ${err}`)
}) })
updateInfo();
} }
return <div> return <div>