From 74a6ef945c04cedebee16af1b71dd974071a60f1 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 23 Oct 2023 11:25:20 +0100 Subject: [PATCH] added friend removing and updated fetching scores notice --- src/components/Navbar.tsx | 2 +- src/components/player/PlayerInfo.tsx | 67 ++++++++++++++++++++-------- src/store/scoresaberScoresStore.ts | 19 ++++++-- src/store/settingsStore.ts | 3 ++ 4 files changed, 68 insertions(+), 23 deletions(-) diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index 2ce84ba..bacc142 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -68,7 +68,7 @@ export default function Navbar() { return ( )} - {!settingsStore?.isFriend(playerId) && !isOwnProfile && ( - + {!isOwnProfile && ( + <> + {!settingsStore?.isFriend(playerId) && ( + + )} + + {settingsStore.isFriend(playerId) && ( + + )} + )} diff --git a/src/store/scoresaberScoresStore.ts b/src/store/scoresaberScoresStore.ts index 7a9b4c2..f28ee6e 100644 --- a/src/store/scoresaberScoresStore.ts +++ b/src/store/scoresaberScoresStore.ts @@ -57,6 +57,13 @@ interface ScoreSaberScoresStore { message: string; }>; + /** + * Removes a player and clears their scores from the local database + * + * @param playerId the player id + */ + removePlayer: (playerId: string) => void; + /** * Refreshes the player scores and adds any new scores to the local database */ @@ -135,15 +142,15 @@ export const useScoresaberScoresStore = create()( console.log("Scanning page", page, "for", playerId); if (newScores?.scores.length == 0 || newScores == undefined) break; + // Call the callback if it exists + callback?.(page, newScores.pageInfo.totalPages); + for (const score of newScores.scores) { if (score.score.id == mostRecentScoreId) { search = false; break; } - // Call the callback if it exists - callback?.(page, newScores.pageInfo.totalPages); - if (mostRecentScoreId) { // remove the old score const oldScoreIndex = oldScores.findIndex( @@ -210,6 +217,12 @@ export const useScoresaberScoresStore = create()( }; }, + removePlayer: (playerId: string) => { + let players: Player[] = get().players; + players = players.filter((player) => player.id != playerId); + set({ players }); + }, + updatePlayerScores: async () => { const players = get().players; const friends = useSettingsStore.getState().friends; diff --git a/src/store/settingsStore.ts b/src/store/settingsStore.ts index 8494ece..ecde96f 100644 --- a/src/store/settingsStore.ts +++ b/src/store/settingsStore.ts @@ -6,6 +6,7 @@ import { ScoreSaberAPI } from "@/utils/scoresaber/api"; import { create } from "zustand"; import { createJSONStorage, persist } from "zustand/middleware"; import { IDBStorage } from "./IndexedDBStorage"; +import { useScoresaberScoresStore } from "./scoresaberScoresStore"; interface SettingsStore { player: ScoresaberPlayer | undefined; @@ -54,6 +55,8 @@ export const useSettingsStore = create()( removeFriend: (friendId: string) => { const friends = get().friends; + + useScoresaberScoresStore.getState().removePlayer(friendId); set({ friends: friends.filter((friend) => friend.id != friendId) }); return friendId;