fix score fetching
All checks were successful
deploy / deploy (push) Successful in 58s

This commit is contained in:
Lee 2023-10-23 16:12:09 +01:00
parent dd7f78b662
commit 7e2c4cf972

@ -16,16 +16,8 @@ type Player = {
};
interface ScoreSaberScoresStore {
lastUpdated: number;
players: Player[];
/**
* Sets when the player scores were last updated
*
* @param lastUpdated when the player scores were last updated
*/
setLastUpdated: (lastUpdated: number) => void;
/**
* Checks if the player exists
*
@ -78,10 +70,6 @@ export const useScoresaberScoresStore = create<ScoreSaberScoresStore>()(
lastUpdated: 0,
players: [],
setLastUpdated: (lastUpdated: number) => {
set({ lastUpdated });
},
exists: (playerId: string) => {
const players: Player[] = get().players;
return players.some((player) => player.id == playerId);
@ -238,10 +226,6 @@ export const useScoresaberScoresStore = create<ScoreSaberScoresStore>()(
// add local player and friends if they don't exist
for (const player of allPlayers) {
if (get().lastUpdated == 0) {
set({ lastUpdated: Date.now() });
}
if (get().get(player.id) == undefined) {
toast.info(
`${
@ -261,20 +245,20 @@ export const useScoresaberScoresStore = create<ScoreSaberScoresStore>()(
}
}
// Skip if we refreshed the scores recently
const timeUntilRefreshMs =
UPDATE_INTERVAL - (Date.now() - get().lastUpdated);
if (timeUntilRefreshMs > 0) {
console.log(
"Waiting",
timeUntilRefreshMs / 1000,
"seconds to refresh scores for players",
);
return;
}
// loop through all of the players and update their scores
for (const player of players) {
// Skip if we refreshed the scores recently
const timeUntilRefreshMs =
UPDATE_INTERVAL - (Date.now() - player.lastUpdated);
if (timeUntilRefreshMs > 0) {
console.log(
"Waiting",
timeUntilRefreshMs / 1000,
"seconds to refresh scores for " + player.id,
);
continue;
}
get().addOrUpdatePlayer(player.id);
}
},