diff --git a/app/[locale]/(main)/ClientComponents/NetworkChart.tsx b/app/[locale]/(main)/ClientComponents/NetworkChart.tsx index d0b0c2bb2..8a69eccf2 100644 --- a/app/[locale]/(main)/ClientComponents/NetworkChart.tsx +++ b/app/[locale]/(main)/ClientComponents/NetworkChart.tsx @@ -37,7 +37,13 @@ interface ResultItem { [key: string]: number | null; } -export function NetworkChartClient({ server_id }: { server_id: number }) { +export function NetworkChartClient({ + server_id, + show, +}: { + server_id: number; + show: boolean; +}) { const t = useTranslations("NetworkChartClient"); const { data, error } = useSWR( `/api/monitor?server_id=${server_id}`, @@ -45,6 +51,7 @@ export function NetworkChartClient({ server_id }: { server_id: number }) { { refreshInterval: Number(getEnv("NEXT_PUBLIC_NezhaFetchInterval")) || 15000, + isPaused: () => !show, }, ); diff --git a/app/[locale]/(main)/ClientComponents/ServerDetailChartClient.tsx b/app/[locale]/(main)/ClientComponents/ServerDetailChartClient.tsx index 4edf4b7e4..9e05bcb01 100644 --- a/app/[locale]/(main)/ClientComponents/ServerDetailChartClient.tsx +++ b/app/[locale]/(main)/ClientComponents/ServerDetailChartClient.tsx @@ -55,8 +55,10 @@ type connectChartData = { export default function ServerDetailChartClient({ server_id, + show, }: { server_id: number; + show: boolean; }) { const t = useTranslations("ServerDetailChartClient"); @@ -65,6 +67,7 @@ export default function ServerDetailChartClient({ nezhaFetcher, { refreshInterval: Number(getEnv("NEXT_PUBLIC_NezhaFetchInterval")) || 5000, + isPaused: () => !show, }, ); diff --git a/app/[locale]/(main)/[id]/page.tsx b/app/[locale]/(main)/[id]/page.tsx new file mode 100644 index 000000000..8695fb341 --- /dev/null +++ b/app/[locale]/(main)/[id]/page.tsx @@ -0,0 +1,38 @@ +"use client"; + +import { NetworkChartClient } from "@/app/[locale]/(main)/ClientComponents/NetworkChart"; +import ServerDetailChartClient from "@/app/[locale]/(main)/ClientComponents/ServerDetailChartClient"; +import ServerDetailClient from "@/app/[locale]/(main)/ClientComponents/ServerDetailClient"; +import TabSwitch from "@/components/TabSwitch"; +import { Separator } from "@/components/ui/separator"; +import { useTranslations } from "next-intl"; +import { useState } from "react"; + +export default function Page({ params }: { params: { id: string } }) { + const t = useTranslations("TabSwitch"); + + const tabs = [t("Detail"), t("Network")]; + const [currentTab, setCurrentTab] = useState(tabs[0]); + return ( +
+ +
+ +
+ +
+ +
+ {currentTab === tabs[0] && ( + + )} + {currentTab === tabs[1] && ( + + )} +
+ ); +} diff --git a/app/[locale]/(main)/detail/[id]/page.tsx b/app/[locale]/(main)/detail/[id]/page.tsx deleted file mode 100644 index de69a5dc4..000000000 --- a/app/[locale]/(main)/detail/[id]/page.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import ServerDetailChartClient from "@/app/[locale]/(main)/ClientComponents/ServerDetailChartClient"; -import ServerDetailClient from "@/app/[locale]/(main)/ClientComponents/ServerDetailClient"; -import { Separator } from "@/components/ui/separator"; - -export default function Page({ params }: { params: { id: string } }) { - return ( -
- - - -
- ); -} diff --git a/app/[locale]/(main)/network/[id]/page.tsx b/app/[locale]/(main)/network/[id]/page.tsx deleted file mode 100644 index b46b6af1c..000000000 --- a/app/[locale]/(main)/network/[id]/page.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import { NetworkChartClient } from "@/app/[locale]/(main)/ClientComponents/NetworkChart"; - -export default function Page({ params }: { params: { id: string } }) { - return ( -
- -
- ); -} diff --git a/components/ServerCard.tsx b/components/ServerCard.tsx index 0e15ebfea..ff07e5c2c 100644 --- a/components/ServerCard.tsx +++ b/components/ServerCard.tsx @@ -33,15 +33,15 @@ export default function ServerCard({ return online ? ( { + router.push(`/${locale}/${id}`); + }} >
{ - router.push(`/${locale}/detail/${id}`); - }} >
-
{ - router.push(`/${locale}/network/${id}`); - }} - className="flex flex-col gap-2 cursor-pointer" - > +

{t("CPU")}

diff --git a/components/TabSwitch.tsx b/components/TabSwitch.tsx new file mode 100644 index 000000000..d2913ad5b --- /dev/null +++ b/components/TabSwitch.tsx @@ -0,0 +1,48 @@ +"use client"; + +import { cn } from "@/lib/utils"; +import { motion } from "framer-motion"; +import React, { useState } from "react"; + +export default function TabSwitch({ + tabs, + currentTab, + setCurrentTab, +}: { + tabs: string[]; + currentTab: string; + setCurrentTab: (tab: string) => void; +}) { + return ( +
+
+ {tabs.map((tab: string) => ( +
setCurrentTab(tab)} + className={cn( + "relative cursor-pointer rounded-3xl px-2.5 py-[8px] text-[13px] font-[600] transition-all duration-500", + currentTab === tab + ? "text-black dark:text-white" + : "text-stone-400 dark:text-stone-500", + )} + > + {currentTab === tab && ( + + )} +
+

{tab}

+
+
+ ))} +
+
+ ); +} diff --git a/messages/en.json b/messages/en.json index fbfb6dac1..0fe32f9ad 100644 --- a/messages/en.json +++ b/messages/en.json @@ -19,6 +19,10 @@ "Download": "Download", "Offline": "Offline" }, + "TabSwitch": { + "Detail": "Detail", + "Network": "Network" + }, "ServerCardPopover": { "System": "System", "CPU": "CPU", diff --git a/messages/ja.json b/messages/ja.json index bf29650d3..02aef4390 100644 --- a/messages/ja.json +++ b/messages/ja.json @@ -19,6 +19,10 @@ "Download": "Download", "Offline": "Offline" }, + "TabSwitch": { + "Detail": "詳細", + "Network": "ネットワーク" + }, "ServerCardPopover": { "System": "システム", "CPU": "CPU", diff --git a/messages/zh-t.json b/messages/zh-t.json index 5e6d75ba9..ffead2aa3 100644 --- a/messages/zh-t.json +++ b/messages/zh-t.json @@ -19,6 +19,10 @@ "Download": "下載", "Offline": "離線" }, + "TabSwitch": { + "Detail": "詳細", + "Network": "網路" + }, "ServerCardPopover": { "System": "系統", "CPU": "CPU", diff --git a/messages/zh.json b/messages/zh.json index 01523e5bd..ed853f0f8 100644 --- a/messages/zh.json +++ b/messages/zh.json @@ -19,6 +19,10 @@ "Download": "下载", "Offline": "离线" }, + "TabSwitch": { + "Detail": "详情", + "Network": "网络" + }, "ServerCardPopover": { "System": "系统", "CPU": "CPU",