Skip to content

Commit 2ddc76f

Browse files
committed
adds a playtime button
1 parent f429954 commit 2ddc76f

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/components/userLookup.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ const UserDetailsModal = (props: { player: Player }) => {
309309
const global = useContext(GlobalContext);
310310

311311
const [tickets, setViewTickets] = useState(false);
312+
const [playtime, setViewPlaytime] = useState(false);
312313

313314
useEffect(() => {
314315
setViewTickets(false);
@@ -398,6 +399,21 @@ const UserDetailsModal = (props: { player: Player }) => {
398399
</div>
399400
</Dialog>
400401
)}
402+
{"|"}
403+
<LinkColor onClick={() => setViewPlaytime(true)}>
404+
View Playtime
405+
</LinkColor>
406+
{playtime && (
407+
<Dialog
408+
open={playtime}
409+
toggle={() => setViewPlaytime(false)}
410+
className="h-[80%]"
411+
>
412+
<div className="pt-5">
413+
<UserPlaytime id={player.id} />
414+
</div>
415+
</Dialog>
416+
)}
401417
</div>
402418
</div>
403419
</>
@@ -473,6 +489,37 @@ const UserTickets = (props: { ckey: string }) => {
473489
);
474490
};
475491

492+
type Playtime = {
493+
id: number;
494+
playerId: number;
495+
roleId: string;
496+
totalMinutes: number;
497+
};
498+
499+
const UserPlaytime = (props: { id: number }) => {
500+
const [playtimeData, setPlaytimeData] = useState<Playtime[] | undefined>();
501+
502+
useEffect(() => {
503+
callApi(`/User/${props.id}/Playtime`).then((value) =>
504+
value.json().then((json) => setPlaytimeData(json))
505+
);
506+
}, [props.id]);
507+
508+
if (!playtimeData) return "Loading...";
509+
510+
return (
511+
<div className="flex flex-col gap-2 mt-2">
512+
{playtimeData
513+
.sort((a, b) => b.totalMinutes - a.totalMinutes)
514+
.map((playtime) => (
515+
<div key={playtime.id}>
516+
{playtime.roleId}: {playtime.totalMinutes} minutes
517+
</div>
518+
))}
519+
</div>
520+
);
521+
};
522+
476523
const ConnectionType = (props: {
477524
label: string;
478525
path: string;

0 commit comments

Comments
 (0)