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