This commit is contained in:
parent
05f98bf4a7
commit
d9cdef5515
@ -19,6 +19,7 @@ export async function GET(request: NextRequest) {
|
||||
};
|
||||
if (foundPlayer != null) {
|
||||
response["trackedSince"] = foundPlayer.trackedSince?.toUTCString();
|
||||
response["daysTracked"] = foundPlayer.getStatisticHistory().size;
|
||||
}
|
||||
return NextResponse.json(response);
|
||||
}
|
||||
|
@ -74,8 +74,7 @@ export async function trackScoreSaberPlayer(
|
||||
if (
|
||||
foundPlayer.rawPlayer &&
|
||||
foundPlayer.rawPlayer.inactive &&
|
||||
Date.now() - foundPlayer.getLastTracked().getTime() >
|
||||
INACTIVE_CHECK_AGAIN_TIME
|
||||
Date.now() - foundPlayer.getked().getTime() > INACTIVE_CHECK_AGAIN_TIME
|
||||
) {
|
||||
io &&
|
||||
(await io.logger.warn(
|
||||
|
@ -8,4 +8,9 @@ export interface PlayerTrackedSince {
|
||||
* The date the player was first tracked
|
||||
*/
|
||||
trackedSince?: string;
|
||||
|
||||
/**
|
||||
* The amount of days the player has been tracked
|
||||
*/
|
||||
daysTracked?: number;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ export interface IPlayer extends Document {
|
||||
/**
|
||||
* The last time the player was tracked
|
||||
*/
|
||||
lastTracked: Date;
|
||||
ked: Date;
|
||||
|
||||
/**
|
||||
* The raw player data.
|
||||
@ -33,7 +33,7 @@ export interface IPlayer extends Document {
|
||||
/**
|
||||
* Gets when this player was last tracked.
|
||||
*/
|
||||
getLastTracked(): Date;
|
||||
getked(): Date;
|
||||
|
||||
/**
|
||||
* Gets the history for the given date
|
||||
@ -64,14 +64,14 @@ export interface IPlayer extends Document {
|
||||
// Mongoose Schema definition for Player
|
||||
const PlayerSchema = new Schema<IPlayer>({
|
||||
_id: { type: String, required: true },
|
||||
lastTracked: { type: Date, default: new Date(), required: false },
|
||||
ked: { type: Date, default: new Date(), required: false },
|
||||
rawPlayer: { type: Object, required: false },
|
||||
statisticHistory: { type: Map, default: () => new Map(), required: false },
|
||||
trackedSince: { type: Date, default: new Date(), required: false },
|
||||
});
|
||||
|
||||
PlayerSchema.methods.getLastTracked = function (): Date {
|
||||
return this.lastTracked || new Date();
|
||||
PlayerSchema.methods.getked = function (): Date {
|
||||
return this.ked || new Date();
|
||||
};
|
||||
|
||||
PlayerSchema.methods.getHistory = function (date: Date): PlayerHistory {
|
||||
|
@ -11,6 +11,7 @@ import PlayerScores from "./player-scores";
|
||||
import ScoreSaberPlayer from "@/common/model/player/impl/scoresaber-player";
|
||||
import Card from "@/components/card";
|
||||
import PlayerBadges from "@/components/player/player-badges";
|
||||
import { useIsMobile } from "@/hooks/use-is-mobile";
|
||||
|
||||
const REFRESH_INTERVAL = 5 * 60 * 1000; // 5 minutes
|
||||
|
||||
@ -29,6 +30,8 @@ export default function PlayerData({
|
||||
sort,
|
||||
page,
|
||||
}: Props) {
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
let player = initalPlayerData;
|
||||
const { data, isLoading, isError } = useQuery({
|
||||
queryKey: ["player", player.id],
|
||||
@ -58,10 +61,12 @@ export default function PlayerData({
|
||||
page={page}
|
||||
/>
|
||||
</article>
|
||||
{!isMobile && (
|
||||
<aside className="w-[550px] hidden 2xl:flex flex-col gap-2">
|
||||
<Mini type="Global" player={player} />
|
||||
<Mini type="Country" player={player} />
|
||||
</aside>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ export default function PlayerTrackedStatus({ player }: Props) {
|
||||
<p>
|
||||
Tracked Since: {format(trackedSince)} ({daysAgoFormatted})
|
||||
</p>
|
||||
<p>Days Tracked: {formatNumberWithCommas(data.daysTracked!)}</p>
|
||||
</div>
|
||||
}
|
||||
side="bottom"
|
||||
|
17
src/hooks/use-is-mobile.ts
Normal file
17
src/hooks/use-is-mobile.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
export function useIsMobile() {
|
||||
const [isMobile, setIsMobile] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const handleResize = () => {
|
||||
setIsMobile(window.innerWidth < 768);
|
||||
};
|
||||
window.addEventListener("resize", handleResize);
|
||||
handleResize();
|
||||
|
||||
return () => window.removeEventListener("resize", handleResize);
|
||||
}, []);
|
||||
|
||||
return isMobile;
|
||||
}
|
Reference in New Issue
Block a user