|
1 | 1 | import React, { useEffect, useState } from "react"; |
2 | | -import logo from './commit-logo.png'; |
3 | | -import './App.css'; |
| 2 | +import logo from "./commit-logo.png"; |
| 3 | +import "./App.css"; |
4 | 4 |
|
5 | | -import './components/Info' |
6 | | -import InfoPanel from './components/Info'; |
| 5 | +import "./components/Info"; |
| 6 | +import InfoPanel from "./components/Info"; |
7 | 7 |
|
8 | 8 | // Set config based on the environment variable the build was run under. |
9 | | -let config = {} |
10 | | -if (process.env.NODE_ENV === 'production') { |
11 | | - config = require('./config/production.json') |
12 | | -} else if (process.env.NODE_ENV === 'staging') { |
13 | | - config = require('./config/staging.json') |
| 9 | +let config = {}; |
| 10 | +if (process.env.NODE_ENV === "production") { |
| 11 | + config = require("./config/production.json"); |
| 12 | +} else if (process.env.NODE_ENV === "staging") { |
| 13 | + config = require("./config/staging.json"); |
14 | 14 | } else { |
15 | | - config = require('./config/development.json') |
| 15 | + config = require("./config/development.json"); |
16 | 16 | } |
17 | 17 |
|
18 | 18 | function App() { |
19 | 19 | const [data, setData] = useState({ |
20 | 20 | info: {}, |
21 | | - status: "Checking...", |
22 | | - error: null |
| 21 | + error: null, |
23 | 22 | }); |
24 | 23 |
|
| 24 | + const [status, setStatus] = useState({ |
| 25 | + code: "Checking...", |
| 26 | + }) |
| 27 | + |
25 | 28 | useEffect(() => { |
26 | | - fetch(`https://${config.backendURL}/status/about`) |
27 | | - .then(result => setData({ |
28 | | - info: result.data, |
29 | | - status: result.status |
30 | | - })) |
31 | | - .catch(error => setData({ |
32 | | - info: {}, |
33 | | - status: "Failed.", |
34 | | - error: error.message |
35 | | - })) |
| 29 | + fetch(`${config.backendURL}/status/about`) |
| 30 | + .then(result => { |
| 31 | + setStatus({ |
| 32 | + code: result.status, |
| 33 | + }) |
| 34 | + return result.json() |
| 35 | + }) |
| 36 | + .then(data => { |
| 37 | + setData({ |
| 38 | + info: data, |
| 39 | + error: null |
| 40 | + }) |
| 41 | + }) |
| 42 | + .catch(error => { |
| 43 | + setData({ |
| 44 | + info: {}, |
| 45 | + error: error |
| 46 | + }) |
| 47 | + }); |
36 | 48 | }, []); |
37 | 49 |
|
38 | 50 | return ( |
39 | 51 | <div className="App"> |
40 | 52 | <header className="App-header"> |
41 | 53 | <img src={logo} className="App-logo" alt="logo" /> |
42 | 54 | <h1>zero</h1> |
43 | | - <InfoPanel data={data} config={config} /> |
| 55 | + <InfoPanel data={data} status={status} config={config} /> |
44 | 56 | </header> |
45 | 57 | </div> |
46 | 58 | ); |
|
0 commit comments