Skip to content

Commit

Permalink
v1.4.0
Browse files Browse the repository at this point in the history
修复 #10 #11 #12 提到的转义问题;
更新 npm 依赖;
完善多处细节,提升渲染效率;
  • Loading branch information
yb committed Jul 31, 2020
1 parent fcfc80c commit 20fdecf
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 14,755 deletions.
14,714 changes: 0 additions & 14,714 deletions package-lock.json

This file was deleted.

15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "uptime-status",
"version": "1.3.0",
"version": "1.4.0",
"private": true,
"dependencies": {
"axios": "^0.19.2",
"dayjs": "^1.8.22",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-scripts": "^3.4.0",
"react-tooltip": "^4.1.2"
"dayjs": "^1.8.31",
"htmr": "^0.8.8",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "^3.4.1",
"react-tooltip": "^4.2.7"
},
"scripts": {
"start": "react-app-rewired start",
Expand All @@ -30,7 +31,7 @@
]
},
"devDependencies": {
"react-app-rewired": "^2.1.5"
"react-app-rewired": "^2.1.6"
},
"homepage": "./"
}
9 changes: 7 additions & 2 deletions src/components/app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import React from 'react';
import React, { useEffect } from 'react';
import Header from './header';
import Footer from './footer';
import Uptime from './uptime';

const App = () => {

const { ApiKeys, SiteName } = window.Config;
window.document.title = SiteName;

useEffect(() => {
window.document.title = SiteName;
}, [SiteName]);

return (
<>
<Header />
Expand Down
6 changes: 3 additions & 3 deletions src/components/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const Header = () => {
<div className="container">
<a className="logo" href={SiteUrl}>{SiteName}</a>
<div className="navi">
{Navi.map((item, index) => (
<Link key={index} text={item.text} to={item.url} />
))}
{Navi.map((item, index) => (
<Link key={index} text={item.text} to={item.url} />
))}
</div>
</div>
</div>
Expand Down
35 changes: 18 additions & 17 deletions src/components/uptime-block.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import React from 'react';
import React, { useMemo } from 'react';
import { formatDuration, fixed } from '../utils/helper';

const UptimeBlock = (props) => {

const { data } = props;

let status = '';
let text = data.date.format('YYYY-MM-DD');

if (data.uptime >= 100) {
status = 'ok';
text += ` 可用率 ${fixed(data.uptime)}%`;
}
else if (data.uptime <= 0 && data.down.times === 0) {
status = 'none';
text += ' 无数据';
}
else {
status = 'down';
text += ` 故障 ${data.down.times} 次,累计 ${formatDuration(data.down.duration)},可用率 ${fixed(data.uptime)}%`;
}
const { status, text } = useMemo(() => {
let status = '';
let text = data.date.format('YYYY-MM-DD');
if (data.uptime >= 100) {
status = 'ok';
text += ` 可用率 ${fixed(data.uptime)}%`;
}
else if (data.uptime <= 0 && data.down.times === 0) {
status = 'none';
text += ' 无数据';
}
else {
status = 'down';
text += ` 故障 ${data.down.times} 次,累计 ${formatDuration(data.down.duration)},可用率 ${fixed(data.uptime)}%`;
}
return { status, text };
}, [data]);

return (
<i className={status} data-tip={text}></i>
Expand Down
21 changes: 14 additions & 7 deletions src/components/uptime-item.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import React, { useMemo } from 'react';
import htmr from 'htmr';
import ReactTooltip from 'react-tooltip';
import UptimeBlock from './uptime-block';
import Link from './link';
Expand All @@ -8,23 +9,29 @@ const UptimeItem = (props) => {

const { ShowLink, CountDays } = window.Config;
const { monitor } = props;
const initial = monitor.daily[monitor.daily.length - 1].date;

const status = {
ok: '正常',
down: '无法访问',
unknow: '未知'
};

const total = monitor.total.times
? `最近 ${CountDays} 天故障 ${monitor.total.times} 次,累计 ${formatDuration(monitor.total.duration)},平均可用率 ${monitor.average}%`
: `最近 ${CountDays} 天可用率 ${monitor.average}%`;
const total = useMemo(() => {
return monitor.total.times
? `最近 ${CountDays} 天故障 ${monitor.total.times} 次,累计 ${formatDuration(monitor.total.duration)},平均可用率 ${monitor.average}%`
: `最近 ${CountDays} 天可用率 ${monitor.average}%`;
}, [CountDays, monitor]);

const initial = useMemo(() => {
return monitor.daily[monitor.daily.length - 1].date;
}, [monitor]);

return (
<div className="item">
<div className="meta">
<div className="info">
<span className="name">{monitor.name}</span>
{ShowLink && <Link className="link" to={monitor.url} text={monitor.name} />}
<span className="name">{htmr(monitor.name)}</span>
{ShowLink && <Link className="link" to={monitor.url} text={htmr(monitor.name)} />}
</div>
<div className={`status ${monitor.status}`}>{status[monitor.status]}</div>
</div>
Expand Down
8 changes: 3 additions & 5 deletions src/components/uptime.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ const Uptime = (props) => {

const { CountDays } = window.Config;
const { apikey } = props;
const [ monitors, setMonitors ] = useState(null);
const [monitors, setMonitors] = useState(null);

useEffect(() => {
GetMonitors(apikey, CountDays).then(setMonitors);
}, [apikey]);
}, [apikey, CountDays]);

return monitors ? monitors.map(item => (
<UptimeItem key={item.id} monitor={item} />
)) : (
<div className="item loading"></div>
);
)) : <div className="item loading"></div>;
}

export default Uptime;

0 comments on commit 20fdecf

Please sign in to comment.