const { useEffect, useRef, useState } = React
const useLatest = val => {
const ref = useRef(val)
ref.current = val
return ref
}
const sleep = async ms => new Promise(res => setTimeout(res, ms))
const cOk = { background: "lime", color: "black" }
const cWarn = { background: "yellow", color: "black", fontWeight: "bold" }
const cErr = { background: "red", color: "white", fontWeight: "bold" }
// 1 day
const isGone = ts =>
Date.now() - new Date(ts).getTime() > 1000 * 3600 * 24
const dateFmt = ts => {
const date = new Date(ts)
const pref = date.toLocaleString("ja")
const ds = (Date.now() - date.getTime()) / 1000
const d = Math.trunc(ds / 3600 / 24)
if(d) return `${pref} (${d}日前)`
const h = Math.trunc((ds - 3600 * 24 * d) / 3600)
if(h) return `${pref} (${h}時間前)`
const m = Math.trunc((ds - 3600 * (24 * d + h)) / 60)
if(m) return `${pref} (${m}分前)`
const s = Math.trunc(ds)
return `${pref} (さっき)`
}
const Layout = ({ children }) => (
<>
YamaD Status
Name | Status | Load Average | CPU | Updated |
---|---|---|---|---|
{nick} | {gone || status} | [{lav .map(i => String(Math.round(i * 1000) / 1000)) .map(s => { const [before, after = ""] = s.split(".") if(before.length >= 3) return before return `${before}.${(after + "000").slice(0, 3)}` }) .join(",") }] | {cores}C{threads}T | {dateFmt(ts)} |