import { getAchievements } from "@/lib/api"; import type { Achievement } from "@/lib/types/achievement"; import { useEffectOnce } from "@/lib/useEffectOnce"; import { useState } from "react"; import { Card, CardContent } from "../ui/card"; import { Medal, Sparkle, Sparkles, Users } from "lucide-react"; import { Skeleton } from "../ui/skeleton"; import A from "../misc/Link"; export default function AchievementList({ server }: { server: string }) { const [achievements, setAchievements] = useState< Array> >([]); const [loading, setLoading] = useState(true); useEffectOnce(() => { setAchievements(() => []); getAchievements(server).then((v) => { for (const a of v) a.achievements.forEach((item, interval) => setAchievements((prev) => [...prev, { interval, ...item }]) ); setLoading(false); }); }); if (loading) return (
); return (
Achievements are earned automatically when the server is online. See{" "} Docs:Advanced/Achievements {achievements .filter( (value, index) => listify(achievements).indexOf(value.type) === index ) .map((a) => { const Icon = formalNames[a.type].icon; return (

{formalNames[a.type].description}

Achieved on {new Date(a.date).getMonth()}/ {new Date(a.date).getDate()}/ {new Date(a.date).getFullYear()}{" "} {new Date(a.date).toLocaleTimeString()}
); })}
); } const formalNames = { mostJoined: { title: "At one time, this server had the most players on the platform!", description: "This is awarded to servers that had the number 1 permission at the time of the achievements getting resolved.", color: "#9aedff", icon: Medal, }, has1kFavorites: { title: "This server has more than 1,000 favorites on MHSF!", description: "This is awarded to servers that had 1,000 favorites at the time of the achievements getting resolved.", color: "#d064ff", icon: Sparkle, }, has1kTotalJoins: { title: "This server has more than 1,000 total joins on Minehut!", description: "This is awarded to servers that had 1,000 total joins at the time of the achievements getting resolved.", color: "#aefa1f", icon: Users, }, has100kFavorites: { title: "This server has more than 100,000 favorites on MHSF!", description: "This is awarded to servers that had 100,000 favorites at the time of the achievements getting resolved.", color: "#fa5b07", icon: Sparkles, }, has100kTotalJoins: { title: "This server has more than 100,000 total joins on Minehut!", description: "This is awarded to servers that had 100,000 total joins at the time of the achievements getting resolved.", color: "#bdcffa", icon: Users, }, }; type WithInterval = K & { interval: number; }; const listify = (list: WithInterval[]) => { const newL: Array = []; list.forEach((c) => newL.push(c.type)); return newL; };