From fe20952e7b7a8f6acde4bf1791eecda53b342372 Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Thu, 17 Oct 2024 23:45:18 +0800 Subject: [PATCH] feat: add detail page --- .../(main)/ClientComponents/NetworkChart.tsx | 74 ++++++++++-------- app/[locale]/(main)/detail/[id]/page.tsx | 7 ++ bun.lockb | Bin 445857 -> 445857 bytes components/ServerCard.tsx | 52 ++++++------ 4 files changed, 76 insertions(+), 57 deletions(-) create mode 100644 app/[locale]/(main)/detail/[id]/page.tsx diff --git a/app/[locale]/(main)/ClientComponents/NetworkChart.tsx b/app/[locale]/(main)/ClientComponents/NetworkChart.tsx index ec9a91d..d0b0c2b 100644 --- a/app/[locale]/(main)/ClientComponents/NetworkChart.tsx +++ b/app/[locale]/(main)/ClientComponents/NetworkChart.tsx @@ -28,9 +28,9 @@ import { useLocale } from "next-intl"; import { useTranslations } from "next-intl"; import { useRouter } from "next/navigation"; import * as React from "react"; +import { useCallback, useMemo } from "react"; import { CartesianGrid, Line, LineChart, XAxis, YAxis } from "recharts"; import useSWR from "swr"; -import { useMemo, useCallback } from 'react'; interface ResultItem { created_at: number; @@ -64,7 +64,6 @@ export function NetworkChartClient({ server_id }: { server_id: number }) { if (!data) return ; - const transformedData = transformData(data); const formattedData = formatData(data); @@ -109,32 +108,40 @@ export const NetworkChart = React.memo(function NetworkChart({ const [activeChart, setActiveChart] = React.useState(defaultChart); - const handleButtonClick = useCallback((chart: string) => { - setActiveChart(prev => prev === chart ? defaultChart : chart); - }, [defaultChart]); + const handleButtonClick = useCallback( + (chart: string) => { + setActiveChart((prev) => (prev === chart ? defaultChart : chart)); + }, + [defaultChart], + ); - const getColorByIndex = useCallback((chart: string) => { - const index = chartDataKey.indexOf(chart); - return `hsl(var(--chart-${(index % 10) + 1}))`; - }, [chartDataKey]); + const getColorByIndex = useCallback( + (chart: string) => { + const index = chartDataKey.indexOf(chart); + return `hsl(var(--chart-${(index % 10) + 1}))`; + }, + [chartDataKey], + ); - const chartButtons = useMemo(() => ( - chartDataKey.map((key) => ( - - )) - ), [chartDataKey, activeChart, chartData, handleButtonClick]); + const chartButtons = useMemo( + () => + chartDataKey.map((key) => ( + + )), + [chartDataKey, activeChart, chartData, handleButtonClick], + ); const chartLines = useMemo(() => { if (activeChart !== defaultChart) { @@ -180,9 +187,7 @@ export const NetworkChart = React.memo(function NetworkChart({ {chartDataKey.length} {t("ServerMonitorCount")} -
- {chartButtons} -
+
{chartButtons}
@@ -235,7 +244,6 @@ export const NetworkChart = React.memo(function NetworkChart({ ); }); - const transformData = (data: NezhaAPIMonitor[]) => { const monitorData: ServerMonitorChart = {}; @@ -255,7 +263,7 @@ const transformData = (data: NezhaAPIMonitor[]) => { }); return monitorData; -} +}; const formatData = (rawData: NezhaAPIMonitor[]) => { const result: { [time: number]: ResultItem } = {}; @@ -282,4 +290,4 @@ const formatData = (rawData: NezhaAPIMonitor[]) => { }); return Object.values(result).sort((a, b) => a.created_at - b.created_at); -}; \ No newline at end of file +}; diff --git a/app/[locale]/(main)/detail/[id]/page.tsx b/app/[locale]/(main)/detail/[id]/page.tsx new file mode 100644 index 0000000..47d32f6 --- /dev/null +++ b/app/[locale]/(main)/detail/[id]/page.tsx @@ -0,0 +1,7 @@ +export default function Page({ params }: { params: { id: string } }) { + return ( +
+ {params.id} +
+ ); +} diff --git a/bun.lockb b/bun.lockb index 91e32b6d4305dca58f280f9c8e875e7dd42a748f..0c25b049f2ee017ee864de29a45eccb04b45d695 100755 GIT binary patch delta 41 vcmZ2DTYBMa>4p}@7N!>FEiBXg7!9{i_hb3Q#Awmp703d_tlPT+*~DuAI=l{4 delta 41 vcmZ2DTYBMa>4p}@7N!>FEiBXg7!9^h_hb3Q#Ax2$703d_tlPT+*~DuAI+hMn diff --git a/components/ServerCard.tsx b/components/ServerCard.tsx index 36a40dc..7ff341e 100644 --- a/components/ServerCard.tsx +++ b/components/ServerCard.tsx @@ -36,35 +36,39 @@ export default function ServerCard({ "flex flex-col items-center justify-start gap-3 p-3 md:px-5 lg:flex-row" } > - + {/* -
-
- {showFlag ? : null} -
-

- {name} -

- -
+
-
+
*/} +
{ + router.push(`/${locale}/detail/${id}`); + }} + > +
+ {showFlag ? : null} +
+

+ {name} +

+ +
{ router.push(`/${locale}/${id}`);