feat: added pin/unpin to the game card in profile

This commit is contained in:
Moyasee
2025-09-25 20:26:49 +03:00
parent dba4b2c4be
commit fd1f13225b

View File

@@ -35,8 +35,7 @@ export function UserLibraryGameCard({
onMouseEnter,
onMouseLeave,
}: UserLibraryGameCardProps) {
const { userProfile, isMe, getUserLibraryGames } =
useContext(userProfileContext);
const { userProfile, isMe, getUserLibraryGames } = useContext(userProfileContext);
const { t } = useTranslation("user_profile");
const { t: tGame } = useTranslation("game_details");
const { numberFormatter } = useFormat();
@@ -100,23 +99,17 @@ export function UserLibraryGameCard({
try {
if (game.isPinned) {
await window.electron
.removeGameFromPinned(game.shop, game.objectId)
.then(() => {
showSuccessToast(tGame("game_removed_from_pinned"));
});
await window.electron.removeGameFromPinned(game.shop, game.objectId).then(() => {
showSuccessToast(tGame("game_removed_from_pinned"));
});
} else {
await window.electron
.addGameToPinned(game.shop, game.objectId)
.then(() => {
showSuccessToast(tGame("game_added_to_pinned"));
});
await window.electron.addGameToPinned(game.shop, game.objectId).then(() => {
showSuccessToast(tGame("game_added_to_pinned"));
});
}
// Add a small delay to allow server synchronization before refreshing
await new Promise((resolve) => setTimeout(resolve, 1000));
// Refresh the library games to update the UI
await new Promise(resolve => setTimeout(resolve, 1000));
await getUserLibraryGames();
} finally {
setIsPinning(false);
@@ -154,11 +147,7 @@ export function UserLibraryGameCard({
}}
disabled={isPinning}
>
{game.isPinned ? (
<PinSlashIcon size={12} />
) : (
<PinIcon size={12} />
)}
{game.isPinned ? <PinSlashIcon size={12} /> : <PinIcon size={12} />}
</button>
)}
</div>