mhsf-dev/src/components/ServerCard.tsx

216 lines
7.1 KiB
TypeScript
Raw Normal View History

2024-07-23 18:49:21 -05:00
import {
ContextMenu,
ContextMenuTrigger,
ContextMenuItem,
ContextMenuContent,
ContextMenuSeparator,
} from "@/components/ui/context-menu";
import toast from "react-hot-toast";
import {
CardHeader,
CardTitle,
CardDescription,
Card,
CardContent,
} from "./ui/card";
import IconDisplay from "./IconDisplay";
import { TagShower } from "./ServerList";
import { Copy, EllipsisVertical, Layers, MoveRight } from "lucide-react";
import { Button } from "./ui/button";
import {
Drawer,
DrawerClose,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer";
import { useEffect, useState } from "react";
import { Tooltip } from "@radix-ui/react-tooltip";
import { TooltipContent, TooltipTrigger } from "./ui/tooltip";
export default function ServerCard({ b, motd }: any) {
return (
<ContextMenu>
<ContextMenuTrigger>
2024-07-23 22:07:54 -05:00
<Card
key={b.name}
className="min-h-[450px] max-h-[450px] mb-4 flex items-start"
>
2024-07-23 18:49:21 -05:00
<CardHeader>
<CardTitle className=" m-0">
<IconDisplay server={b} /> {b.name}{" "}
<Drawer>
<DrawerTrigger>
<Button
size="icon"
className=" w-[24px] h-[24px] ml-2 md:hidden"
variant="secondary"
>
<EllipsisVertical size={16} />
</Button>
</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Actions</DrawerTitle>
</DrawerHeader>
<DrawerFooter>
<Button
variant="ghost"
onClick={() => {
2024-07-23 22:07:54 -05:00
navigator.clipboard.writeText(
b.name + ".mshf.minehut.gg",
);
2024-07-23 18:49:21 -05:00
toast.success("Copied IP to clipboard");
}}
>
Copy server IP
<Copy size={18} className=" ml-4" />
</Button>
<Button
variant="ghost"
onClick={() => {
window.location.href = "/server/" + b.name;
}}
>
Open server page
</Button>
</DrawerFooter>
</DrawerContent>
</Drawer>
{b.author != undefined ? (
<div className=" text-sm text-muted-foreground">
by {b.author}
</div>
) : (
<br />
)}
<TagShower server={b} />
</CardTitle>
<CardDescription className=" float-left inline">
<span className=" flex items-center">
{b.playerData.playerCount == 0 ? (
<div
className=" items-center border"
style={{
width: ".5rem",
height: ".5rem",
borderRadius: "9999px",
}}
/>
) : (
<div
className=" items-center"
style={{
backgroundColor: "#0cce6b",
width: ".5rem",
height: ".5rem",
borderRadius: "9999px",
}}
/>
)}
<span className=" pl-1">
{b.playerData.playerCount}{" "}
{b.playerData.playerCount == 1 ? "player" : "players"}{" "}
currently online
</span>
</span>
<ContextMenu>
<ContextMenuTrigger>
<>
<Button
size="icon"
variant="secondary"
className=" min-w-[128px] max-w-[328px] h-[32px] mt-2 ml-2 max-md:hidden"
onClick={() => {
2024-07-23 22:07:54 -05:00
navigator.clipboard.writeText(
b.name + ".mshf.minehut.gg",
);
2024-07-23 18:49:21 -05:00
toast.success("Copied IP to clipboard");
}}
>
<Copy size={18} />
<code className="ml-2">{b.name}</code>
</Button>
<Tooltip>
<TooltipTrigger>
<Button
size="icon"
variant="secondary"
className=" w-[32px] h-[32px] mt-2 ml-2 max-md:hidden"
onClick={() => {
window.location.href = "/server/" + b.name;
}}
>
<Layers size={18} />
</Button>
</TooltipTrigger>
<TooltipContent>
2024-07-23 22:07:54 -05:00
Open up the server page to see more information about
the server
2024-07-23 18:49:21 -05:00
</TooltipContent>
</Tooltip>
</>
</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem
onClick={() => {
2024-07-23 22:07:54 -05:00
navigator.clipboard.writeText(
b.name + ".mshf.minehut.gg",
);
2024-07-23 18:49:21 -05:00
toast.success("Copied IP to clipboard");
}}
>
Copy server IP
<div className=" RightSlot">
<Copy size={18} />
</div>
</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem
onClick={() => {
window.location.href = "/server/" + b.name;
}}
>
Open server page
</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
</CardDescription>
<CardContent>
2024-07-23 22:07:54 -05:00
{b.name != "Skylegendz" && (
<span dangerouslySetInnerHTML={{ __html: motd }} />
)}
2024-07-23 18:49:21 -05:00
</CardContent>
</CardHeader>
</Card>
</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem
onClick={() => {
2024-07-23 22:07:54 -05:00
navigator.clipboard.writeText(b.name + ".mshf.minehut.gg");
2024-07-23 18:49:21 -05:00
toast.success("Copied IP to clipboard");
}}
>
Copy server IP
<div className=" RightSlot">
<Copy size={18} />
</div>
</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem
onClick={() => {
window.location.href = "/server/" + b.name;
}}
>
Open server page
</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
);
}