From 6757ebe13c1f7f73fdc4a9141851bc2155c599bc Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Fri, 30 May 2025 08:39:40 -0300 Subject: [PATCH 1/4] feat: syncing favorite games --- src/main/events/library/add-game-to-favorites.ts | 3 +++ src/main/events/library/remove-game-from-favorites.ts | 3 +++ src/main/events/library/sync-game-by-object-id.ts | 5 ++++- src/main/services/library-sync/merge-with-remote-games.ts | 3 +++ src/main/services/library-sync/upload-games-batch.ts | 1 + 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/events/library/add-game-to-favorites.ts b/src/main/events/library/add-game-to-favorites.ts index 8371b366..68c81abb 100644 --- a/src/main/events/library/add-game-to-favorites.ts +++ b/src/main/events/library/add-game-to-favorites.ts @@ -1,5 +1,6 @@ import { registerEvent } from "../register-event"; import { gamesSublevel, levelKeys } from "@main/level"; +import { HydraApi } from "@main/services"; import type { GameShop } from "@types"; const addGameToFavorites = async ( @@ -12,6 +13,8 @@ const addGameToFavorites = async ( const game = await gamesSublevel.get(gameKey); if (!game) return; + HydraApi.put(`/profile/games/${shop}/${objectId}/favorite`).catch(() => {}); + try { await gamesSublevel.put(gameKey, { ...game, diff --git a/src/main/events/library/remove-game-from-favorites.ts b/src/main/events/library/remove-game-from-favorites.ts index c802ab0b..f06f55ce 100644 --- a/src/main/events/library/remove-game-from-favorites.ts +++ b/src/main/events/library/remove-game-from-favorites.ts @@ -1,5 +1,6 @@ import { registerEvent } from "../register-event"; import { gamesSublevel, levelKeys } from "@main/level"; +import { HydraApi } from "@main/services"; import type { GameShop } from "@types"; const removeGameFromFavorites = async ( @@ -12,6 +13,8 @@ const removeGameFromFavorites = async ( const game = await gamesSublevel.get(gameKey); if (!game) return; + HydraApi.put(`/profile/games/${shop}/${objectId}/unfavorite`).catch(() => {}); + try { await gamesSublevel.put(gameKey, { ...game, diff --git a/src/main/events/library/sync-game-by-object-id.ts b/src/main/events/library/sync-game-by-object-id.ts index 6235a09c..960a51d7 100644 --- a/src/main/events/library/sync-game-by-object-id.ts +++ b/src/main/events/library/sync-game-by-object-id.ts @@ -11,14 +11,17 @@ const syncGameByObjectId = async ( return HydraApi.get( `/profile/games/${shop}/${objectId}` ).then(async (res) => { - const { id, playTimeInSeconds, ...rest } = res; + const { id, playTimeInSeconds, isFavorite, ...rest } = res; const gameKey = levelKeys.game(shop, objectId); + const currentData = await gamesSublevel.get(gameKey); + await gamesSublevel.put(gameKey, { ...rest, remoteId: id, playTimeInMilliseconds: playTimeInSeconds * 1000, + favorite: isFavorite ?? currentData?.favorite, }); return res; diff --git a/src/main/services/library-sync/merge-with-remote-games.ts b/src/main/services/library-sync/merge-with-remote-games.ts index ff052506..74ef9c77 100644 --- a/src/main/services/library-sync/merge-with-remote-games.ts +++ b/src/main/services/library-sync/merge-with-remote-games.ts @@ -6,6 +6,7 @@ type ProfileGame = { id: string; lastTimePlayed: Date | null; playTimeInMilliseconds: number; + isFavorite?: boolean; } & ShopAssets; export const mergeWithRemoteGames = async () => { @@ -34,6 +35,7 @@ export const mergeWithRemoteGames = async () => { remoteId: game.id, lastTimePlayed: updatedLastTimePlayed, playTimeInMilliseconds: updatedPlayTime, + favorite: game.isFavorite ?? localGame.favorite, }); } else { await gamesSublevel.put(levelKeys.game(game.shop, game.objectId), { @@ -45,6 +47,7 @@ export const mergeWithRemoteGames = async () => { lastTimePlayed: game.lastTimePlayed, playTimeInMilliseconds: game.playTimeInMilliseconds, isDeleted: false, + favorite: game.isFavorite ?? false, }); } diff --git a/src/main/services/library-sync/upload-games-batch.ts b/src/main/services/library-sync/upload-games-batch.ts index 4294e389..984521db 100644 --- a/src/main/services/library-sync/upload-games-batch.ts +++ b/src/main/services/library-sync/upload-games-batch.ts @@ -26,6 +26,7 @@ export const uploadGamesBatch = async () => { playTimeInMilliseconds: Math.trunc(game.playTimeInMilliseconds), shop: game.shop, lastTimePlayed: game.lastTimePlayed, + isFavorite: game.favorite, }; }) ).catch(() => {}); From 5305e5ca18072619256640fb2c8206b1c732a9e2 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Fri, 30 May 2025 08:40:55 -0300 Subject: [PATCH 2/4] feat: better handle friend code input --- src/locales/en/translation.json | 3 ++- src/locales/pt-BR/translation.json | 3 ++- src/main/constants.ts | 3 ++- .../user-friend-modal-add-friend.tsx | 14 ++++++++------ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index ee4254e2..91946baf 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -500,7 +500,8 @@ "achievements_unlocked": "Achievements Unlocked", "earned_points": "Earned points", "show_achievements_on_profile": "Show your achievements on your profile", - "show_points_on_profile": "Show your earned points on your profile" + "show_points_on_profile": "Show your earned points on your profile", + "error_adding_friend": "Could not send friend request. Please check friend code" }, "achievement": { "achievement_unlocked": "Achievement unlocked", diff --git a/src/locales/pt-BR/translation.json b/src/locales/pt-BR/translation.json index 6b9546ec..af650966 100644 --- a/src/locales/pt-BR/translation.json +++ b/src/locales/pt-BR/translation.json @@ -493,7 +493,8 @@ "achievements_unlocked": "Conquistas desbloqueadas", "earned_points": "Pontos ganhos", "show_achievements_on_profile": "Exiba suas conquistas no perfil", - "show_points_on_profile": "Exiba seus pontos ganhos no perfil" + "show_points_on_profile": "Exiba seus pontos ganhos no perfil", + "error_adding_friend": "Não foi possível enviar o pedido de amizade. Verifique o código de amizade inserido" }, "achievement": { "achievement_unlocked": "Conquista desbloqueada", diff --git a/src/main/constants.ts b/src/main/constants.ts index 16642d50..5625a53e 100644 --- a/src/main/constants.ts +++ b/src/main/constants.ts @@ -4,7 +4,8 @@ import { SystemPath } from "./services/system-path"; export const defaultDownloadsPath = SystemPath.getPath("downloads"); -export const isStaging = import.meta.env.MAIN_VITE_API_URL.includes("staging"); +export const isStaging = + true || import.meta.env.MAIN_VITE_API_URL.includes("staging"); export const windowsStartMenuPath = path.join( SystemPath.getPath("appData"), diff --git a/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal-add-friend.tsx b/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal-add-friend.tsx index 2bcf5ba7..a597c809 100644 --- a/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal-add-friend.tsx +++ b/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal-add-friend.tsx @@ -29,11 +29,10 @@ export const UserFriendModalAddFriend = ({ setIsAddingFriend(true); sendFriendRequest(friendCode) .then(() => { - // TODO: add validation for this input? setFriendCode(""); }) .catch(() => { - showErrorToast("Não foi possível enviar o pedido de amizade"); + showErrorToast(t("error_adding_friend")); }) .finally(() => { setIsAddingFriend(false); @@ -46,8 +45,8 @@ export const UserFriendModalAddFriend = ({ }; const handleClickSeeProfile = () => { - closeModal(); if (friendCode.length === 8) { + closeModal(); navigate(`/profile/${friendCode}`); } }; @@ -74,16 +73,19 @@ export const UserFriendModalAddFriend = ({ }); }; + const handleChangeFriendCode = (e: React.ChangeEvent) => { + const friendCode = e.target.value.trim().slice(0, 8); + setFriendCode(friendCode); + }; + return ( <>
setFriendCode(e.target.value)} + onChange={handleChangeFriendCode} />