feat: store position

This commit is contained in:
hamster1963 2025-01-03 09:38:19 +08:00
parent 0b43a3943d
commit 1e2c271dc8
5 changed files with 36 additions and 8 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -27,7 +27,7 @@
"@tanstack/react-query": "^5.62.11", "@tanstack/react-query": "^5.62.11",
"@tanstack/react-query-devtools": "^5.62.11", "@tanstack/react-query-devtools": "^5.62.11",
"@tanstack/react-table": "^8.20.6", "@tanstack/react-table": "^8.20.6",
"@trivago/prettier-plugin-sort-imports": "^5.2.0", "@trivago/prettier-plugin-sort-imports": "^5.2.1",
"@types/d3-geo": "^3.1.0", "@types/d3-geo": "^3.1.0",
"@types/luxon": "^3.4.2", "@types/luxon": "^3.4.2",
"class-variance-authority": "^0.7.1", "class-variance-authority": "^0.7.1",
@ -51,7 +51,7 @@
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.17.0", "@eslint/js": "^9.17.0",
"@types/node": "^22.10.3", "@types/node": "^22.10.4",
"@types/react": "^19.0.2", "@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2", "@types/react-dom": "^19.0.2",
"@vitejs/plugin-react-swc": "^3.7.2", "@vitejs/plugin-react-swc": "^3.7.2",
@ -64,6 +64,6 @@
"tailwindcss": "^3.4.17", "tailwindcss": "^3.4.17",
"typescript": "~5.6.3", "typescript": "~5.6.3",
"typescript-eslint": "^8.19.0", "typescript-eslint": "^8.19.0",
"vite": "^6.0.6" "vite": "^6.0.7"
} }
} }

View File

@ -20,6 +20,11 @@ export default function ServerCard({ now, serverInfo }: { now: number; serverInf
serverInfo, serverInfo,
) )
const cardClick = () => {
sessionStorage.setItem("fromMainPage", "true")
navigate(`/server/${serverInfo.id}`)
}
const showFlag = true const showFlag = true
const customBackgroundImage = const customBackgroundImage =
@ -46,7 +51,7 @@ export default function ServerCard({ now, serverInfo }: { now: number; serverInf
"bg-card/70": customBackgroundImage, "bg-card/70": customBackgroundImage,
}, },
)} )}
onClick={() => navigate(`/server/${serverInfo.id}`)} onClick={cardClick}
> >
<section <section
className={cn("grid items-center gap-2", { className={cn("grid items-center gap-2", {
@ -157,7 +162,7 @@ export default function ServerCard({ now, serverInfo }: { now: number; serverInf
"bg-card/70": customBackgroundImage, "bg-card/70": customBackgroundImage,
}, },
)} )}
onClick={() => navigate(`/server/${serverInfo.id}`, { replace: true })} onClick={cardClick}
> >
<section <section
className={cn("grid items-center gap-2", { className={cn("grid items-center gap-2", {

View File

@ -20,6 +20,11 @@ export default function ServerCardInline({ now, serverInfo }: { now: number; ser
serverInfo, serverInfo,
) )
const cardClick = () => {
sessionStorage.setItem("fromMainPage", "true")
navigate(`/server/${serverInfo.id}`)
}
const showFlag = true const showFlag = true
const customBackgroundImage = const customBackgroundImage =
@ -37,7 +42,7 @@ export default function ServerCardInline({ now, serverInfo }: { now: number; ser
"bg-card/70": customBackgroundImage, "bg-card/70": customBackgroundImage,
}, },
)} )}
onClick={() => navigate(`/server/${serverInfo.id}`)} onClick={cardClick}
> >
<section className={cn("grid items-center gap-2 lg:w-36")} style={{ gridTemplateColumns: "auto auto 1fr" }}> <section className={cn("grid items-center gap-2 lg:w-36")} style={{ gridTemplateColumns: "auto auto 1fr" }}>
<span className="h-2 w-2 shrink-0 rounded-full bg-green-500 self-center"></span> <span className="h-2 w-2 shrink-0 rounded-full bg-green-500 self-center"></span>
@ -121,7 +126,7 @@ export default function ServerCardInline({ now, serverInfo }: { now: number; ser
"bg-card/70": customBackgroundImage, "bg-card/70": customBackgroundImage,
}, },
)} )}
onClick={() => navigate(`/server/${serverInfo.id}`)} onClick={cardClick}
> >
<section className={cn("grid items-center gap-2 w-40")} style={{ gridTemplateColumns: "auto auto 1fr" }}> <section className={cn("grid items-center gap-2 w-40")} style={{ gridTemplateColumns: "auto auto 1fr" }}>
<span className="h-2 w-2 shrink-0 rounded-full bg-red-500 self-center"></span> <span className="h-2 w-2 shrink-0 rounded-full bg-red-500 self-center"></span>

View File

@ -7,6 +7,7 @@ import { useWebSocketContext } from "@/hooks/use-websocket-context"
import { formatBytes } from "@/lib/format" import { formatBytes } from "@/lib/format"
import { cn, formatNezhaInfo } from "@/lib/utils" import { cn, formatNezhaInfo } from "@/lib/utils"
import { NezhaWebsocketResponse } from "@/types/nezha-api" import { NezhaWebsocketResponse } from "@/types/nezha-api"
import { useEffect, useState } from "react"
import { useTranslation } from "react-i18next" import { useTranslation } from "react-i18next"
import { useNavigate } from "react-router-dom" import { useNavigate } from "react-router-dom"
@ -16,12 +17,29 @@ export default function ServerDetailOverview({ server_id }: { server_id: string
const { t } = useTranslation() const { t } = useTranslation()
const navigate = useNavigate() const navigate = useNavigate()
const [hasHistory, setHasHistory] = useState(false)
useEffect(() => {
const previousPath = sessionStorage.getItem("fromMainPage")
if (previousPath) {
setHasHistory(true)
}
}, [])
const { lastMessage, connected } = useWebSocketContext() const { lastMessage, connected } = useWebSocketContext()
if (!connected && !lastMessage) { if (!connected && !lastMessage) {
return <ServerDetailLoading /> return <ServerDetailLoading />
} }
const linkClick = () => {
if (hasHistory) {
navigate(-1)
} else {
navigate("/")
}
}
const nezhaWsData = lastMessage ? (JSON.parse(lastMessage.data) as NezhaWebsocketResponse) : null const nezhaWsData = lastMessage ? (JSON.parse(lastMessage.data) as NezhaWebsocketResponse) : null
if (!nezhaWsData) { if (!nezhaWsData) {
@ -66,7 +84,7 @@ export default function ServerDetailOverview({ server_id }: { server_id: string
})} })}
> >
<div <div
onClick={() => navigate("/")} onClick={linkClick}
className="flex flex-none cursor-pointer font-semibold leading-none items-center break-all tracking-tight gap-1 text-xl server-name" className="flex flex-none cursor-pointer font-semibold leading-none items-center break-all tracking-tight gap-1 text-xl server-name"
> >
<BackIcon /> <BackIcon />