added friend removing and updated fetching scores notice
All checks were successful
deploy / deploy (push) Successful in 56s
All checks were successful
deploy / deploy (push) Successful in 56s
This commit is contained in:
parent
26a4d3ef2a
commit
74a6ef945c
@ -68,7 +68,7 @@ export default function Navbar() {
|
|||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
key={friend.id}
|
key={friend.id}
|
||||||
className="mt-2 bg-gray-600"
|
className="mt-2 bg-gray-500"
|
||||||
text={friend.name}
|
text={friend.name}
|
||||||
url={`/player/${friend.id}`}
|
url={`/player/${friend.id}`}
|
||||||
icon={
|
icon={
|
||||||
|
@ -12,6 +12,7 @@ import {
|
|||||||
GlobeAsiaAustraliaIcon,
|
GlobeAsiaAustraliaIcon,
|
||||||
HomeIcon,
|
HomeIcon,
|
||||||
UserIcon,
|
UserIcon,
|
||||||
|
XMarkIcon,
|
||||||
} from "@heroicons/react/20/solid";
|
} from "@heroicons/react/20/solid";
|
||||||
import dynamic from "next/dynamic";
|
import dynamic from "next/dynamic";
|
||||||
import { useRef } from "react";
|
import { useRef } from "react";
|
||||||
@ -52,8 +53,20 @@ export default function PlayerInfo({ playerData }: PlayerInfoProps) {
|
|||||||
addProfile(true);
|
addProfile(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function removeFriend() {
|
||||||
|
settingsStore?.removeFriend(playerData.id);
|
||||||
|
|
||||||
|
toast.success(`Successfully removed ${playerData.name} as a friend`);
|
||||||
|
}
|
||||||
|
|
||||||
async function addProfile(isFriend: boolean) {
|
async function addProfile(isFriend: boolean) {
|
||||||
if (!useScoresaberScoresStore.getState().exists(playerId)) {
|
if (!useScoresaberScoresStore.getState().exists(playerId)) {
|
||||||
|
if (!isFriend) {
|
||||||
|
toast.success(`Successfully set ${playerData.name} as your profile`);
|
||||||
|
} else {
|
||||||
|
toast.success(`Successfully added ${playerData.name} as a friend`);
|
||||||
|
}
|
||||||
|
|
||||||
const reponse = await playerScoreStore?.addOrUpdatePlayer(
|
const reponse = await playerScoreStore?.addOrUpdatePlayer(
|
||||||
playerId,
|
playerId,
|
||||||
(page, totalPages) => {
|
(page, totalPages) => {
|
||||||
@ -61,18 +74,27 @@ export default function PlayerInfo({ playerData }: PlayerInfoProps) {
|
|||||||
|
|
||||||
if (page == 1) {
|
if (page == 1) {
|
||||||
toastId.current = toast.info(
|
toastId.current = toast.info(
|
||||||
`Fetching scores ${page}/${totalPages}`,
|
`Fetching scores for ${playerData.name} page ${page}/${totalPages}`,
|
||||||
{
|
{
|
||||||
autoClose: autoClose,
|
autoClose: autoClose,
|
||||||
progress: page / totalPages,
|
progress: page / totalPages,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
if (page != totalPages) {
|
||||||
toast.update(toastId.current, {
|
toast.update(toastId.current, {
|
||||||
progress: page / totalPages,
|
progress: page / totalPages,
|
||||||
render: `Fetching scores ${page}/${totalPages}`,
|
render: `Fetching scores for ${playerData.name} page ${page}/${totalPages}`,
|
||||||
autoClose: autoClose,
|
autoClose: autoClose,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
toast.update(toastId.current, {
|
||||||
|
progress: 0,
|
||||||
|
render: `Successfully fetched scores for ${playerData.name}`,
|
||||||
|
autoClose: autoClose,
|
||||||
|
type: "success",
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
@ -86,12 +108,6 @@ export default function PlayerInfo({ playerData }: PlayerInfoProps) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isFriend) {
|
|
||||||
toast.success(`Successfully set ${playerData.name} as your profile`);
|
|
||||||
} else {
|
|
||||||
toast.success(`Successfully added ${playerData.name} as a friend`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const isOwnProfile = settingsStore.player?.id == playerId;
|
const isOwnProfile = settingsStore.player?.id == playerId;
|
||||||
@ -117,14 +133,27 @@ export default function PlayerInfo({ playerData }: PlayerInfoProps) {
|
|||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!settingsStore?.isFriend(playerId) && !isOwnProfile && (
|
{!isOwnProfile && (
|
||||||
|
<>
|
||||||
|
{!settingsStore?.isFriend(playerId) && (
|
||||||
<button
|
<button
|
||||||
className="rounded-md bg-blue-500 p-1 hover:bg-blue-600"
|
className="rounded-md bg-blue-500 p-1 hover:opacity-80"
|
||||||
onClick={addFriend}
|
onClick={addFriend}
|
||||||
>
|
>
|
||||||
<UserIcon title="Add as Friend" width={24} height={24} />
|
<UserIcon title="Add as Friend" width={24} height={24} />
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{settingsStore.isFriend(playerId) && (
|
||||||
|
<button
|
||||||
|
className="rounded-md bg-red-500 p-1 hover:opacity-80"
|
||||||
|
onClick={removeFriend}
|
||||||
|
>
|
||||||
|
<XMarkIcon title="Remove Friend" width={24} height={24} />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-1 flex w-full flex-col items-center gap-2 md:items-start">
|
<div className="mt-1 flex w-full flex-col items-center gap-2 md:items-start">
|
||||||
|
@ -57,6 +57,13 @@ interface ScoreSaberScoresStore {
|
|||||||
message: string;
|
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
|
* Refreshes the player scores and adds any new scores to the local database
|
||||||
*/
|
*/
|
||||||
@ -135,15 +142,15 @@ export const useScoresaberScoresStore = create<ScoreSaberScoresStore>()(
|
|||||||
console.log("Scanning page", page, "for", playerId);
|
console.log("Scanning page", page, "for", playerId);
|
||||||
if (newScores?.scores.length == 0 || newScores == undefined) break;
|
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) {
|
for (const score of newScores.scores) {
|
||||||
if (score.score.id == mostRecentScoreId) {
|
if (score.score.id == mostRecentScoreId) {
|
||||||
search = false;
|
search = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the callback if it exists
|
|
||||||
callback?.(page, newScores.pageInfo.totalPages);
|
|
||||||
|
|
||||||
if (mostRecentScoreId) {
|
if (mostRecentScoreId) {
|
||||||
// remove the old score
|
// remove the old score
|
||||||
const oldScoreIndex = oldScores.findIndex(
|
const oldScoreIndex = oldScores.findIndex(
|
||||||
@ -210,6 +217,12 @@ export const useScoresaberScoresStore = create<ScoreSaberScoresStore>()(
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
removePlayer: (playerId: string) => {
|
||||||
|
let players: Player[] = get().players;
|
||||||
|
players = players.filter((player) => player.id != playerId);
|
||||||
|
set({ players });
|
||||||
|
},
|
||||||
|
|
||||||
updatePlayerScores: async () => {
|
updatePlayerScores: async () => {
|
||||||
const players = get().players;
|
const players = get().players;
|
||||||
const friends = useSettingsStore.getState().friends;
|
const friends = useSettingsStore.getState().friends;
|
||||||
|
@ -6,6 +6,7 @@ import { ScoreSaberAPI } from "@/utils/scoresaber/api";
|
|||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import { createJSONStorage, persist } from "zustand/middleware";
|
import { createJSONStorage, persist } from "zustand/middleware";
|
||||||
import { IDBStorage } from "./IndexedDBStorage";
|
import { IDBStorage } from "./IndexedDBStorage";
|
||||||
|
import { useScoresaberScoresStore } from "./scoresaberScoresStore";
|
||||||
|
|
||||||
interface SettingsStore {
|
interface SettingsStore {
|
||||||
player: ScoresaberPlayer | undefined;
|
player: ScoresaberPlayer | undefined;
|
||||||
@ -54,6 +55,8 @@ export const useSettingsStore = create<SettingsStore>()(
|
|||||||
|
|
||||||
removeFriend: (friendId: string) => {
|
removeFriend: (friendId: string) => {
|
||||||
const friends = get().friends;
|
const friends = get().friends;
|
||||||
|
|
||||||
|
useScoresaberScoresStore.getState().removePlayer(friendId);
|
||||||
set({ friends: friends.filter((friend) => friend.id != friendId) });
|
set({ friends: friends.filter((friend) => friend.id != friendId) });
|
||||||
|
|
||||||
return friendId;
|
return friendId;
|
||||||
|
Loading…
Reference in New Issue
Block a user