Added online status to sidebar

This commit is contained in:
2025-09-13 23:28:47 +02:00
parent d754fc0b37
commit 781338a81b
7 changed files with 399 additions and 1 deletions

View File

@@ -4,9 +4,11 @@ import { Separator } from "@/components/ui/separator"
import { getColor } from "@/lib/colors"
import { formatDate, formatNumber } from "@/lib/formatters"
import { getCoinMultiplier, getTotalChallenges, getTotalCoins, getTotalQuests, rewardClaimed } from "@/lib/hypixel/general/stats"
import { getGame, getGameMode } from "@/lib/hypixel/general/status"
import { getGuildMember, getGuildRankTag, getMemberGEXP, getMemberWeeklyGEXP } from "@/lib/hypixel/guild/guild"
import { Guild } from "@/lib/schema/guild"
import { Player } from "@/lib/schema/player"
import { Session } from "@/lib/schema/status"
import Link from "next/link"
import SocialIcons from "./SocialIcons"
@@ -18,9 +20,10 @@ type SidebarProps = {
rank: string | undefined
specialRank: string | undefined
eulaCoins: boolean | undefined
session: Session["session"] | null
}
export default function Sidebar({ level, ign, player, guild, rank, specialRank, eulaCoins }: SidebarProps) {
export default function Sidebar({ level, ign, player, guild, rank, specialRank, eulaCoins, session }: SidebarProps) {
const levelMultiplier = getCoinMultiplier(level, rank, specialRank, eulaCoins)
const levelMultiplierVal = levelMultiplier.value
@@ -200,6 +203,62 @@ export default function Sidebar({ level, ign, player, guild, rank, specialRank,
)
}
function OnlineStatus() {
if (!session?.online) return null
const noMapGameTypes = ["BUILD_BATTLE", "HOUSING", "REPLAY"]
const noMapArcadeModes = [
"DAYONE",
"DEFENDER",
"DRAGONWARS2",
"DROPPER",
"SOCCER",
"STARWARS",
"SIMON_SAYS",
"PARTY",
"DRAW_THEIR_THING",
"PIXEL_PARTY",
"THROW_OUT"
]
const showMode = !(session.gameType === "REPLAY")
const showMap = session.map !== undefined &&
session.gameType !== undefined &&
!noMapGameTypes.includes(session.gameType) &&
session.mode !== undefined &&
!(session.gameType === "ARCADE" && noMapArcadeModes.includes(session.mode))
const mode = session.mode === "LOBBY" ? "Lobby" : getGameMode(session.gameType, session.mode)
return (
<>
<div className="flex flex-col gap-2">
<h2 className="text-xl font-bold">Online Status</h2>
<div>
{session.gameType && (
<p>
<span className="font-bold">{"Game: "}</span>
<span>{getGame(session.gameType)?.name || "Unknown"}</span>
</p>
)}
{showMode && (
<p>
<span className="font-bold">{"Mode: "}</span>
<span>{mode || "Unknown"}</span>
</p>
)}
{showMap && (
<p>
<span className="font-bold">{"Map: "}</span>
<span>{session.map}</span>
</p>
)}
</div>
</div>
<Separator className="my-4" />
</>
)
}
function SoicalLinks() {
return (
<div className="flex flex-col gap-2">
@@ -235,6 +294,7 @@ export default function Sidebar({ level, ign, player, guild, rank, specialRank,
<SkyblockButton />
<Separator className="my-4" />
<GuildInfo />
<OnlineStatus />
<SoicalLinks />
</CardContent>
</Card>

View File

@@ -4,6 +4,7 @@ import { Card, CardContent } from "@/components/ui/card"
import { env } from "@/lib/env/server"
import { getGuild } from "@/lib/hypixel/api/guild"
import { getUuid } from "@/lib/hypixel/api/mojang"
import { getSession } from "@/lib/hypixel/api/online"
import { getPlayer } from "@/lib/hypixel/api/player"
import { getExactLevel } from "@/lib/hypixel/general/level"
import { Loader2Icon, ShieldAlert } from "lucide-react"
@@ -78,6 +79,7 @@ async function SuspendedPage({ params }: Pick<PageProps<"/player/[ign]">, "param
)
}
const session = await getSession(mc.id)
const guild = await getGuild(mc.id)
const level = getExactLevel(player.networkExp)
@@ -109,6 +111,7 @@ async function SuspendedPage({ params }: Pick<PageProps<"/player/[ign]">, "param
rank={player.newPackageRank}
specialRank={player.rank}
eulaCoins={player.eulaCoins}
session={session}
/>
{player.stats !== undefined ?
(