Skip to content

Commit

Permalink
fix: chart error state
Browse files Browse the repository at this point in the history
  • Loading branch information
hamster1963 committed Oct 10, 2024
1 parent bd14f46 commit 67badd2
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 26 deletions.
16 changes: 12 additions & 4 deletions app/[locale]/(main)/ClientComponents/NetworkChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,20 @@ export function NetworkChartClient({ server_id }: { server_id: number }) {
},
);

if (error)
if (error) {
return (
<div className="flex flex-col items-center justify-center">
<p className="text-sm font-medium opacity-40">{error.message}</p>
</div>
<>
<div className="flex flex-col items-center justify-center">
<p className="text-sm font-medium opacity-40">{error.message}</p>
<p className="text-sm font-medium opacity-40">
{t("chart_fetch_error_message")}
</p>
</div>
<NetworkChartLoading />
</>
);
}

if (!data) return <NetworkChartLoading />;

function transformData(data: NezhaAPIMonitor[]) {
Expand Down
12 changes: 11 additions & 1 deletion app/[locale]/(main)/ClientComponents/NetworkChartLoading.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import { BackIcon } from "@/components/Icon";
import { Loader } from "@/components/loading/Loader";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { useLocale } from "next-intl";
import { useRouter } from "next/navigation";

export default function NetworkChartLoading() {
const router = useRouter();
const locale = useLocale();

return (
<Card>
<CardHeader className="flex flex-col items-stretch space-y-0 border-b p-0 sm:flex-row">
<div className="flex flex-1 flex-col justify-center gap-1 px-6 py-5">
<CardTitle className="flex items-center gap-0.5 text-xl">
<CardTitle
onClick={() => {
router.push(`/${locale}/`);
}}
className="flex items-center cursor-pointer gap-0.5 text-xl"
>
<BackIcon />
<div className="aspect-auto h-[20px] w-24 bg-muted"></div>
</CardTitle>
Expand Down
9 changes: 4 additions & 5 deletions app/[locale]/(main)/ClientComponents/ServerOverviewClient.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
"use client";

import { useTranslations } from "next-intl";
import Image from "next/image";
import useSWR from "swr";

import { ServerApi } from "@/app/[locale]/types/nezha-api";
import { Loader } from "@/components/loading/Loader";
import { Card, CardContent } from "@/components/ui/card";
import getEnv from "@/lib/env-entry";
import { formatBytes, nezhaFetcher } from "@/lib/utils";
import blogMan from "@/public/blog-man.webp";
import { ServerApi } from "@/app/[locale]/types/nezha-api";
import { useTranslations } from "next-intl";
import Image from "next/image";
import useSWR from "swr";

export default function ServerOverviewClient() {
const t = useTranslations("ServerOverviewClient");
Expand Down
7 changes: 3 additions & 4 deletions components/ServerCard.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { NezhaAPISafe } from "@/app/[locale]/types/nezha-api";
import ServerCardPopover from "@/components/ServerCardPopover";
import ServerFlag from "@/components/ServerFlag";
import ServerUsageBar from "@/components/ServerUsageBar";
import { Card } from "@/components/ui/card";
import {
Expand All @@ -10,10 +13,6 @@ import { useLocale, useTranslations } from "next-intl";
import { env } from "next-runtime-env";
import { useRouter } from "next/navigation";

import { NezhaAPISafe } from "@/app/[locale]/types/nezha-api";
import ServerCardPopover from "@/components/ServerCardPopover";
import ServerFlag from "@/components/ServerFlag";

export default function ServerCard({
serverInfo,
}: {
Expand Down
3 changes: 1 addition & 2 deletions components/ServerCardPopover.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { NezhaAPISafe } from "@/app/[locale]/types/nezha-api";
import { cn, formatBytes } from "@/lib/utils";
import { useTranslations } from "next-intl";

import { NezhaAPISafe } from "@/app/[locale]/types/nezha-api";

export function ServerCardPopoverCard({
className,
title,
Expand Down
3 changes: 1 addition & 2 deletions components/ServerList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";

import ServerListClient from "@/app/[locale]/(main)/ClientComponents/ServerListClient";
import React from "react";

export default async function ServerList() {
return <ServerListClient />;
Expand Down
3 changes: 1 addition & 2 deletions lib/serverFetch.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"use server";

import { unstable_noStore as noStore } from "next/cache";

import { NezhaAPI, ServerApi } from "@/app/[locale]/types/nezha-api";
import { MakeOptional } from "@/app/[locale]/types/utils";
import getEnv from "@/lib/env-entry";
import { unstable_noStore as noStore } from "next/cache";

export async function GetNezhaData() {
noStore();
Expand Down
3 changes: 1 addition & 2 deletions lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { NezhaAPISafe } from "@/app/[locale]/types/nezha-api";
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";

import { NezhaAPISafe } from "@/app/[locale]/types/nezha-api";

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
Expand Down
3 changes: 2 additions & 1 deletion messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"Offline": "Offline"
},
"NetworkChartClient": {
"avg_delay": "Latency"
"avg_delay": "Latency",
"chart_fetch_error_message": "Failed to fetch network data, please check if the server monitoring is enabled"
},
"NetworkChart": {
"ServerMonitorCount": "Services"
Expand Down
3 changes: 2 additions & 1 deletion messages/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"Offline": "オフライン"
},
"NetworkChartClient": {
"avg_delay": "遅延"
"avg_delay": "遅延",
"chart_fetch_error_message": "ネットワークデータの取得に失敗しました。サーバーの監視が有効になっているかどうかを確認してください"
},
"NetworkChart": {
"ServerMonitorCount": "サービス"
Expand Down
3 changes: 2 additions & 1 deletion messages/zh-t.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"Offline": "離線"
},
"NetworkChartClient": {
"avg_delay": "延遲"
"avg_delay": "延遲",
"chart_fetch_error_message": "獲取網絡數據失敗,請檢查是否開啟服務端監控"
},
"NetworkChart": {
"ServerMonitorCount": "個監測服務"
Expand Down
3 changes: 2 additions & 1 deletion messages/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"Offline": "离线"
},
"NetworkChartClient": {
"avg_delay": "延迟"
"avg_delay": "延迟",
"chart_fetch_error_message": "获取网络数据失败,请检查是否开启服务端监控"
},
"NetworkChart": {
"ServerMonitorCount": "个监控服务"
Expand Down

0 comments on commit 67badd2

Please sign in to comment.