From 413dd1de7d5674d125858035bc9d58c49285c7e3 Mon Sep 17 00:00:00 2001 From: kacarmichael Date: Thu, 29 May 2025 01:01:29 -0500 Subject: [PATCH] Integration w/Go API --- src/App.js | 17 ++------ src/components/ServiceTile.jsx | 17 ++------ src/components/ServiceTileCollection.jsx | 52 ++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 28 deletions(-) create mode 100644 src/components/ServiceTileCollection.jsx diff --git a/src/App.js b/src/App.js index dd7aeb4..bac7e24 100644 --- a/src/App.js +++ b/src/App.js @@ -1,24 +1,13 @@ import './App.css'; -import {ServiceTile} from "./components/ServiceTile"; +import {ServiceTileCollection} from "./components/ServiceTileCollection"; -const services = [ - 'git.aaronic.cc', - 'jellyfin.aaronic.cc', - 'portainer.aaronic.cc', - 'dnd.aaronic.cc' -] - -const API_URL = 'https://status.aaronic.cc'; +const API_URL = 'http://homelab01:9000'; function App() { return (

Health Check

-
- {services.map(service => ( - - ))} -
+
); } diff --git a/src/components/ServiceTile.jsx b/src/components/ServiceTile.jsx index 34aeb20..e3e8e9d 100644 --- a/src/components/ServiceTile.jsx +++ b/src/components/ServiceTile.jsx @@ -3,13 +3,6 @@ import {PropTypes} from "prop-types"; export class ServiceTile extends Component { - constructor(props) { - super(props); - this.state = { - isUp: false - }; - } - // componentDidMount() { // this.interval = setInterval(this.fetchStatus, 10000); // } @@ -25,13 +18,8 @@ export class ServiceTile extends Component { }); } - setIsUp(isUp) { - this.setState({isUp}); - } - render() { - const {isUp} = this.state; - const {service, statusCode, checkedAt} = this.props; + const {isUp,service, statusCode, checkedAt} = this.props; return (

{service}

@@ -51,5 +39,6 @@ ServiceTile.propTypes = { service: PropTypes.string, statusCode: PropTypes.number, checkedAt: PropTypes.string, - apiURL: PropTypes.string + apiURL: PropTypes.string, + isUp: PropTypes.bool } \ No newline at end of file diff --git a/src/components/ServiceTileCollection.jsx b/src/components/ServiceTileCollection.jsx new file mode 100644 index 0000000..3fccab4 --- /dev/null +++ b/src/components/ServiceTileCollection.jsx @@ -0,0 +1,52 @@ +import {ServiceTile} from "./ServiceTile"; +import {Component} from "react"; +import {PropTypes} from "prop-types"; + +export class ServiceTileCollection extends Component { + + constructor(props) { + super(props); + this.state = { + statuses: [], + loading: true, + error: null + }; + } + + fetchStatuses() { + fetch(this.props.apiURL + "/status") + .then(response => response.json()) + .then(statuses => { + this.setState({statuses, loading: false}); + }) + .catch(error => { + this.setState({error}); + }); + } + + componentDidMount() { + this.fetchStatuses(); + } + + render() { + if (this.state.loading) return

Loading...

; + if (this.state.error) return

{this.state.error}

; + + return ( +
+ {this.state.statuses.map(service => ( + + ))} +
+ ) + } +} + +ServiceTileCollection.propTypes = { + apiURL: PropTypes.string +} \ No newline at end of file