Replace play dialog with inline server address field #3
3 changed files with 142 additions and 64 deletions
|
|
@ -1,17 +1,14 @@
|
||||||
"use client";
|
"use client";
|
||||||
import localFont from "next/font/local";
|
import localFont from "next/font/local";
|
||||||
import Link from "next/link";
|
import { useRef } from "react";
|
||||||
import { useRef, useState } from "react";
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { TopBar } from "@/components/top-bar";
|
import { TopBar } from "@/components/top-bar";
|
||||||
import { PlayDialog } from "@/components/play-dialog";
|
import { PlayField } from "@/components/play-dialog";
|
||||||
import { ServerStatusChip } from "@/components/server-status-chip";
|
import { ServerStatusChip } from "@/components/server-status-chip";
|
||||||
import { GradientShimmer, type GradientShimmerHandle } from "@/components/gradient-shimmer";
|
import { GradientShimmer, type GradientShimmerHandle } from "@/components/gradient-shimmer";
|
||||||
|
|
||||||
const makeSans = localFont({ src: "../../public/font/makesans.ttf" });
|
const makeSans = localFont({ src: "../../public/font/makesans.ttf" });
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
const [playOpen, setPlayOpen] = useState(false);
|
|
||||||
const shimmerRef = useRef<GradientShimmerHandle>(null);
|
const shimmerRef = useRef<GradientShimmerHandle>(null);
|
||||||
return (
|
return (
|
||||||
<main className="min-h-screen bg-background text-foreground flex flex-col font-mona">
|
<main className="min-h-screen bg-background text-foreground flex flex-col font-mona">
|
||||||
|
|
@ -24,20 +21,11 @@ export default function Page() {
|
||||||
</div>
|
</div>
|
||||||
<h1 className={`${makeSans.className} text-4xl md:text-5xl font-extrabold lowercase text-primary tracking-tight leading-none`}>FRG Network</h1>
|
<h1 className={`${makeSans.className} text-4xl md:text-5xl font-extrabold lowercase text-primary tracking-tight leading-none`}>FRG Network</h1>
|
||||||
<p className="text-sm leading-relaxed text-muted-foreground max-w-md mx-auto">A small and fun Minecraft server and surrounding community.</p>
|
<p className="text-sm leading-relaxed text-muted-foreground max-w-md mx-auto">A small and fun Minecraft server and surrounding community.</p>
|
||||||
<div className="pt-1 flex justify-center gap-3">
|
<div className="pt-1 flex justify-center">
|
||||||
<Button
|
<PlayField onMouseEnter={() => shimmerRef.current?.emphasize()} />
|
||||||
size="lg"
|
|
||||||
onClick={() => setPlayOpen(true)}
|
|
||||||
onMouseEnter={() => shimmerRef.current?.emphasize()}
|
|
||||||
>
|
|
||||||
Play
|
|
||||||
</Button>
|
|
||||||
<Button size="lg" variant="outline" asChild><Link href="/donate">Donate</Link></Button>
|
|
||||||
</div>
|
</div>
|
||||||
<p className="text-xs text-muted-foreground/70">Java & Bedrock · frg.network</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<PlayDialog open={playOpen} onOpenChange={setPlayOpen} />
|
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
"use client";
|
"use client";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import { CheckIcon, ChevronDownIcon, CopyIcon } from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from "@/components/ui/dialog";
|
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from "@/components/ui/dialog";
|
||||||
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||||
|
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from "@/components/ui/input-group";
|
||||||
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs";
|
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs";
|
||||||
|
|
||||||
export function PlayDialog({ open, onOpenChange }: { open: boolean; onOpenChange: (v: boolean) => void }) {
|
export function PlayDialog({ open, onOpenChange }: { open: boolean; onOpenChange: (v: boolean) => void }) {
|
||||||
|
|
@ -35,3 +38,58 @@ export function PlayButton({ size = "sm" }: { size?: "sm" | "default" | "lg" })
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PLATFORMS = {
|
||||||
|
java: { label: "Java", value: "frg.network", copyLabel: "Copy address", href: undefined, hint: "Multiplayer → Add Server, then paste the address." },
|
||||||
|
bedrock: { label: "Bedrock", value: "FRG Servers", copyLabel: "Copy gamertag", href: "https://www.xbox.com/en-GB/play/user/FRG%20Servers", hint: "Add this gamertag as an Xbox Live friend, then join via Friends." },
|
||||||
|
} as const;
|
||||||
|
type Platform = keyof typeof PLATFORMS;
|
||||||
|
|
||||||
|
export function PlayField({ onMouseEnter }: { onMouseEnter?: () => void }) {
|
||||||
|
const [platform, setPlatform] = useState<Platform>("java");
|
||||||
|
const [copied, setCopied] = useState(false);
|
||||||
|
const p = PLATFORMS[platform];
|
||||||
|
const copy = async () => {
|
||||||
|
await navigator.clipboard.writeText(p.value);
|
||||||
|
setCopied(true);
|
||||||
|
setTimeout(() => setCopied(false), 1500);
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<div className="w-full max-w-xs space-y-2 text-left">
|
||||||
|
<div className="rounded-md bg-background">
|
||||||
|
<InputGroup className="h-10">
|
||||||
|
<InputGroupAddon align="inline-start">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<InputGroupButton variant="ghost" aria-label="Choose edition" className="font-semibold text-foreground">
|
||||||
|
{p.label}<ChevronDownIcon />
|
||||||
|
</InputGroupButton>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="start">
|
||||||
|
<DropdownMenuRadioGroup value={platform} onValueChange={(v) => { setPlatform(v as Platform); setCopied(false); }}>
|
||||||
|
{(Object.keys(PLATFORMS) as Platform[]).map((k) => (
|
||||||
|
<DropdownMenuRadioItem key={k} value={k}>{PLATFORMS[k].label}</DropdownMenuRadioItem>
|
||||||
|
))}
|
||||||
|
</DropdownMenuRadioGroup>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</InputGroupAddon>
|
||||||
|
<InputGroupInput readOnly value={p.value} aria-label={p.label === "Java" ? "Server address" : "Xbox gamertag"} className="font-mono text-sm" onFocus={(e) => e.currentTarget.select()} />
|
||||||
|
<InputGroupAddon align="inline-end">
|
||||||
|
<InputGroupButton variant="ghost" size="icon-xs" aria-label={p.copyLabel} onClick={copy} onMouseEnter={onMouseEnter}>
|
||||||
|
{copied ? <CheckIcon /> : <CopyIcon />}
|
||||||
|
</InputGroupButton>
|
||||||
|
</InputGroupAddon>
|
||||||
|
</InputGroup>
|
||||||
|
</div>
|
||||||
|
{p.href && (
|
||||||
|
<div className="rounded-md bg-background">
|
||||||
|
<Button asChild variant="outline" className="w-full" onMouseEnter={onMouseEnter}>
|
||||||
|
<a href={p.href} target="_blank" rel="noopener noreferrer">Add Friend</a>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<p className="text-center text-xs text-muted-foreground" aria-live="polite">{copied ? "Copied!" : p.hint}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
"use client";
|
"use client";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
import { motion } from "motion/react";
|
||||||
import type { ServerStatus } from "@/lib/server-status";
|
import type { ServerStatus } from "@/lib/server-status";
|
||||||
|
|
||||||
const REFRESH_MS = 60_000;
|
const REFRESH_MS = 60_000;
|
||||||
|
|
@ -19,6 +20,23 @@ const TEXT = {
|
||||||
export function ServerStatusChip() {
|
export function ServerStatusChip() {
|
||||||
const [status, setStatus] = useState<ServerStatus | null>(null);
|
const [status, setStatus] = useState<ServerStatus | null>(null);
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
const rootRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return;
|
||||||
|
const onDown = (e: PointerEvent) => {
|
||||||
|
if (!rootRef.current?.contains(e.target as Node)) setOpen(false);
|
||||||
|
};
|
||||||
|
const onKey = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "Escape") setOpen(false);
|
||||||
|
};
|
||||||
|
document.addEventListener("pointerdown", onDown);
|
||||||
|
document.addEventListener("keydown", onKey);
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener("pointerdown", onDown);
|
||||||
|
document.removeEventListener("keydown", onKey);
|
||||||
|
};
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
|
@ -45,55 +63,69 @@ export function ServerStatusChip() {
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="inline-flex flex-col items-center">
|
<div ref={rootRef} className="relative h-[26px] w-full">
|
||||||
<button
|
<div className="absolute inset-x-0 top-0 z-10 flex justify-center">
|
||||||
type="button"
|
<motion.div
|
||||||
onClick={() => setOpen((v) => !v)}
|
className="overflow-hidden rounded-[20px] border border-border bg-background/60 backdrop-blur-md text-left shadow-xl shadow-black/0 data-[open=true]:shadow-black/30 data-[open=true]:bg-background/80"
|
||||||
aria-expanded={open}
|
data-open={open}
|
||||||
aria-controls="server-status-panel"
|
|
||||||
className="inline-flex items-center gap-2 rounded-full border border-border bg-background/60 backdrop-blur-sm px-3 py-1 text-xs font-medium text-muted-foreground hover:text-foreground transition-colors"
|
|
||||||
>
|
|
||||||
<span className={`inline-flex h-2 w-2 rounded-full ${DOT[state]}`} />
|
|
||||||
<span>{status ? TEXT[state] : "Checking…"}</span>
|
|
||||||
{state === "online" && status?.players && (
|
|
||||||
<span className="text-muted-foreground/70">· {status.players.online} online</span>
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{open && (
|
|
||||||
<div
|
|
||||||
id="server-status-panel"
|
|
||||||
className="mt-2 w-72 rounded-xl border border-border bg-background/80 backdrop-blur-md p-4 text-left text-sm shadow-xl shadow-black/30"
|
|
||||||
>
|
>
|
||||||
{status ? (
|
<motion.button
|
||||||
<dl className="grid grid-cols-[auto_1fr] gap-x-4 gap-y-2 text-xs">
|
type="button"
|
||||||
<dt className="text-muted-foreground">Address</dt>
|
onClick={() => setOpen((v) => !v)}
|
||||||
<dd className="font-mono text-foreground">{status.host}</dd>
|
aria-expanded={open}
|
||||||
<dt className="text-muted-foreground">Players</dt>
|
aria-controls="server-status-panel"
|
||||||
<dd className="text-foreground">
|
className="flex w-full items-center gap-2 px-3 py-1 text-xs font-medium text-muted-foreground hover:text-foreground transition-colors whitespace-nowrap"
|
||||||
{state === "online" && status.players ? `${status.players.online} / ${status.players.max}` : "—"}
|
>
|
||||||
</dd>
|
<span className={`inline-flex h-2 w-2 rounded-full ${DOT[state]}`} />
|
||||||
<dt className="text-muted-foreground">Version</dt>
|
<span>{status ? TEXT[state] : "Checking…"}</span>
|
||||||
<dd className="text-foreground">{state === "online" && status.version ? status.version : "—"}</dd>
|
{state === "online" && status?.players && (
|
||||||
{state === "online" && status.motd && (
|
<span className="text-muted-foreground/70">· {status.players.online} online</span>
|
||||||
<>
|
)}
|
||||||
<dt className="text-muted-foreground">Message</dt>
|
</motion.button>
|
||||||
<dd className="text-foreground">{status.motd}</dd>
|
|
||||||
</>
|
<motion.div
|
||||||
|
id="server-status-panel"
|
||||||
|
initial={false}
|
||||||
|
animate={{ height: open ? "auto" : 0, width: open ? 256 : 0, opacity: open ? 1 : 0 }}
|
||||||
|
transition={{
|
||||||
|
height: { type: "spring", stiffness: 420, damping: 38 },
|
||||||
|
width: { type: "spring", stiffness: 420, damping: 38 },
|
||||||
|
opacity: { duration: 0.15, delay: open ? 0.08 : 0 },
|
||||||
|
}}
|
||||||
|
aria-hidden={!open}
|
||||||
|
inert={!open}
|
||||||
|
className="overflow-hidden"
|
||||||
|
>
|
||||||
|
<div className="w-64 px-4 pb-4 pt-2">
|
||||||
|
{status ? (
|
||||||
|
<dl className="grid grid-cols-[auto_1fr] gap-x-4 gap-y-2 text-xs">
|
||||||
|
<dt className="text-muted-foreground">Players</dt>
|
||||||
|
<dd className="text-foreground">
|
||||||
|
{state === "online" && status.players ? `${status.players.online} / ${status.players.max}` : "—"}
|
||||||
|
</dd>
|
||||||
|
<dt className="text-muted-foreground">Version</dt>
|
||||||
|
<dd className="text-foreground">{state === "online" && status.version ? status.version : "—"}</dd>
|
||||||
|
{state === "online" && status.motd && (
|
||||||
|
<>
|
||||||
|
<dt className="text-muted-foreground">Message</dt>
|
||||||
|
<dd className="text-foreground">{status.motd}</dd>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</dl>
|
||||||
|
) : (
|
||||||
|
<p className="text-xs text-muted-foreground">Fetching server status…</p>
|
||||||
)}
|
)}
|
||||||
</dl>
|
<p className="mt-3 text-[11px] text-muted-foreground/70">
|
||||||
) : (
|
{state === "unknown" && status
|
||||||
<p className="text-xs text-muted-foreground">Fetching server status…</p>
|
? "We couldn't reach the status service. Try again shortly."
|
||||||
)}
|
: lastChecked
|
||||||
<p className="mt-3 text-[11px] text-muted-foreground/70">
|
? `Last checked ${lastChecked} UTC · refreshes every minute`
|
||||||
{state === "unknown" && status
|
: null}
|
||||||
? "We couldn't reach the status service. Try again shortly."
|
</p>
|
||||||
: lastChecked
|
</div>
|
||||||
? `Last checked ${lastChecked} UTC · refreshes every minute`
|
</motion.div>
|
||||||
: null}
|
</motion.div>
|
||||||
</p>
|
</div>
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue