|
@@ -1,33 +1,32 @@
|
|
-import React from "react";
|
|
|
|
-
|
|
|
|
|
|
+import React, { useState, useEffect } from "react";
|
|
import { getStatus } from "../../services/ggsh.service";
|
|
import { getStatus } from "../../services/ggsh.service";
|
|
|
|
|
|
-class ApiInfo extends React.Component {
|
|
|
|
- constructor(props) {
|
|
|
|
- super(props);
|
|
|
|
- this.state = {
|
|
|
|
- loading: true,
|
|
|
|
- version: null,
|
|
|
|
- status: null,
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- async componentDidMount() {
|
|
|
|
- const { version, status } = await getStatus();
|
|
|
|
- this.setState({loading: false, version, status});
|
|
|
|
- }
|
|
|
|
|
|
+const ApiInfo = () => {
|
|
|
|
+ const [{ loading, version, status }, setState] = useState({ loading: true, version: null, status: null });
|
|
|
|
|
|
- render() {
|
|
|
|
- if (this.state.loading) {
|
|
|
|
- return <p>Connecting to back-end...</p>
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ if (version && status) {
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
- if (this.state.status !== "healthy") {
|
|
|
|
- return <p>Unable to communicate with API server! Error: {this.state.status}</p>
|
|
|
|
|
|
+ const fetchStatus = async () => {
|
|
|
|
+ const { version, status } = await getStatus();
|
|
|
|
+ setState({ loading: false, version, status });
|
|
}
|
|
}
|
|
|
|
|
|
- return <p>API Version: {this.state.version}</p>
|
|
|
|
|
|
+ fetchStatus();
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (loading) {
|
|
|
|
+ return <p>Connecting to back-end...</p>
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (status !== "healthy") {
|
|
|
|
+ return <p>Unable to communicate with API server! Error: {status}</p>
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ return <p>API Version: {version}</p>
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
export default ApiInfo;
|
|
export default ApiInfo;
|