mirror of
https://github.com/woodchen-ink/nezha-dash-v1.git
synced 2025-07-18 17:41:56 +08:00
feat: dashboard link
This commit is contained in:
parent
5364d5cdb5
commit
97087fe67d
@ -1,9 +1,9 @@
|
|||||||
"use client";
|
|
||||||
|
|
||||||
// import { LanguageSwitcher } from "@/components/LanguageSwitcher";
|
// import { LanguageSwitcher } from "@/components/LanguageSwitcher";
|
||||||
import { ModeToggle } from "@/components/ThemeSwitcher";
|
import { ModeToggle } from "@/components/ThemeSwitcher";
|
||||||
import { Separator } from "@/components/ui/separator";
|
import { Separator } from "@/components/ui/separator";
|
||||||
import { Skeleton } from "@/components/ui/skeleton";
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
|
import { fetchLoginUser } from "@/lib/nezha-api";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { DateTime } from "luxon";
|
import { DateTime } from "luxon";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
@ -31,6 +31,7 @@ function Header() {
|
|||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
<section className="flex items-center gap-2">
|
<section className="flex items-center gap-2">
|
||||||
|
<DashboardLink />
|
||||||
{/* <LanguageSwitcher /> */}
|
{/* <LanguageSwitcher /> */}
|
||||||
<ModeToggle />
|
<ModeToggle />
|
||||||
</section>
|
</section>
|
||||||
@ -40,6 +41,30 @@ function Header() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function DashboardLink() {
|
||||||
|
const { data: userData } = useQuery({
|
||||||
|
queryKey: ["login-user"],
|
||||||
|
queryFn: () => fetchLoginUser(),
|
||||||
|
refetchOnMount: true,
|
||||||
|
refetchOnWindowFocus: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!userData?.data?.id) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<a
|
||||||
|
href={"/dashboard"}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="flex items-center gap-1 text-sm font-medium opacity-50 transition-opacity hover:opacity-100"
|
||||||
|
>
|
||||||
|
Dashboard
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// https://github.com/streamich/react-use/blob/master/src/useInterval.ts
|
// https://github.com/streamich/react-use/blob/master/src/useInterval.ts
|
||||||
const useInterval = (callback: () => void, delay: number | null) => {
|
const useInterval = (callback: () => void, delay: number | null) => {
|
||||||
const savedCallback = useRef<() => void>(() => {});
|
const savedCallback = useRef<() => void>(() => {});
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
"use client";
|
|
||||||
|
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
import { ChartConfig, ChartContainer } from "@/components/ui/chart";
|
import { ChartConfig, ChartContainer } from "@/components/ui/chart";
|
||||||
import { formatNezhaInfo, formatRelativeTime } from "@/lib/utils";
|
import { formatNezhaInfo, formatRelativeTime } from "@/lib/utils";
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
"use client";
|
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
"use client";
|
|
||||||
|
|
||||||
import { LazyMotion } from "framer-motion";
|
import { LazyMotion } from "framer-motion";
|
||||||
|
|
||||||
const loadFeatures = () =>
|
const loadFeatures = () =>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { ServerGroupResponse } from "@/types/nezha-api";
|
import { LoginUserResponse, ServerGroupResponse } from "@/types/nezha-api";
|
||||||
|
|
||||||
export const fetchServerGroup = async (): Promise<ServerGroupResponse> => {
|
export const fetchServerGroup = async (): Promise<ServerGroupResponse> => {
|
||||||
const response = await fetch("/api/v1/server-group");
|
const response = await fetch("/api/v1/server-group");
|
||||||
@ -8,3 +8,12 @@ export const fetchServerGroup = async (): Promise<ServerGroupResponse> => {
|
|||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const fetchLoginUser = async (): Promise<LoginUserResponse> => {
|
||||||
|
const response = await fetch("/api/v1/profile");
|
||||||
|
const data = await response.json();
|
||||||
|
if (data.error) {
|
||||||
|
throw new Error(data.error);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
@ -58,3 +58,14 @@ export interface ServerGroup {
|
|||||||
};
|
};
|
||||||
servers: number[];
|
servers: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface LoginUserResponse {
|
||||||
|
success: boolean;
|
||||||
|
data: {
|
||||||
|
id: number;
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user