Skip to content

Commit 15c9bf0

Browse files
committed
view recent playtime
1 parent c63f50b commit 15c9bf0

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

src/components/userLookup.tsx

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,13 @@ const UserPlaytime = (props: { id: number }) => {
505505
);
506506
}, [props.id]);
507507

508+
const getRecentPlaytime = (when: number) => {
509+
setPlaytimeData(undefined);
510+
callApi(`/User/${props.id}/Playtime/${when}`).then((value) =>
511+
value.json().then((json) => setPlaytimeData(json))
512+
);
513+
};
514+
508515
if (!playtimeData) return "Loading...";
509516

510517
const totalMinutes: number = playtimeData.reduce(
@@ -513,20 +520,33 @@ const UserPlaytime = (props: { id: number }) => {
513520
);
514521

515522
return (
516-
<div className="flex flex-col gap-2 mt-2">
517-
{totalMinutes > 0 && (
523+
<div className="flex flex-col">
524+
<div className="flex flex-row gap-2">
525+
<LinkColor onClick={() => getRecentPlaytime(30)}>
526+
Last 30 days
527+
</LinkColor>{" "}
528+
|{" "}
529+
<LinkColor onClick={() => getRecentPlaytime(60)}>
530+
Last 60 Days
531+
</LinkColor>{" "}
532+
|{" "}
533+
<LinkColor onClick={() => getRecentPlaytime(90)}>
534+
Last 90 Days
535+
</LinkColor>
536+
</div>
537+
<div className="flex flex-col gap-2 mt-2">
518538
<div className="underline">
519539
Total: {Math.round((totalMinutes / 60) * 100) / 100} hours
520540
</div>
521-
)}
522-
{playtimeData
523-
.sort((a, b) => b.totalMinutes - a.totalMinutes)
524-
.map((playtime) => (
525-
<div key={playtime.id}>
526-
{playtime.roleId}:{" "}
527-
{Math.round((playtime.totalMinutes / 60) * 100) / 100} hours
528-
</div>
529-
))}
541+
{playtimeData
542+
.sort((a, b) => b.totalMinutes - a.totalMinutes)
543+
.map((playtime) => (
544+
<div key={playtime.id}>
545+
{playtime.roleId}:{" "}
546+
{Math.round((playtime.totalMinutes / 60) * 100) / 100} hours
547+
</div>
548+
))}
549+
</div>
530550
</div>
531551
);
532552
};

0 commit comments

Comments
 (0)