feat: update typing to match get me endpoint

This commit is contained in:
Zamitto 2024-09-16 11:22:26 -03:00
parent ee02811aea
commit 1de3a9836c
6 changed files with 53 additions and 62 deletions

View file

@ -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<void>;
/* Profile */
getMe: () => Promise<UserProfile | null>;
getMe: () => Promise<UserDetails | null>;
undoFriendship: (userId: string) => Promise<void>;
updateProfile: (
updateProfile: UpdateProfileRequest

View file

@ -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<UserProfile | null>) => {
setUserDetails: (state, action: PayloadAction<UserDetails | null>) => {
state.userDetails = action.payload;
},
setProfileBackground: (state, action: PayloadAction<string | null>) => {

View file

@ -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]
);

View file

@ -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<keyof SteamAppDetails["pc_requirements"]>("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 (
<aside className={styles.contentSidebar}>