From 4e73009997ec7cc347668a06994ae5724762ed51 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Wed, 12 Jun 2024 22:23:12 -0300 Subject: [PATCH] feat: showing first content on profile page --- src/main/events/profile/get-user-profile.ts | 41 ++++++++++++---- .../src/components/sidebar/sidebar.tsx | 2 +- .../src/pages/profile/profile-content.tsx | 23 ++++++++- .../src/pages/profile/profile-skeleton.tsx | 6 ++- .../src/pages/profile/profile.css.tsx | 48 ++++++++++++++++--- src/renderer/src/pages/profile/profile.tsx | 17 +++++-- src/types/index.ts | 4 +- 7 files changed, 116 insertions(+), 25 deletions(-) diff --git a/src/main/events/profile/get-user-profile.ts b/src/main/events/profile/get-user-profile.ts index 018d0ef1..18e9f692 100644 --- a/src/main/events/profile/get-user-profile.ts +++ b/src/main/events/profile/get-user-profile.ts @@ -2,20 +2,41 @@ import { registerEvent } from "../register-event"; import { userProfileSchema } from "../helpers/validators"; import { logger } from "@main/services"; import { HydraApi } from "@main/services/hydra-api"; +import { steamGamesWorker } from "@main/workers"; +import { LibraryGame, SteamGame, UserProfile } from "@types"; const getUserProfile = async ( _event: Electron.IpcMainInvokeEvent, username: string -) => { - return HydraApi.get(`/profile/${username}`) - .then((response) => { - const profile = userProfileSchema.parse(response.data); - return profile; - }) - .catch((err) => { - logger.error(`getUserProfile: ${username}`, err); - return null; - }); +): Promise => { + try { + const response = await HydraApi.get(`/profile/${username}`); + const profile = userProfileSchema.parse(response.data); + + const recentGames = await Promise.all( + profile.recentGames.map(async (game) => { + const steamGame = await steamGamesWorker.run(Number(game.objectId), { + name: "getById", + }); + + return { ...game, title: steamGame.name, objectId: game.objectId }; + }) + ); + + const libraryGames = await Promise.all( + profile.game.map(async (game) => { + const steamGame = await steamGamesWorker.run(Number(game.objectId), { + name: "getById", + }); + return { ...game, title: steamGame.name, objectID: game.objectId }; + }) + ); + + return { ...profile, game: libraryGames, recentGames }; + } catch (err) { + logger.error(`getUserProfile: ${username}`, err); + return null; + } }; registerEvent("getUserProfile", getUserProfile); diff --git a/src/renderer/src/components/sidebar/sidebar.tsx b/src/renderer/src/components/sidebar/sidebar.tsx index 62f71a7c..ae364002 100644 --- a/src/renderer/src/components/sidebar/sidebar.tsx +++ b/src/renderer/src/components/sidebar/sidebar.tsx @@ -144,7 +144,7 @@ export function Sidebar() { }; const handleClickProfile = () => { - navigate("/profile/brownie"); + navigate("/profile/zamitto"); }; return ( diff --git a/src/renderer/src/pages/profile/profile-content.tsx b/src/renderer/src/pages/profile/profile-content.tsx index 08a459b5..78dd7206 100644 --- a/src/renderer/src/pages/profile/profile-content.tsx +++ b/src/renderer/src/pages/profile/profile-content.tsx @@ -1,5 +1,6 @@ import { UserProfile } from "@types"; import { useTranslation } from "react-i18next"; +import * as styles from "./profile.css"; export interface ProfileContentProps { userProfile: UserProfile; @@ -8,9 +9,29 @@ export interface ProfileContentProps { export const ProfileContent = ({ userProfile }: ProfileContentProps) => { const { t } = useTranslation("profile"); + console.log(userProfile.recentGames); return ( <> -

{userProfile.username}

+
+ + +
+

{userProfile.username}

+

Jogando ABC

+
+
+

Feed

+ {userProfile.recentGames.map((game) => { + return

{game.title}

; + })} + +

Games

+ {userProfile.game.map((game) => { + return

{game.title}

; + })} ); }; diff --git a/src/renderer/src/pages/profile/profile-skeleton.tsx b/src/renderer/src/pages/profile/profile-skeleton.tsx index 1e6783fa..0298b07a 100644 --- a/src/renderer/src/pages/profile/profile-skeleton.tsx +++ b/src/renderer/src/pages/profile/profile-skeleton.tsx @@ -1,7 +1,11 @@ +import Skeleton from "react-loading-skeleton"; +import * as styles from "./profile.css"; + export const ProfileSkeleton = () => { return ( <> -

Loading....

+ + ); }; diff --git a/src/renderer/src/pages/profile/profile.css.tsx b/src/renderer/src/pages/profile/profile.css.tsx index 6b712134..a25e0a9b 100644 --- a/src/renderer/src/pages/profile/profile.css.tsx +++ b/src/renderer/src/pages/profile/profile.css.tsx @@ -1,7 +1,41 @@ -export const UserProfile = () => { - return ( - <> -

Tela do usuarioooooooo

- - ); -}; +import { SPACING_UNIT, vars } from "../../theme.css"; +import { style } from "@vanilla-extract/css"; + +export const wrapper = style({ + padding: "24px", + width: "100%", + display: "flex", + flexDirection: "column", +}); + +export const profileHeader = style({ + display: "flex", + gap: `${SPACING_UNIT + SPACING_UNIT / 2}px`, + alignItems: "center", + padding: `${SPACING_UNIT * 2}px ${SPACING_UNIT * 2}px`, + color: vars.color.muted, + borderRadius: "4px", + border: `solid 1px ${vars.color.border}`, + width: "100%", +}); + +export const profileAvatar = style({ + width: "96px", + height: "96px", + borderRadius: "50%", + display: "flex", + justifyContent: "center", + alignItems: "center", + backgroundColor: vars.color.background, + position: "relative", +}); + +export const profileInformation = style({ + display: "flex", + flexDirection: "column", + alignItems: "flex-start", +}); + +export const profileHeaderSkeleton = style({ + height: "200px", +}); diff --git a/src/renderer/src/pages/profile/profile.tsx b/src/renderer/src/pages/profile/profile.tsx index 6541cb7a..97868c84 100644 --- a/src/renderer/src/pages/profile/profile.tsx +++ b/src/renderer/src/pages/profile/profile.tsx @@ -5,6 +5,9 @@ import { setHeaderTitle } from "@renderer/features"; import { useAppDispatch } from "@renderer/hooks"; import { ProfileSkeleton } from "./profile-skeleton"; import { ProfileContent } from "./profile-content"; +import { SkeletonTheme } from "react-loading-skeleton"; +import { vars } from "@renderer/theme.css"; +import * as styles from "./profile.css"; export const Profile = () => { const { username } = useParams(); @@ -21,7 +24,15 @@ export const Profile = () => { }); }, [dispatch]); - if (!userProfile) return ; - - return ; + return ( + +
+ {userProfile ? ( + + ) : ( + + )} +
+
+ ); }; diff --git a/src/types/index.ts b/src/types/index.ts index fe0175e0..e983019f 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -236,8 +236,8 @@ export interface RealDebridUser { export interface UserProfile { username: string; - game: any[]; - recentGames: any[]; + game: Partial[]; + recentGames: Partial[]; } export interface DownloadSource {