Skip to content

Commit

Permalink
homescreen stats, deeeeeper integration
Browse files Browse the repository at this point in the history
  • Loading branch information
harryob committed Apr 23, 2024
1 parent 30ff617 commit 1c6c861
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 47 deletions.
5 changes: 3 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faXmark } from "@fortawesome/free-solid-svg-icons";
import { GlobalContext } from "./types/global";
import { CidLookup } from "./components/cidLookup";
import { RoundData } from "./components/roundData";

export default function App() {
const [toastMessage, showToastMessage] = useState<string | null>(null);

const [option, setOption] = useState<string | null>(null);

const displayToast = (string: string) => {
Expand Down Expand Up @@ -42,7 +42,7 @@ export default function App() {
{!option && (
<div className="flex flex-row gap-3">
<div
className="border border-white p-3 cursor-pointer"
className="border border-white p-3 cursor-pointer grow"
onClick={() => setOption("lookup")}
>
Lookup User
Expand All @@ -65,6 +65,7 @@ export default function App() {
{option === "lookup" && <LookupMenu />}
{option === "ip" && <IpLookup />}
{option === "cid" && <CidLookup />}
{!option && <RoundData />}
</div>
</div>
<div className={`toast ${toastMessage ? "show" : ""}`}>
Expand Down
5 changes: 4 additions & 1 deletion src/components/cidLookup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { LookupMenu } from "./userLookup";
import { Dialog } from "./dialog";
import { GlobalContext } from "../types/global";
import { LoginTriplet } from "../types/loginTriplet";
import { DetailedIp } from "./detailedIp";

interface CidLookupProps extends PropsWithChildren {
initialCid?: string;
Expand Down Expand Up @@ -84,7 +85,9 @@ const CidData = (props: { triplets: LoginTriplet[] }) => {
{props.triplets.map((triplet) => (
<div key={triplet.id}>
{triplet.loginDate}: <NameExpand name={triplet.ckey} /> -{" "}
{triplet.ip1}.{triplet.ip2}.{triplet.ip3}.{triplet.ip4}
<DetailedIp
ip={`${triplet.ip1}.${triplet.ip2}.${triplet.ip3}.${triplet.ip4}`}
/>
</div>
))}
</div>
Expand Down
29 changes: 29 additions & 0 deletions src/components/detailedCid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { useState } from "react";
import { Dialog } from "./dialog";
import { CidLookup } from "./cidLookup";

type DetailedCidProps = {
cid: string;
};

export const DetailedCid: React.FC<DetailedCidProps> = (
props: DetailedCidProps
) => {
const [open, setOpen] = useState(false);

return (
<>
<div
onClick={() => setOpen(true)}
className="cursor-pointer inline text-blue-600"
>
{props.cid}
</div>
{open && (
<Dialog open={open} toggle={() => setOpen(false)}>
<CidLookup initialCid={props.cid} />
</Dialog>
)}
</>
);
};
29 changes: 29 additions & 0 deletions src/components/detailedIp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { useState } from "react";
import { Dialog } from "./dialog";
import { IpLookup } from "./ipLookup";

type DetailedIpProps = {
ip: string;
};

export const DetailedIp: React.FC<DetailedIpProps> = (
props: DetailedIpProps
) => {
const [open, setOpen] = useState(false);

return (
<>
<div
onClick={() => setOpen(true)}
className="cursor-pointer inline text-blue-600"
>
{props.ip}
</div>
{open && (
<Dialog open={open} toggle={() => setOpen(false)}>
<IpLookup initialIp={props.ip} />
</Dialog>
)}
</>
);
};
3 changes: 2 additions & 1 deletion src/components/ipLookup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { LookupMenu } from "./userLookup";
import { Dialog } from "./dialog";
import { GlobalContext } from "../types/global";
import { LoginTriplet } from "../types/loginTriplet";
import { DetailedCid } from "./detailedCid";

interface IpLookupProps extends PropsWithChildren {
initialIp?: string;
Expand Down Expand Up @@ -84,7 +85,7 @@ const IpData = (props: { triplets: LoginTriplet[] }) => {
{props.triplets.map((triplet) => (
<div key={triplet.id}>
{triplet.loginDate}: <NameExpand name={triplet.ckey} /> -{" "}
{triplet.lastKnownCid}
<DetailedCid cid={triplet.lastKnownCid} />
</div>
))}
</div>
Expand Down
102 changes: 102 additions & 0 deletions src/components/roundData.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import React, { PropsWithChildren, useEffect, useState } from "react";

type RoundData = {
mode: string;
vote: number;
ai: boolean;
host?: string;
round_id: number;
players: number;
revision: string;
admins: number;
gamestate: number;
map_name: string;
security_level: string;
round_duration: number;
time_dilation_current: number;
time_dilation_avg: number;
time_dilation_avg_slow: number;
time_dilation_avg_fast: number;
mcpu: number;
cpu: number;
};

export const RoundData: React.FC = () => {
const [roundData, setRoundData] = useState<RoundData | null>(null);

useEffect(() => {
if (!roundData) {
fetch(`${import.meta.env.VITE_API_PATH}/Round`).then((value) =>
value.json().then((json) => setRoundData(json.data))
);
}
});

if (!roundData) {
return <div>Loading...</div>;
}

const formatGameState = (gameState: number) => {
switch (gameState) {
case 0:
return "Starting";
case 1:
return "Lobby";
case 2:
return "Setting Up";
case 3:
return "Playing";
case 4:
return "Finished";
}
return "Unknown";
};

const formatDuration = (ms: number) => {
if (ms < 0) ms = -ms;
const time = {
day: Math.floor(ms / 86400000),
hour: Math.floor(ms / 3600000) % 24,
minute: Math.floor(ms / 60000) % 60,
second: Math.floor(ms / 1000) % 60,
};
return Object.entries(time)
.filter((val) => val[1] !== 0)
.map(([key, val]) => `${val} ${key}${val !== 1 ? "s" : ""}`)
.join(", ");
};

return (
<div className="flex flex-col justify-center mt-20 gap-2">
<div className="flex flex-row justify-center gap-3">
<InfoBox label="Round ID">{roundData.round_id}</InfoBox>
<InfoBox label="Players">{roundData.players}</InfoBox>
<InfoBox label="Admins">{roundData.admins}</InfoBox>
</div>
<div className="flex flex-row gap-3">
<InfoBox label="Map Name">{roundData.map_name}</InfoBox>
<InfoBox label="Game State">
{formatGameState(roundData.gamestate)}
</InfoBox>
</div>
<div className="flex flex-row gap-3">
<InfoBox label="Duration">
{formatDuration(roundData.round_duration * 100)}
</InfoBox>
</div>
</div>
);
};

interface InfoBoxProps extends PropsWithChildren {
label: string;
}

const InfoBox = (props: InfoBoxProps) => {
return (
<div className="p-5 border-white border flex flex-col gap-2 grow">
<div className="text-3xl">{props.label}</div>
{props.children}
</div>
);
};
45 changes: 2 additions & 43 deletions src/components/userLookup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import {
} from "react";
import React from "react";
import { GlobalContext } from "../types/global";
import { Dialog } from "./dialog";
import { IpLookup } from "./ipLookup";
import { CidLookup } from "./cidLookup";
import { DetailedCid } from "./detailedCid";
import { DetailedIp } from "./detailedIp";

type ActiveLookupType = {
value: string;
Expand Down Expand Up @@ -314,46 +313,6 @@ const UserDetailsModal = (props: { player: Player }) => {
);
};

const DetailedIp = (props: { ip: string }) => {
const [open, setOpen] = useState(false);

return (
<>
<div
onClick={() => setOpen(true)}
className="cursor-pointer inline text-blue-600"
>
{props.ip}
</div>
{open && (
<Dialog open={open} toggle={() => setOpen(false)}>
<IpLookup initialIp={props.ip} />
</Dialog>
)}
</>
);
};

const DetailedCid = (props: { cid: string }) => {
const [open, setOpen] = useState(false);

return (
<>
<div
onClick={() => setOpen(true)}
className="cursor-pointer inline text-blue-600"
>
{props.cid}
</div>
{open && (
<Dialog open={open} toggle={() => setOpen(false)}>
<CidLookup initialCid={props.cid} />
</Dialog>
)}
</>
);
};

interface PlayerNote {
id: number;
playerId: number;
Expand Down

0 comments on commit 1c6c861

Please sign in to comment.