diff --git a/public/imgs/badge1.png b/public/imgs/badge1.png new file mode 100644 index 0000000..43ad68a Binary files /dev/null and b/public/imgs/badge1.png differ diff --git a/src/app/server/[server]/short-term/page.tsx b/src/app/server/[server]/statistics/page.tsx similarity index 97% rename from src/app/server/[server]/short-term/page.tsx rename to src/app/server/[server]/statistics/page.tsx index 38d4c00..5cdb46a 100644 --- a/src/app/server/[server]/short-term/page.tsx +++ b/src/app/server/[server]/statistics/page.tsx @@ -69,7 +69,7 @@ export default function ServerPage({ params }: { params: { server: string } }) {
- +
diff --git a/src/components/CommandBar.tsx b/src/components/CommandBar.tsx index 0bbc189..743729d 100644 --- a/src/components/CommandBar.tsx +++ b/src/components/CommandBar.tsx @@ -9,15 +9,17 @@ import { CommandSeparator, CommandShortcut, } from "@/components/ui/command"; -import { TagShower } from "./ServerList"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { OnlineServer } from "@/lib/types/mh-server"; import events from "@/lib/commandEvent"; import { useHotkeys } from "react-hotkeys-hook"; import { ArrowDown01, ArrowLeft, + Calendar, + CheckIcon, CommandIcon, + Database, LinkIcon, Server, Settings, @@ -27,7 +29,10 @@ import { useEffectOnce } from "@/lib/useEffectOnce"; import { useClerk, useUser } from "@clerk/nextjs"; import { useRouter } from "@/lib/useRouter"; import type { SVGProps } from "react"; -import { getAccountFavorites } from "@/lib/api"; +import { favoriteServer, getAccountFavorites } from "@/lib/api"; +import IconDisplay from "./IconDisplay"; +import ServerSingle from "@/lib/single"; +import toast from "react-hot-toast"; export function SearchCommandBar() { const [serverList, setServerList] = useState([]); @@ -58,23 +63,46 @@ export function SearchCommandBar() { { - fetch("https://api.minehut.com/server/" + c + "?byName=true").then( - (l) => { - if (l.ok) { - console.log("found!"); - l.json().then((m: any) => { - setSearchRes(m.server); - console.log(searchRes); - }); - } else { - setSearchRes(undefined); + if (c != "") { + fetch("https://api.minehut.com/server/" + c + "?byName=true").then( + (l) => { + if (l.ok) { + l.json().then((m: any) => { + setSearchRes(m.server); + }); + } else { + setSearchRes(undefined); + } } - } - ); + ); + } }} /> - + + {serverList.map((b: OnlineServer) => ( + { + if (!backEnabled) + events.emit("cmd-server", { + serverName: b.name, + serverObject: b, + }); + if (backEnabled) + events.emit("cmd-server-vb", { + serverName: b.name, + serverObject: b, + }); + setOpen(false); + }} + > + + {b.name} + + ))} + + { setOpen(false); @@ -86,51 +114,148 @@ export function SearchCommandBar() { Go back - - No results found. (Minehut deleted legacy servers) - - {searchRes == undefined ? ( - "" - ) : ( - - { - router.push("/server/" + searchRes.name); - }} - > -
- {searchRes.name}
- - {searchRes.joins} total joins •{" "} - {searchRes.online ? "Online" : "Offline"} - -
-
-
+
+ + ); +} + +export function ServerCommandBar() { + const [open, setOpen] = useState(false); + const [serverName, setServerName] = useState(""); + const [obj, setObj] = useState({}); + const [vb, setVB] = useState(false); + const router = useRouter(); + const [owned, setOwned] = useState(false); + const [serverSingle, setSingle] = useState( + new ServerSingle(serverName) + ); + + useEffect(() => { + events.on("cmd-server", (info) => { + serverSingle.setName(info.serverName); + if (serverSingle != undefined) + (serverSingle as ServerSingle).init(true).then(() => { + setServerName(info.serverName); + setObj(info.serverObject); + setOpen(true); + serverSingle.isCustomized().then((b) => setOwned(true)); + }); + }); + events.on("cmd-server-vb", (info) => { + serverSingle.setName(info.serverName); + setVB(true); + if (serverSingle != undefined) + (serverSingle as ServerSingle).init(true).then(() => { + setServerName(info.serverName); + setObj(info.serverObject); + setOpen(true); + }); + }); + }, []); + + return ( + + + + {Object.keys(obj).length != 0 && ( +
+

+ + {serverName} +

+

+ by {(obj as OnlineServer).author} +

+

+ + + + {" "} + + {(obj as OnlineServer).playerData.playerCount} online currently + +

+

+ + + Created in{" "} + {timeConverter( + (serverSingle as ServerSingle).grabOffline()?.creation + )} + +

+ + {owned && ( +

+ + + Is customized by a MHSF User + +

+ )} +
)} - - - {serverList.map((b: OnlineServer) => ( + + + router.push("/server/" + serverName + "/")} + > + + Open Server Page + + { + favoriteServer(serverName).then(() => toast.success("Done!")); + }} + > + + Favorite Server + + router.push("/server/" + serverName + "/statistics")} + > + + See Statistics + + + + { + setOpen(false); + if (vb) events.emit("search-request-event-back"); + if (!vb) events.emit("search-request-event"); + }} + > + + Go back + + {vb && ( { - router.push("/server/" + b.name); + setOpen(false); + events.emit("cmd-event"); }} > -
- {b.name}
- - - -
+ + Back to main
- ))} + )}
); } +function timeConverter(UNIX_timestamp: any) { + var a = new Date(UNIX_timestamp); + var months = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"]; + var year = a.getFullYear(); + var month = months[a.getMonth()]; + var date = a.getDate(); + var time = month + "/" + date + "/" + year; + return time; +} + export function CommandBar() { const [open, setOpen] = useState(false); const clerk = useClerk(); @@ -327,6 +452,7 @@ export function CommandBarer() { + ); } diff --git a/src/components/IconDisplay.tsx b/src/components/IconDisplay.tsx index b4d6780..eb78cb8 100644 --- a/src/components/IconDisplay.tsx +++ b/src/components/IconDisplay.tsx @@ -7,18 +7,24 @@ import { } from "@/components/ui/tooltip"; import { useState, useEffect } from "react"; -export default function IconDisplay(props: { server: any }) { +export default function IconDisplay(props: { + server: any; + className?: string; +}) { return ( - +
+ +
diff --git a/src/components/ServerList.tsx b/src/components/ServerList.tsx index 72b05ca..38eafb7 100644 --- a/src/components/ServerList.tsx +++ b/src/components/ServerList.tsx @@ -699,7 +699,11 @@ export default function ServerList() { ); } -export function TagShower(props: { server: OnlineServer; className?: string }) { +export function TagShower(props: { + server: OnlineServer; + className?: string; + unclickable?: boolean; +}) { const [loading, setLoading] = useState(true); const [compatiableTags, setCompatiableTags] = useState< Array<{ @@ -757,38 +761,45 @@ export function TagShower(props: { server: OnlineServer; className?: string }) { <> {compatiableTags.map((t) => ( <> - - - - - - {t.name} - - - -
- {t.tooltip} -
- Click the tag to learn more about it. -
-
-
-
- - - - {'"'} - {t.docsName == undefined ? t.name : t.docsName} - {'"'} documentation - - - - -
+ {props.unclickable && ( + + {t.name} + + )} + {!props.unclickable && ( + + + + + + {t.name} + + + +
+ {t.tooltip} +
+ Click the tag to learn more about it. +
+
+
+
+ + + + {'"'} + {t.docsName == undefined ? t.name : t.docsName} + {'"'} documentation + + + + +
+ )} ))} diff --git a/src/components/misc/TabServer.tsx b/src/components/misc/TabServer.tsx index e5ed054..7ee37fd 100644 --- a/src/components/misc/TabServer.tsx +++ b/src/components/misc/TabServer.tsx @@ -12,7 +12,6 @@ export default function TabServer({ tabDef: string; }) { const [tab, setTab] = useState(tabDef); - const [tabLoading, setTabLoading] = useState(false); const router = useRouter(); return ( @@ -21,9 +20,8 @@ export default function TabServer({ value={tab} onValueChange={(tac) => { setTab(tac); - setTabLoading(true); if (tac == "customize") router.push(`/server/${server}/customize`); - if (tac == "historical") router.push(`/server/${server}/short-term`); + if (tac == "statistics") router.push(`/server/${server}/statistics`); if (tac == "general") router.push(`/server/${server}`); }} className="sm:w-[500px] max-sm:w-[200px]" @@ -34,8 +32,8 @@ export default function TabServer({
General Information
- -
Short Term
+ +
Statistics
diff --git a/src/components/ui/radio-group.tsx b/src/components/ui/radio-group.tsx index 0b260cf..4baf26c 100644 --- a/src/components/ui/radio-group.tsx +++ b/src/components/ui/radio-group.tsx @@ -28,7 +28,7 @@ const RadioGroupItem = React.forwardRef< void) { - this.eventTarget.addEventListener(eventName, () => { - callback(); + on(eventName: string, callback: (info?: any) => void) { + this.eventTarget.addEventListener(eventName, (infoF?: any) => { + callback(infoF.detail); }); } } diff --git a/src/lib/single.ts b/src/lib/single.ts index 4187eb8..b492a9f 100644 --- a/src/lib/single.ts +++ b/src/lib/single.ts @@ -1,3 +1,4 @@ +import { serverOwned } from "./api"; import { OnlineServer, ServerResponse } from "./types/mh-server"; import toast from "react-hot-toast"; @@ -10,7 +11,15 @@ export default class ServerSingle { constructor(name: string) { this.name = name; } - init(): Promise { + setName(newName: string) { + this.name = newName; + } + + isCustomized(): Promise { + return serverOwned(this.name); + } + + init(skipOnline?: boolean): Promise { return new Promise((g, bc) => { fetch("https://api.minehut.com/server/" + this.name + "?byName=true") .then((d) => { @@ -18,7 +27,7 @@ export default class ServerSingle { d.json().then((m) => { this.online = m.server.online; this.offlineObj = m.server; - if (this.online == true) { + if (this.online == true && skipOnline != true) { fetch("https://api.minehut.com/servers").then((l) => l.json().then((o) => { o.servers.forEach((j: OnlineServer) => { diff --git a/src/version.tsx b/src/version.tsx index 0c452f7..27099f6 100644 --- a/src/version.tsx +++ b/src/version.tsx @@ -1,4 +1,7 @@ -export const version = "b-0.7.2"; +import Image from "next/image"; +import Link from "next/link"; + +export const version = "b-0.8.0"; const User = ({ user }: { user: string }) => ( @@ -41,6 +44,16 @@ export const Changelog = () => (

+
+ + Version b-0.8.0 (August 11th 2024) + +
    +
  • • Fixing up command bar
  • +
  • • Renaming "Short Term" to "Statistics"
  • +
+
+
Version b-0.7.2 (August 7th 2024) @@ -118,5 +131,11 @@ export const Changelog = () => (
  • • Inital release!
  • +
    +
    + + cool badge + +
    );