mirror of
https://github.com/woodchen-ink/nezha-dash-v1.git
synced 2025-07-18 17:41:56 +08:00
feat: online counter
This commit is contained in:
parent
b2998752a6
commit
bee3dccc42
@ -1,7 +1,9 @@
|
|||||||
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 { useWebSocketContext } from "@/hooks/use-websocket-context"
|
||||||
import { fetchLoginUser, fetchSetting } from "@/lib/nezha-api"
|
import { fetchLoginUser, fetchSetting } from "@/lib/nezha-api"
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
import { useQuery } from "@tanstack/react-query"
|
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"
|
||||||
@ -9,6 +11,7 @@ import { useTranslation } from "react-i18next"
|
|||||||
import { useNavigate } from "react-router-dom"
|
import { useNavigate } from "react-router-dom"
|
||||||
|
|
||||||
import { LanguageSwitcher } from "./LanguageSwitcher"
|
import { LanguageSwitcher } from "./LanguageSwitcher"
|
||||||
|
import { Button } from "./ui/button"
|
||||||
|
|
||||||
function Header() {
|
function Header() {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@ -21,6 +24,10 @@ function Header() {
|
|||||||
refetchOnWindowFocus: true,
|
refetchOnWindowFocus: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const { lastMessage, connected } = useWebSocketContext()
|
||||||
|
|
||||||
|
const onlineCount = connected ? (lastMessage ? JSON.parse(lastMessage.data).online || 0 : 0) : "..."
|
||||||
|
|
||||||
const siteName = settingData?.data?.site_name
|
const siteName = settingData?.data?.site_name
|
||||||
|
|
||||||
// @ts-expect-error CustomLogo is a global variable
|
// @ts-expect-error CustomLogo is a global variable
|
||||||
@ -68,6 +75,15 @@ function Header() {
|
|||||||
<DashboardLink />
|
<DashboardLink />
|
||||||
<LanguageSwitcher />
|
<LanguageSwitcher />
|
||||||
<ModeToggle />
|
<ModeToggle />
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
className={cn("hover:bg-white dark:hover:bg-black cursor-default rounded-full flex items-center px-[9px] bg-white dark:bg-black")}
|
||||||
|
>
|
||||||
|
{connected ? onlineCount : "..."}
|
||||||
|
<p className="text-muted-foreground">{t("online")}</p>
|
||||||
|
<span className="h-2 w-2 rounded-full bg-green-500"></span>
|
||||||
|
</Button>
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
<div className="w-full flex justify-end sm:hidden mt-1">
|
<div className="w-full flex justify-end sm:hidden mt-1">
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
"overview": "Overview",
|
"overview": "Overview",
|
||||||
"dashboard": "Dashboard",
|
"dashboard": "Dashboard",
|
||||||
"login": "Login",
|
"login": "Login",
|
||||||
|
"online": "Online",
|
||||||
"whereTheTimeIs": "Where the time is",
|
"whereTheTimeIs": "Where the time is",
|
||||||
"info": {
|
"info": {
|
||||||
"websocketConnecting": "WebSocket connecting",
|
"websocketConnecting": "WebSocket connecting",
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
"overview": "概览",
|
"overview": "概览",
|
||||||
"dashboard": "管理后台",
|
"dashboard": "管理后台",
|
||||||
"login": "登录",
|
"login": "登录",
|
||||||
|
"online": "在线",
|
||||||
"whereTheTimeIs": "当前时间",
|
"whereTheTimeIs": "当前时间",
|
||||||
"info": {
|
"info": {
|
||||||
"websocketConnecting": "WebSocket 连接中",
|
"websocketConnecting": "WebSocket 连接中",
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
"overview": "概覽",
|
"overview": "概覽",
|
||||||
"dashboard": "管理後台",
|
"dashboard": "管理後台",
|
||||||
"login": "登錄",
|
"login": "登錄",
|
||||||
|
"online": "在線",
|
||||||
"whereTheTimeIs": "目前時間",
|
"whereTheTimeIs": "目前時間",
|
||||||
"info": {
|
"info": {
|
||||||
"websocketConnecting": "WebSocket 連接中",
|
"websocketConnecting": "WebSocket 連接中",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user