- Add PlayField with Java/Bedrock edition switcher, read-only address input, and copy button - Show Add Friend link for Bedrock gamertag - Remove Play and Donate buttons and footer line from homepage - Animate server status chip into an expandable panel with spring motion and outside-click/Escape close
95 lines
5 KiB
TypeScript
95 lines
5 KiB
TypeScript
"use client";
|
|
import { useState } from "react";
|
|
import { CheckIcon, ChevronDownIcon, CopyIcon } from "lucide-react";
|
|
import { Button } from "@/components/ui/button";
|
|
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";
|
|
|
|
export function PlayDialog({ open, onOpenChange }: { open: boolean; onOpenChange: (v: boolean) => void }) {
|
|
const copy = async (v: string) => { await navigator.clipboard.writeText(v); };
|
|
return (
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
<DialogContent className="gap-5">
|
|
<DialogHeader><DialogTitle>How to play</DialogTitle><DialogDescription>Join on Java or Bedrock — same world via Geyser.</DialogDescription></DialogHeader>
|
|
<Tabs defaultValue="java">
|
|
<TabsList className="w-full"><TabsTrigger value="java" className="flex-1">Java</TabsTrigger><TabsTrigger value="bedrock" className="flex-1">Bedrock</TabsTrigger></TabsList>
|
|
<TabsContent value="java" className="space-y-3 pt-2">
|
|
<p className="text-sm text-muted-foreground">Multiplayer → Add Server → <span className="font-mono font-semibold text-foreground">frg.network</span></p>
|
|
<Button size="sm" variant="secondary" onClick={() => copy("frg.network")}>Copy address</Button>
|
|
</TabsContent>
|
|
<TabsContent value="bedrock" className="space-y-3 pt-2">
|
|
<p className="text-sm text-muted-foreground">Add <span className="font-semibold text-foreground">FRG Servers</span> as an Xbox Live friend, then join via Friends.</p>
|
|
<Button size="sm" variant="secondary" onClick={() => copy("FRG Servers")}>Copy gamertag</Button>
|
|
</TabsContent>
|
|
</Tabs>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|
|
|
|
export function PlayButton({ size = "sm" }: { size?: "sm" | "default" | "lg" }) {
|
|
const [open, setOpen] = useState(false);
|
|
return (
|
|
<>
|
|
<Button size={size} onClick={() => setOpen(true)}>Play</Button>
|
|
<PlayDialog open={open} onOpenChange={setOpen} />
|
|
</>
|
|
);
|
|
}
|
|
|
|
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>
|
|
);
|
|
}
|