From 45c12e33996678353335f154809d758aa0f07cfe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=BB=93=E9=BC=A0?=
<71394853+hamster1963@users.noreply.github.com>
Date: Tue, 15 Oct 2024 15:07:47 +0000
Subject: [PATCH] feat: add header router.push
---
.../(main)/ClientComponents/NetworkChart.tsx | 74 ++++++++++--------
app/[locale]/(main)/header.tsx | 12 ++-
bun.lockb | Bin 445857 -> 445857 bytes
3 files changed, 52 insertions(+), 34 deletions(-)
diff --git a/app/[locale]/(main)/ClientComponents/NetworkChart.tsx b/app/[locale]/(main)/ClientComponents/NetworkChart.tsx
index ec9a91d1f..d0b0c2bb2 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)/header.tsx b/app/[locale]/(main)/header.tsx
index 15b3e82e4..523b2d174 100644
--- a/app/[locale]/(main)/header.tsx
+++ b/app/[locale]/(main)/header.tsx
@@ -6,7 +6,9 @@ import { Separator } from "@/components/ui/separator";
import getEnv from "@/lib/env-entry";
import { DateTime } from "luxon";
import { useTranslations } from "next-intl";
+import { useLocale } from "next-intl";
import Image from "next/image";
+import { useRouter } from "next/navigation";
import React, { useEffect, useRef, useState } from "react";
function Header() {
@@ -15,10 +17,18 @@ function Header() {
const customTitle = getEnv("NEXT_PUBLIC_CustomTitle");
const customDescription = getEnv("NEXT_PUBLIC_CustomDescription");
+ const router = useRouter();
+ const locale = useLocale();
+
return (
-
+ {
+ router.push(`/${locale}/`);
+ }}
+ className="flex cursor-pointer items-center text-base font-medium"
+ >
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