remove debug and cleanup
All checks were successful
deploy / deploy (push) Successful in 58s

This commit is contained in:
Lee 2023-10-23 06:16:51 +01:00
parent 2b91388b95
commit 1001e68e1a
5 changed files with 31 additions and 11 deletions

View File

@ -59,7 +59,7 @@ export default function Player({ params }: { params: { id: string } }) {
return;
}
ScoreSaberAPI.getPlayerInfo(params.id).then((playerResponse) => {
ScoreSaberAPI.fetchPlayerData(params.id).then((playerResponse) => {
if (!playerResponse) {
setError(true);
setErrorMessage("Failed to fetch player. Is the ID correct?");

View File

@ -27,7 +27,7 @@ export default function SearchPlayer() {
const id = search.split("/").pop();
if (id == undefined) return;
const player = await ScoreSaberAPI.getPlayerInfo(id);
const player = await ScoreSaberAPI.fetchPlayerData(id);
if (player == undefined) return;
setPlayers([player]);

View File

@ -314,7 +314,6 @@ export const useScoresaberScoresStore = create<ScoreSaberScoresStore>()(
players: newPlayers,
lastUpdated: Date.now(),
});
console.log(friends);
}
},
}),

View File

@ -9,16 +9,16 @@ import { createJSONStorage, persist } from "zustand/middleware";
interface SettingsStore {
player: ScoresaberPlayer | undefined;
lastUsedSortType: SortType;
friends: ScoresaberPlayer[];
lastUsedSortType: SortType;
profilesLastUpdated: number;
setProfile: (playerData: ScoresaberPlayer) => void;
setLastUsedSortType: (sortType: SortType) => void;
addFriend: (friendId: string) => Promise<boolean>;
removeFriend: (friendId: string) => void;
isFriend: (friendId: string) => boolean;
clearFriends: () => void;
setLastUsedSortType: (sortType: SortType) => void;
setProfilesLastUpdated: (profilesLastUpdated: number) => void;
refreshProfiles: () => void;
}
@ -39,16 +39,13 @@ export const useSettingsStore = create<SettingsStore>()(
});
},
setLastUsedSortType: (sortType: SortType) =>
set({ lastUsedSortType: sortType }),
async addFriend(friendId: string) {
const friends = useSettingsStore.getState().friends;
if (friends.some((friend) => friend.id == friendId)) {
return false;
}
const friend = await ScoreSaberAPI.getPlayerInfo(friendId);
const friend = await ScoreSaberAPI.fetchPlayerData(friendId);
if (friend == undefined || friend == null) return false;
set({ friends: [...friends, friend] });
@ -73,6 +70,10 @@ export const useSettingsStore = create<SettingsStore>()(
set({ profilesLastUpdated });
},
setLastUsedSortType: (sortType: SortType) => {
set({ lastUsedSortType: sortType });
},
async refreshProfiles() {
const timeUntilRefreshMs =
UPDATE_INTERVAL -
@ -87,6 +88,26 @@ export const useSettingsStore = create<SettingsStore>()(
return;
}
const player = useSettingsStore.getState().player;
if (player != undefined) {
const newPlayer = await ScoreSaberAPI.fetchPlayerData(player.id);
if (newPlayer != undefined && newPlayer != null) {
console.log("Updated player data for", newPlayer.name);
set({ player: newPlayer });
}
}
const friends = useSettingsStore.getState().friends;
const newFriends = await Promise.all(
friends.map(async (friend) => {
const newFriend = await ScoreSaberAPI.fetchPlayerData(friend.id);
if (newFriend == undefined || newFriend == null) return friend;
console.log("Updated friend data for", newFriend.name);
return newFriend;
}),
);
set({ friends: newFriends });
useSettingsStore.setState({ profilesLastUpdated: Date.now() });
},
}),

View File

@ -50,7 +50,7 @@ async function searchByName(
* @param playerId the id of the player
* @returns the player info
*/
async function getPlayerInfo(
async function fetchPlayerData(
playerId: string,
): Promise<ScoresaberPlayer | undefined | null> {
const response = await fetchQueue.fetch(
@ -201,7 +201,7 @@ async function fetchTopPlayers(
export const ScoreSaberAPI = {
searchByName,
getPlayerInfo,
fetchPlayerData,
fetchScores,
fetchAllScores,
fetchTopPlayers,