From a974141360163b085f22e081f3dc4649d82e34a1 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Tue, 11 Jun 2024 22:09:24 -0300 Subject: [PATCH 001/128] feat: user profile --- src/main/events/helpers/validators.ts | 16 +++++++++++++ src/main/events/index.ts | 1 + src/main/events/profile/get-user-profile.ts | 23 +++++++++++++++++++ src/preload/index.ts | 4 ++++ src/renderer/src/declaration.d.ts | 3 +++ .../src/pages/profile/profile.css.tsx | 7 ++++++ src/renderer/src/pages/profile/profile.tsx | 17 ++++++++++++++ src/types/index.ts | 6 +++++ 8 files changed, 77 insertions(+) create mode 100644 src/main/events/profile/get-user-profile.ts create mode 100644 src/renderer/src/pages/profile/profile.css.tsx create mode 100644 src/renderer/src/pages/profile/profile.tsx diff --git a/src/main/events/helpers/validators.ts b/src/main/events/helpers/validators.ts index f3c9d8442..dddba5bb2 100644 --- a/src/main/events/helpers/validators.ts +++ b/src/main/events/helpers/validators.ts @@ -12,3 +12,19 @@ export const downloadSourceSchema = z.object({ }) ), }); + +const gamesArray = z.array( + z.object({ + id: z.number(), + objectId: z.string().max(255), + playTimeInMilliseconds: z.number().int(), + shop: z.enum(["steam", "epic"]), + lastTimePlayed: z.coerce.date().nullable(), + }) +); + +export const userProfileSchema = z.object({ + username: z.string(), + game: gamesArray, + recentGames: gamesArray, +}); diff --git a/src/main/events/index.ts b/src/main/events/index.ts index 86e74fcb1..99fd785e7 100644 --- a/src/main/events/index.ts +++ b/src/main/events/index.ts @@ -39,6 +39,7 @@ import "./download-sources/validate-download-source"; import "./download-sources/add-download-source"; import "./download-sources/remove-download-source"; import "./download-sources/sync-download-sources"; +import "./profile/get-user-profile"; ipcMain.handle("ping", () => "pong"); ipcMain.handle("getVersion", () => app.getVersion()); diff --git a/src/main/events/profile/get-user-profile.ts b/src/main/events/profile/get-user-profile.ts new file mode 100644 index 000000000..aa915f0ea --- /dev/null +++ b/src/main/events/profile/get-user-profile.ts @@ -0,0 +1,23 @@ +import axios from "axios"; +import { registerEvent } from "../register-event"; +import { userProfileSchema } from "../helpers/validators"; +import { logger } from "@main/services"; + +const getUserProfile = async ( + _event: Electron.IpcMainInvokeEvent, + username: string +) => { + return axios + .get(`${process.env.API_URL}/profile/${username}`) + .then((response) => { + const profile = userProfileSchema.parse(response.data); + console.log(profile); + return profile; + }) + .catch((err) => { + logger.error(`getUserProfile: ${username}`, err); + return null; + }); +}; + +registerEvent("getUserProfiel", getUserProfile); diff --git a/src/preload/index.ts b/src/preload/index.ts index 3a47ba826..0648353cc 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -125,4 +125,8 @@ contextBridge.exposeInMainWorld("electron", { }, checkForUpdates: () => ipcRenderer.invoke("checkForUpdates"), restartAndInstallUpdate: () => ipcRenderer.invoke("restartAndInstallUpdate"), + + /* Profile */ + getUserProfile: (username: string) => + ipcRenderer.invoke("getUserProfile", username), }); diff --git a/src/renderer/src/declaration.d.ts b/src/renderer/src/declaration.d.ts index 2852696fc..8867baba7 100644 --- a/src/renderer/src/declaration.d.ts +++ b/src/renderer/src/declaration.d.ts @@ -109,6 +109,9 @@ declare global { ) => () => Electron.IpcRenderer; checkForUpdates: () => Promise; restartAndInstallUpdate: () => Promise; + + /* Profile */ + getUserProfile: (username: string) => Promise; } interface Window { diff --git a/src/renderer/src/pages/profile/profile.css.tsx b/src/renderer/src/pages/profile/profile.css.tsx new file mode 100644 index 000000000..6b7121346 --- /dev/null +++ b/src/renderer/src/pages/profile/profile.css.tsx @@ -0,0 +1,7 @@ +export const UserProfile = () => { + return ( + <> +

Tela do usuarioooooooo

+ + ); +}; diff --git a/src/renderer/src/pages/profile/profile.tsx b/src/renderer/src/pages/profile/profile.tsx new file mode 100644 index 000000000..e9becfb7d --- /dev/null +++ b/src/renderer/src/pages/profile/profile.tsx @@ -0,0 +1,17 @@ +import { UserProfile } from "@types"; +import { useState } from "react"; +import { useTranslation } from "react-i18next"; +import { useParams } from "react-router-dom"; + +export const Profile = () => { + const { username } = useParams(); + const [userProfile, setUserProfile] = useState(); + + const { t } = useTranslation("profile"); + + return ( + <> +

Tela do usuarioooooooo

+ + ); +}; diff --git a/src/types/index.ts b/src/types/index.ts index d07e40a18..fe0175e0c 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -234,6 +234,12 @@ export interface RealDebridUser { expiration: string; } +export interface UserProfile { + username: string; + game: any[]; + recentGames: any[]; +} + export interface DownloadSource { id: number; name: string; From b8895afc0a0eb1bc7edf19a790e4fd7f0db7b7a4 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Tue, 11 Jun 2024 23:05:05 -0300 Subject: [PATCH 002/128] getting user profile from api --- src/main/events/profile/get-user-profile.ts | 8 +++--- src/renderer/src/components/header/header.tsx | 1 + .../src/components/sidebar/sidebar.tsx | 10 ++++++- src/renderer/src/declaration.d.ts | 1 + src/renderer/src/main.tsx | 2 ++ .../src/pages/profile/profile-content.tsx | 16 ++++++++++++ .../src/pages/profile/profile-skeleton.tsx | 7 +++++ src/renderer/src/pages/profile/profile.tsx | 26 +++++++++++++------ 8 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 src/renderer/src/pages/profile/profile-content.tsx create mode 100644 src/renderer/src/pages/profile/profile-skeleton.tsx diff --git a/src/main/events/profile/get-user-profile.ts b/src/main/events/profile/get-user-profile.ts index aa915f0ea..018d0ef10 100644 --- a/src/main/events/profile/get-user-profile.ts +++ b/src/main/events/profile/get-user-profile.ts @@ -1,17 +1,15 @@ -import axios from "axios"; import { registerEvent } from "../register-event"; import { userProfileSchema } from "../helpers/validators"; import { logger } from "@main/services"; +import { HydraApi } from "@main/services/hydra-api"; const getUserProfile = async ( _event: Electron.IpcMainInvokeEvent, username: string ) => { - return axios - .get(`${process.env.API_URL}/profile/${username}`) + return HydraApi.get(`/profile/${username}`) .then((response) => { const profile = userProfileSchema.parse(response.data); - console.log(profile); return profile; }) .catch((err) => { @@ -20,4 +18,4 @@ const getUserProfile = async ( }); }; -registerEvent("getUserProfiel", getUserProfile); +registerEvent("getUserProfile", getUserProfile); diff --git a/src/renderer/src/components/header/header.tsx b/src/renderer/src/components/header/header.tsx index 046a6a4fd..8b3ac2fa5 100644 --- a/src/renderer/src/components/header/header.tsx +++ b/src/renderer/src/components/header/header.tsx @@ -39,6 +39,7 @@ export function Header({ onSearch, onClear, search }: HeaderProps) { const title = useMemo(() => { if (location.pathname.startsWith("/game")) return headerTitle; + if (location.pathname.startsWith("/profile")) return headerTitle; if (location.pathname.startsWith("/search")) return t("search_results"); return t(pathTitle[location.pathname]); diff --git a/src/renderer/src/components/sidebar/sidebar.tsx b/src/renderer/src/components/sidebar/sidebar.tsx index 897d6b18b..62f71a7cb 100644 --- a/src/renderer/src/components/sidebar/sidebar.tsx +++ b/src/renderer/src/components/sidebar/sidebar.tsx @@ -143,6 +143,10 @@ export function Sidebar() { } }; + const handleClickProfile = () => { + navigate("/profile/brownie"); + }; + return ( <>