From 58ddf3d79aab49dea08c83e9e39df4d3235f3ae1 Mon Sep 17 00:00:00 2001 From: Liam Date: Sun, 22 Oct 2023 05:20:59 +0100 Subject: [PATCH] update embed --- src/app/layout.tsx | 2 +- src/store/playerScoresStore.ts | 32 ++++++++++++++++++++++++++++++++ src/store/settingsStore.ts | 1 + src/utils/scoresaber/api.ts | 8 ++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 8d05d73..7191998 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -15,7 +15,7 @@ export const metadata: Metadata = { openGraph: { title: "Scoresaber Reloaded", description: "Aggregate your scores with other leaderboards together!", - url: "https://ssrdev.fascinated.cc", + url: "https://ssr.fascinated.cc", locale: "en_US", type: "website", }, diff --git a/src/store/playerScoresStore.ts b/src/store/playerScoresStore.ts index 2518728..50774b3 100644 --- a/src/store/playerScoresStore.ts +++ b/src/store/playerScoresStore.ts @@ -16,9 +16,36 @@ interface PlayerScoresStore { 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 + * + * @param playerId the player id + * @returns if the player exists + */ exists: (playerId: string) => boolean; + + /** + * Gets the given player + * + * @param playerId the player id + * @returns the player + */ get(playerId: string): Player | undefined; + + /** + * Adds the player to the local database + * + * @param playerId the player id + * @param callback a callback to call when a score page is fetched + * @returns if the player was added successfully + */ addPlayer: ( playerId: string, callback?: (page: number, totalPages: number) => void, @@ -26,6 +53,10 @@ interface PlayerScoresStore { error: boolean; message: string; }>; + + /** + * Refreshes the player scores and adds any new scores to the local database + */ updatePlayerScores: () => void; } @@ -193,6 +224,7 @@ export const usePlayerScoresStore = create()( ), ); +// Update the player scores every 30 minutes usePlayerScoresStore.getState().updatePlayerScores(); setInterval(() => { usePlayerScoresStore.getState().updatePlayerScores(); diff --git a/src/store/settingsStore.ts b/src/store/settingsStore.ts index 7963845..f870b2c 100644 --- a/src/store/settingsStore.ts +++ b/src/store/settingsStore.ts @@ -125,6 +125,7 @@ export const useSettingsStore = create()( ), ); +// Refresh profiles every 10 minutes useSettingsStore.getState().refreshProfiles(); setInterval( () => useSettingsStore.getState().refreshProfiles(), diff --git a/src/utils/scoresaber/api.ts b/src/utils/scoresaber/api.ts index b131db7..3a3d1cd 100644 --- a/src/utils/scoresaber/api.ts +++ b/src/utils/scoresaber/api.ts @@ -117,6 +117,14 @@ export async function fetchScores( }; } +/** + * Gets all of the players for the given player id + * + * @param playerId the id of the player + * @param searchType the type of search to perform + * @param callback a callback to call when a page is fetched + * @returns a list of scores + */ export async function fetchAllScores( playerId: string, searchType: string,