From d97eff97961c83d2339449e34acdebeb1ad4bfa1 Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 20 Oct 2024 20:12:27 +0200 Subject: [PATCH] Make apiUri changeable from frontend --- Website/App.tsx | 42 ++++-- Website/modules/Footer.tsx | 12 +- Website/modules/Header.tsx | 4 +- Website/modules/Job.tsx | 68 +++++----- Website/modules/Manga.tsx | 28 ++-- Website/modules/MonitorJobsList.tsx | 12 +- Website/modules/QueuePopUp.tsx | 18 +-- Website/modules/Settings.tsx | 128 ++++++++++++++---- .../modules/interfaces/IBackendSettings.tsx | 18 +++ .../modules/interfaces/IFrontendSettings.tsx | 30 ++++ .../modules/interfaces/ILibraryConnector.tsx | 13 ++ .../interfaces/INotificationConnector.tsx | 8 ++ package-lock.json | 65 +++++++++ package.json | 1 + 14 files changed, 339 insertions(+), 108 deletions(-) create mode 100644 Website/modules/interfaces/IBackendSettings.tsx create mode 100644 Website/modules/interfaces/ILibraryConnector.tsx create mode 100644 Website/modules/interfaces/INotificationConnector.tsx diff --git a/Website/App.tsx b/Website/App.tsx index 8d538d3..d5657ee 100644 --- a/Website/App.tsx +++ b/Website/App.tsx @@ -5,26 +5,42 @@ import Header from "./modules/Header"; import MonitorJobsList from "./modules/MonitorJobsList"; import './styles/index.css' import {Job} from "./modules/Job"; -import IFrontendSettings from "./modules/interfaces/IFrontendSettings"; +import IFrontendSettings, {FrontendSettingsWith} from "./modules/interfaces/IFrontendSettings"; +import {useCookies} from "react-cookie"; export default function App(){ + const [, setCookie] = useCookies(['apiUri', 'jobInterval']); const [connected, setConnected] = React.useState(false); const [showSearch, setShowSearch] = React.useState(false); - const [frontendSettings, setFrontendSettings] = useState({jobInterval: new Date(0,0,0,3)}); + const [frontendSettings, setFrontendSettings] = useState(FrontendSettingsWith(undefined, undefined, undefined)); + const [updateInterval, setUpdateInterval] = React.useState(); + + const apiUri = frontendSettings.apiUri; useEffect(() => { - checkConnection().then(res => setConnected(res)).catch(() => setConnected(false)); - setInterval(() => { - checkConnection().then(res => setConnected(res)).catch(() => setConnected(false)); - }, 500); - }, []); + checkConnection(apiUri).then(res => setConnected(res)).catch(() => setConnected(false)); + if(updateInterval === undefined){ + setUpdateInterval(setInterval(() => { + checkConnection(apiUri).then(res => setConnected(res)).catch(() => setConnected(false)); + }, 500)); + }else{ + clearInterval(updateInterval); + setUpdateInterval(undefined); + } + }, [frontendSettings]); + + function ChangeSettings(settings: IFrontendSettings) { + setFrontendSettings(settings); + setCookie('apiUri', settings.apiUri); + setCookie('jobInterval', settings.jobInterval); + } function CreateJob(internalId: string, jobType: string){ - Job.CreateJobDateInterval(internalId, jobType, frontendSettings.jobInterval); + Job.CreateJobDateInterval(apiUri, internalId, jobType, frontendSettings.jobInterval); } return(
-
+
{connected ? <> {showSearch @@ -33,10 +49,10 @@ export default function App(){
: <>} - setShowSearch(true)} onJobsChanged={() => console.info("jobsChanged")} connectedToBackend={connected} /> + setShowSearch(true)} onJobsChanged={() => console.info("jobsChanged")} connectedToBackend={connected} /> :

No connection to backend

} -
+
) } @@ -108,8 +124,8 @@ export function isValidUri(uri: string) : boolean{ } } -export const checkConnection = async (): Promise =>{ - return getData('http://127.0.0.1:6531/v2/Ping').then((result) => { +export const checkConnection = async (apiUri: string): Promise =>{ + return getData(`${apiUri}/v2/Ping`).then((result) => { return result != null; }).catch(() => Promise.reject()); } \ No newline at end of file diff --git a/Website/modules/Footer.tsx b/Website/modules/Footer.tsx index 235c850..da9299a 100644 --- a/Website/modules/Footer.tsx +++ b/Website/modules/Footer.tsx @@ -5,7 +5,7 @@ import Icon from '@mdi/react'; import { mdiRun, mdiCounter, mdiEyeCheck, mdiTrayFull } from '@mdi/js'; import QueuePopUp from "./QueuePopUp"; -export default function Footer({connectedToBackend} : {connectedToBackend: boolean}) { +export default function Footer({connectedToBackend, apiUri} : {connectedToBackend: boolean, apiUri: string}) { const [MonitoringJobsCount, setMonitoringJobsCount] = React.useState(0); const [AllJobsCount, setAllJobsCount] = React.useState(0); const [RunningJobsCount, setRunningJobsCount] = React.useState(0); @@ -13,10 +13,10 @@ export default function Footer({connectedToBackend} : {connectedToBackend: boole const [countUpdateInterval, setcountUpdateInterval] = React.useState(); function UpdateBackendState(){ - Job.GetMonitoringJobs().then((jobs) => setMonitoringJobsCount(jobs.length)); - Job.GetAllJobs().then((jobs) => setAllJobsCount(jobs.length)); - Job.GetRunningJobs().then((jobs) => setRunningJobsCount(jobs.length)); - Job.GetStandbyJobs().then((jobs) => setStandbyJobsCount(jobs.length)); + Job.GetMonitoringJobs(apiUri).then((jobs) => setMonitoringJobsCount(jobs.length)); + Job.GetAllJobs(apiUri).then((jobs) => setAllJobsCount(jobs.length)); + Job.GetRunningJobs(apiUri).then((jobs) => setRunningJobsCount(jobs.length)); + Job.GetStandbyJobs(apiUri).then((jobs) => setStandbyJobsCount(jobs.length)); } useEffect(() => { @@ -34,7 +34,7 @@ export default function Footer({connectedToBackend} : {connectedToBackend: boole return (