fix: pull data once page loaded instead of wait 5m

pull/4/head
Kairee Wu 7 years ago
parent 8ec10d4904
commit f244decff1
No known key found for this signature in database
GPG Key ID: E91BB34E2C3FDA63

@ -0,0 +1,28 @@
{
"env": {
"es6": true,
"node": true
},
"extends": [
"plugin:react/recommended",
"airbnb"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"react",
"@typescript-eslint"
],
"rules": {
}
}

12398
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -32,7 +32,7 @@
"react-app-rewired": "^2.1.5", "react-app-rewired": "^2.1.5",
"react-dom": "^16.9.0", "react-dom": "^16.9.0",
"react-intl-universal": "^2.2.2", "react-intl-universal": "^2.2.2",
"react-scripts": "^3.3.0", "react-scripts": "^3.4.1",
"typescript": "~3.7.2" "typescript": "~3.7.2"
}, },
"scripts": { "scripts": {
@ -58,20 +58,21 @@
] ]
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^8.2.0", "@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.2.0", "@commitlint/config-conventional": "^8.3.4",
"@commitlint/prompt": "^8.2.0",
"@semantic-release/changelog": "^3.0.4", "@semantic-release/changelog": "^3.0.4",
"@semantic-release/git": "^7.0.16", "@semantic-release/git": "^7.0.16",
"commitizen": "^4.0.3", "@typescript-eslint/eslint-plugin": "^2.27.0",
"husky": "^3.0.5", "@typescript-eslint/parser": "^2.27.0",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.1.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-react-hooks": "^2.5.1",
"husky": "^4.2.5",
"semantic-release": "^15.13.24" "semantic-release": "^15.13.24"
}, },
"config": {
"commitizen": {
"path": "./node_modules/@commitlint/prompt"
}
},
"husky": { "husky": {
"hooks": { "hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS" "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"

@ -1,57 +1,59 @@
import './App.css'; import "./App.css";
import intl from 'react-intl-universal'; import intl from "react-intl-universal";
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from "react";
import { Layout, Row, Col, Spin } from 'antd'; import { Layout, Row, Col, Spin } from "antd";
import ServerRow from './ServerRow'; import ServerRow from "./ServerRow";
require('intl/locale-data/jsonp/en.js'); require("intl/locale-data/jsonp/en.js");
require('intl/locale-data/jsonp/zh.js'); require("intl/locale-data/jsonp/zh.js");
const { Header, Footer, Content } = Layout; const { Header, Footer, Content } = Layout;
const App: React.FC = () => { const App: React.FC = () => {
const [serverData, setServerData] = useState({servers: [], updated: "0"}); const [serverData, setServerData] = useState({ servers: [], updated: "0" });
const [isOnline, setIsOnline] = useState(false); const [isOnline, setIsOnline] = useState(false);
useEffect(() => { useEffect(() => {
let fetchData = setInterval(() => { const fetchData = () => {
fetch('json/stats.json') fetch("json/stats.json")
.then(res => res.json()) .then((res) => res.json())
.then(data => { .then((data) => {
setServerData(data); setServerData(data);
setIsOnline(true); setIsOnline(true);
}) })
.catch(e => console.log('错误:',e)) .catch((e) => console.log("错误:", e));
}, 5000); };
fetchData();
let itv = setInterval(fetchData, 5000);
return () => { return () => {
clearInterval(fetchData); clearInterval(itv);
} };
}); }, []);
const [initDone, setInitDone] = useState(false); const [initDone, setInitDone] = useState(false);
let currentLocale = navigator.language || 'zh-CN'; let currentLocale = navigator.language || "zh-CN";
if (currentLocale === 'zh-TW' || currentLocale === 'zh-HK') { if (currentLocale === "zh-TW" || currentLocale === "zh-HK") {
currentLocale = 'zh-TW'; currentLocale = "zh-TW";
} else if (currentLocale.startsWith('zh')) { } else if (currentLocale.startsWith("zh")) {
currentLocale = 'zh-CN'; currentLocale = "zh-CN";
} else { } else {
currentLocale = 'en-US'; currentLocale = "en-US";
} }
initDone || fetch(`locales/${currentLocale}.json`) initDone ||
.then(res => res.json()) fetch(`locales/${currentLocale}.json`)
.then(data => { .then((res) => res.json())
return intl.init({ .then((data) => {
currentLocale, return intl.init({
locales: { currentLocale,
[currentLocale]: data locales: {
} [currentLocale]: data,
},
});
})
.then(() => {
setInitDone(true);
}); });
})
.then(() => {
setInitDone(true);
});
return ( return (
<div className="App"> <div className="App">
@ -59,21 +61,41 @@ const App: React.FC = () => {
<Header> <Header>
<div className="logo">ServerStatus</div> <div className="logo">ServerStatus</div>
</Header> </Header>
<Content style={{background:'#fff'}}> <Content style={{ background: "#fff" }}>
<Row type="flex" justify="center"> <Row type="flex" justify="center">
<Col xs={24} sm={23} md={23} lg={22} xl={20} xxl={16}> <Col xs={24} sm={23} md={23} lg={22} xl={20} xxl={16}>
{initDone ? (<Spin size="large" spinning={!isOnline} tip="Loading..."> {initDone ? (
<ServerRow {...serverData} /> <Spin size="large" spinning={!isOnline} tip="Loading...">
</Spin>) : (<div />)} <ServerRow {...serverData} />
</Spin>
) : (
<div />
)}
</Col> </Col>
</Row> </Row>
</Content> </Content>
<Footer className="footer"> <Footer className="footer">
<a href="https://github.com/krwu/ServerStatus-web" rel="external noopener">WebUI</a> for <a href="https://github.com/BotoX/ServerStatus/" rel="external noopener">ServerStatus</a>, made by <a href="https://www.ofcss.com/" rel="external noopener">Kairee</a> <a
href="https://github.com/krwu/ServerStatus-web"
rel="external noopener"
>
WebUI
</a>{" "}
for{" "}
<a
href="https://github.com/BotoX/ServerStatus/"
rel="external noopener"
>
ServerStatus
</a>
, made by{" "}
<a href="https://www.ofcss.com/" rel="external noopener">
Kairee
</a>
</Footer> </Footer>
</Layout> </Layout>
</div> </div>
); );
} };
export default App; export default App;

Loading…
Cancel
Save