This commit is contained in:
parent
7e2c4cf972
commit
b88c33e91c
@ -9,6 +9,8 @@ import { createJSONStorage, persist } from "zustand/middleware";
|
|||||||
import { IDBStorage } from "./IndexedDBStorage";
|
import { IDBStorage } from "./IndexedDBStorage";
|
||||||
import { useSettingsStore } from "./settingsStore";
|
import { useSettingsStore } from "./settingsStore";
|
||||||
|
|
||||||
|
const UPDATE_INTERVAL = 1000 * 60 * 30; // 30 minutes
|
||||||
|
|
||||||
type Player = {
|
type Player = {
|
||||||
id: string;
|
id: string;
|
||||||
lastUpdated: number;
|
lastUpdated: number;
|
||||||
@ -62,8 +64,6 @@ interface ScoreSaberScoresStore {
|
|||||||
updatePlayerScores: () => Promise<void>;
|
updatePlayerScores: () => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const UPDATE_INTERVAL = 1000 * 60 * 30; // 30 minutes
|
|
||||||
|
|
||||||
export const useScoresaberScoresStore = create<ScoreSaberScoresStore>()(
|
export const useScoresaberScoresStore = create<ScoreSaberScoresStore>()(
|
||||||
persist(
|
persist(
|
||||||
(set, get) => ({
|
(set, get) => ({
|
||||||
@ -89,14 +89,6 @@ export const useScoresaberScoresStore = create<ScoreSaberScoresStore>()(
|
|||||||
}> => {
|
}> => {
|
||||||
const players: Player[] = get().players;
|
const players: Player[] = get().players;
|
||||||
|
|
||||||
// Check if the player already exists
|
|
||||||
if (get().exists(playerId)) {
|
|
||||||
return {
|
|
||||||
error: true,
|
|
||||||
message: "Player already exists",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (playerId == undefined) {
|
if (playerId == undefined) {
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
@ -194,6 +186,8 @@ export const useScoresaberScoresStore = create<ScoreSaberScoresStore>()(
|
|||||||
|
|
||||||
if (newScoresCount > 0) {
|
if (newScoresCount > 0) {
|
||||||
console.log(`Found ${newScoresCount} new scores for ${playerId}`);
|
console.log(`Found ${newScoresCount} new scores for ${playerId}`);
|
||||||
|
} else {
|
||||||
|
console.log(`No new scores found for ${playerId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
set({
|
set({
|
||||||
@ -247,6 +241,10 @@ export const useScoresaberScoresStore = create<ScoreSaberScoresStore>()(
|
|||||||
|
|
||||||
// loop through all of the players and update their scores
|
// loop through all of the players and update their scores
|
||||||
for (const player of players) {
|
for (const player of players) {
|
||||||
|
if (player.lastUpdated == undefined) {
|
||||||
|
player.lastUpdated = Date.now();
|
||||||
|
}
|
||||||
|
|
||||||
// Skip if we refreshed the scores recently
|
// Skip if we refreshed the scores recently
|
||||||
const timeUntilRefreshMs =
|
const timeUntilRefreshMs =
|
||||||
UPDATE_INTERVAL - (Date.now() - player.lastUpdated);
|
UPDATE_INTERVAL - (Date.now() - player.lastUpdated);
|
||||||
|
Loading…
Reference in New Issue
Block a user