Skip to content

Commit

Permalink
adds a playtime button
Browse files Browse the repository at this point in the history
  • Loading branch information
harryob committed Oct 28, 2024
1 parent f429954 commit 2ddc76f
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/components/userLookup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ const UserDetailsModal = (props: { player: Player }) => {
const global = useContext(GlobalContext);

const [tickets, setViewTickets] = useState(false);
const [playtime, setViewPlaytime] = useState(false);

useEffect(() => {
setViewTickets(false);
Expand Down Expand Up @@ -398,6 +399,21 @@ const UserDetailsModal = (props: { player: Player }) => {
</div>
</Dialog>
)}
{"|"}
<LinkColor onClick={() => setViewPlaytime(true)}>
View Playtime
</LinkColor>
{playtime && (
<Dialog
open={playtime}
toggle={() => setViewPlaytime(false)}
className="h-[80%]"
>
<div className="pt-5">
<UserPlaytime id={player.id} />
</div>
</Dialog>
)}
</div>
</div>
</>
Expand Down Expand Up @@ -473,6 +489,37 @@ const UserTickets = (props: { ckey: string }) => {
);
};

type Playtime = {
id: number;
playerId: number;
roleId: string;
totalMinutes: number;
};

const UserPlaytime = (props: { id: number }) => {
const [playtimeData, setPlaytimeData] = useState<Playtime[] | undefined>();

useEffect(() => {
callApi(`/User/${props.id}/Playtime`).then((value) =>
value.json().then((json) => setPlaytimeData(json))
);
}, [props.id]);

if (!playtimeData) return "Loading...";

return (
<div className="flex flex-col gap-2 mt-2">
{playtimeData
.sort((a, b) => b.totalMinutes - a.totalMinutes)
.map((playtime) => (
<div key={playtime.id}>
{playtime.roleId}: {playtime.totalMinutes} minutes
</div>
))}
</div>
);
};

const ConnectionType = (props: {
label: string;
path: string;
Expand Down

0 comments on commit 2ddc76f

Please sign in to comment.