diff --git a/src/components/services/item.jsx b/src/components/services/item.jsx index 6528a7b5c..056d5cfc3 100644 --- a/src/components/services/item.jsx +++ b/src/components/services/item.jsx @@ -29,8 +29,6 @@ export default function Item({ service, group }) { } }; - - return (
  • {service.ping && (
    - + Ping status
    )} diff --git a/src/components/services/ping.jsx b/src/components/services/ping.jsx index 27ea92eff..de56ce516 100644 --- a/src/components/services/ping.jsx +++ b/src/components/services/ping.jsx @@ -1,42 +1,58 @@ import { useTranslation } from "react-i18next"; import useSWR from "swr"; -export default function Ping({ group, service }) { +export default function Ping({ group, service, style }) { const { t } = useTranslation(); const { data, error } = useSWR(`/api/ping?${new URLSearchParams({ group, service }).toString()}`, { refreshInterval: 30000 }); + let textSize = "text-[8px]"; + let colorClass = "" + let backgroundClass = "bg-theme-500/10 dark:bg-theme-900/50"; + let statusTitle = "HTTP status"; + let statusText; + if (error) { - return ( -
    -
    {t("ping.error")}
    -
    - ); - } - - if (!data) { - return ( -
    -
    {t("ping.ping")}
    -
    - ); - } + colorClass = "text-rose-500" + statusText = t("ping.error") + statusTitle += " error" + } else if (!data) { + colorClass = "text-black/20 dark:text-white/40" + statusText = t("ping.ping") + statusTitle += " not available" + } else if (data.status > 403) { + colorClass = "text-rose-500/80" + statusTitle += ` ${data.status}` - const statusText = `${service}: HTTP status ${data.status}`; - - if (data.status > 403) { - return ( -
    -
    {data.status}
    -
    - ); + if (style === "basic") { + statusText = t("docker.offline") + } else if (style === "dot") { + statusText = "◉" + textSize = "text-[14px]" + backgroundClass = "" + } else { + statusText = data.status + } + } else { + const ping = t("common.ms", { value: data.latency, style: "unit", unit: "millisecond", maximumFractionDigits: 0 }) + statusTitle += ` ${data.status} (${ping})`; + colorClass = "text-emerald-500/80" + + if (style === "basic") { + statusText = t("docker.running") + } else if (style === "dot") { + statusText = "◉" + textSize = "text-[14px]" + backgroundClass = "" + } else { + statusText = ping + } } - + return ( -
    -
    {t("common.ms", { value: data.latency, style: "unit", unit: "millisecond", maximumFractionDigits: 0 })}
    +
    +
    {statusText}
    ); - }