diff --git a/src/main/events/profile/get-me.ts b/src/main/events/profile/get-me.ts index 5154da8d..1eeecbf9 100644 --- a/src/main/events/profile/get-me.ts +++ b/src/main/events/profile/get-me.ts @@ -1,32 +1,14 @@ import { registerEvent } from "../register-event"; import * as Sentry from "@sentry/electron/main"; -import { HydraApi, logger } from "@main/services"; -import { UserProfile } from "@types"; +import { HydraApi } from "@main/services"; +import { ProfileVisibility, UserDetails } from "@types"; import { userAuthRepository } from "@main/repository"; -import { steamUrlBuilder, UserNotLoggedInError } from "@shared"; -import { steamGamesWorker } from "@main/workers"; - -const getSteamGame = async (objectId: string) => { - try { - const steamGame = await steamGamesWorker.run(Number(objectId), { - name: "getById", - }); - - return { - title: steamGame.name, - iconUrl: steamUrlBuilder.icon(objectId, steamGame.clientIcon), - }; - } catch (err) { - logger.error("Failed to get Steam game", err); - - return null; - } -}; +import { UserNotLoggedInError } from "@shared"; const getMe = async ( _event: Electron.IpcMainInvokeEvent -): Promise => { - return HydraApi.get(`/profile/me`) +): Promise => { + return HydraApi.get(`/profile/me`) .then(async (me) => { userAuthRepository.upsert( { @@ -38,17 +20,6 @@ const getMe = async ( ["id"] ); - if (me.currentGame) { - const steamGame = await getSteamGame(me.currentGame.objectId); - - if (steamGame) { - me.currentGame = { - ...me.currentGame, - ...steamGame, - }; - } - } - Sentry.setUser({ id: me.id, username: me.username }); return me; @@ -61,7 +32,13 @@ const getMe = async ( const loggedUser = await userAuthRepository.findOne({ where: { id: 1 } }); if (loggedUser) { - return { ...loggedUser, id: loggedUser.userId }; + return { + ...loggedUser, + id: loggedUser.userId, + username: "", + bio: "", + profileVisibility: "PUBLIC" as ProfileVisibility, + }; } return null; diff --git a/src/main/services/hydra-api.ts b/src/main/services/hydra-api.ts index 3a167851..90149038 100644 --- a/src/main/services/hydra-api.ts +++ b/src/main/services/hydra-api.ts @@ -6,6 +6,7 @@ import { uploadGamesBatch } from "./library-sync"; import { clearGamesRemoteIds } from "./library-sync/clear-games-remote-id"; import { logger } from "./logger"; import { UserNotLoggedInError } from "@shared"; +import { omit } from "lodash-es"; interface HydraApiOptions { needsAuth: boolean; @@ -96,11 +97,14 @@ export class HydraApi { this.instance.interceptors.response.use( (response) => { logger.log(" ---- RESPONSE -----"); + const data = Array.isArray(response.data) + ? response.data + : omit(response.data, ["username", "accessToken", "refreshToken"]); logger.log( response.status, response.config.method, response.config.url, - response.data + data ); return response; }, @@ -166,7 +170,10 @@ export class HydraApi { this.userAuth.authToken = accessToken; this.userAuth.expirationTimestamp = tokenExpirationTimestamp; - logger.log("Token refreshed", this.userAuth); + logger.log( + "Token refreshed. New expiration:", + this.userAuth.expirationTimestamp + ); userAuthRepository.upsert( { diff --git a/src/renderer/src/context/game-details/game-details.context.tsx b/src/renderer/src/context/game-details/game-details.context.tsx index 9e36a5ea..e723779f 100644 --- a/src/renderer/src/context/game-details/game-details.context.tsx +++ b/src/renderer/src/context/game-details/game-details.context.tsx @@ -105,7 +105,7 @@ export function GameDetailsContextProvider({ setShopDetails(appDetailsResult.value); if ( - appDetailsResult.value!.content_descriptors.ids.includes( + appDetailsResult.value?.content_descriptors.ids.includes( SteamContentDescriptor.AdultOnlySexualContent ) ) { diff --git a/src/renderer/src/declaration.d.ts b/src/renderer/src/declaration.d.ts index 8e341ed8..26169d67 100644 --- a/src/renderer/src/declaration.d.ts +++ b/src/renderer/src/declaration.d.ts @@ -23,6 +23,7 @@ import type { GameStats, TrendingGame, UserStats, + UserDetails, } from "@types"; import type { DiskSpace } from "check-disk-space"; @@ -153,7 +154,7 @@ declare global { ) => Promise; /* Profile */ - getMe: () => Promise; + getMe: () => Promise; undoFriendship: (userId: string) => Promise; updateProfile: ( updateProfile: UpdateProfileRequest diff --git a/src/renderer/src/features/user-details-slice.ts b/src/renderer/src/features/user-details-slice.ts index 00542020..d559de09 100644 --- a/src/renderer/src/features/user-details-slice.ts +++ b/src/renderer/src/features/user-details-slice.ts @@ -1,9 +1,9 @@ import { PayloadAction, createSlice } from "@reduxjs/toolkit"; import { UserFriendModalTab } from "@renderer/pages/shared-modals/user-friend-modal"; -import type { FriendRequest, UserProfile } from "@types"; +import type { FriendRequest, UserDetails } from "@types"; export interface UserDetailsState { - userDetails: UserProfile | null; + userDetails: UserDetails | null; profileBackground: null | string; friendRequests: FriendRequest[]; isFriendsModalVisible: boolean; @@ -24,7 +24,7 @@ export const userDetailsSlice = createSlice({ name: "user-details", initialState, reducers: { - setUserDetails: (state, action: PayloadAction) => { + setUserDetails: (state, action: PayloadAction) => { state.userDetails = action.payload; }, setProfileBackground: (state, action: PayloadAction) => { diff --git a/src/renderer/src/hooks/use-user-details.ts b/src/renderer/src/hooks/use-user-details.ts index a826b008..0ae196dc 100644 --- a/src/renderer/src/hooks/use-user-details.ts +++ b/src/renderer/src/hooks/use-user-details.ts @@ -10,7 +10,7 @@ import { import type { FriendRequestAction, UpdateProfileRequest, - UserProfile, + UserDetails, } from "@types"; import { UserFriendModalTab } from "@renderer/pages/shared-modals/user-friend-modal"; @@ -40,7 +40,7 @@ export function useUserDetails() { }, [clearUserDetails]); const updateUserDetails = useCallback( - async (userDetails: UserProfile) => { + async (userDetails: UserDetails) => { dispatch(setUserDetails(userDetails)); if (userDetails.profileImageUrl) { @@ -83,7 +83,10 @@ export function useUserDetails() { const patchUser = useCallback( async (values: UpdateProfileRequest) => { const response = await window.electron.updateProfile(values); - return updateUserDetails(response); + return updateUserDetails({ + ...response, + username: userDetails?.username || "", + }); }, [updateUserDetails] ); diff --git a/src/renderer/src/pages/game-details/sidebar/sidebar.tsx b/src/renderer/src/pages/game-details/sidebar/sidebar.tsx index 1922403c..e56f0764 100644 --- a/src/renderer/src/pages/game-details/sidebar/sidebar.tsx +++ b/src/renderer/src/pages/game-details/sidebar/sidebar.tsx @@ -1,4 +1,4 @@ -import { useContext, useEffect, useState } from "react"; +import { useContext, useState } from "react"; import type { HowLongToBeatCategory, SteamAppDetails } from "@types"; import { useTranslation } from "react-i18next"; import { Button } from "@renderer/components"; @@ -9,7 +9,7 @@ import { useFormat } from "@renderer/hooks"; import { DownloadIcon, PeopleIcon } from "@primer/octicons-react"; export function Sidebar() { - const [_howLongToBeat, setHowLongToBeat] = useState<{ + const [_howLongToBeat, _setHowLongToBeat] = useState<{ isLoading: boolean; data: HowLongToBeatCategory[] | null; }>({ isLoading: true, data: null }); @@ -17,27 +17,26 @@ export function Sidebar() { const [activeRequirement, setActiveRequirement] = useState("minimum"); - const { gameTitle, shopDetails, objectID, stats } = - useContext(gameDetailsContext); + const { gameTitle, shopDetails, stats } = useContext(gameDetailsContext); const { t } = useTranslation("game_details"); const { numberFormatter } = useFormat(); - useEffect(() => { - if (objectID) { - setHowLongToBeat({ isLoading: true, data: null }); + // useEffect(() => { + // if (objectID) { + // setHowLongToBeat({ isLoading: true, data: null }); - window.electron - .getHowLongToBeat(objectID, "steam", gameTitle) - .then((howLongToBeat) => { - setHowLongToBeat({ isLoading: false, data: howLongToBeat }); - }) - .catch(() => { - setHowLongToBeat({ isLoading: false, data: null }); - }); - } - }, [objectID, gameTitle]); + // window.electron + // .getHowLongToBeat(objectID, "steam", gameTitle) + // .then((howLongToBeat) => { + // setHowLongToBeat({ isLoading: false, data: howLongToBeat }); + // }) + // .catch(() => { + // setHowLongToBeat({ isLoading: false, data: null }); + // }); + // } + // }, [objectID, gameTitle]); return (