feat: user profile

This commit is contained in:
Zamitto 2024-06-11 22:09:24 -03:00
parent 8fad9b05e6
commit a974141360
8 changed files with 77 additions and 0 deletions

View file

@ -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,
});

View file

@ -39,6 +39,7 @@ import "./download-sources/validate-download-source";
import "./download-sources/add-download-source"; import "./download-sources/add-download-source";
import "./download-sources/remove-download-source"; import "./download-sources/remove-download-source";
import "./download-sources/sync-download-sources"; import "./download-sources/sync-download-sources";
import "./profile/get-user-profile";
ipcMain.handle("ping", () => "pong"); ipcMain.handle("ping", () => "pong");
ipcMain.handle("getVersion", () => app.getVersion()); ipcMain.handle("getVersion", () => app.getVersion());

View file

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

View file

@ -125,4 +125,8 @@ contextBridge.exposeInMainWorld("electron", {
}, },
checkForUpdates: () => ipcRenderer.invoke("checkForUpdates"), checkForUpdates: () => ipcRenderer.invoke("checkForUpdates"),
restartAndInstallUpdate: () => ipcRenderer.invoke("restartAndInstallUpdate"), restartAndInstallUpdate: () => ipcRenderer.invoke("restartAndInstallUpdate"),
/* Profile */
getUserProfile: (username: string) =>
ipcRenderer.invoke("getUserProfile", username),
}); });

View file

@ -109,6 +109,9 @@ declare global {
) => () => Electron.IpcRenderer; ) => () => Electron.IpcRenderer;
checkForUpdates: () => Promise<boolean>; checkForUpdates: () => Promise<boolean>;
restartAndInstallUpdate: () => Promise<void>; restartAndInstallUpdate: () => Promise<void>;
/* Profile */
getUserProfile: (username: string) => Promise<UserProfile | null>;
} }
interface Window { interface Window {

View file

@ -0,0 +1,7 @@
export const UserProfile = () => {
return (
<>
<p>Tela do usuarioooooooo</p>
</>
);
};

View file

@ -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<UserProfile>();
const { t } = useTranslation("profile");
return (
<>
<p>Tela do usuarioooooooo</p>
</>
);
};

View file

@ -234,6 +234,12 @@ export interface RealDebridUser {
expiration: string; expiration: string;
} }
export interface UserProfile {
username: string;
game: any[];
recentGames: any[];
}
export interface DownloadSource { export interface DownloadSource {
id: number; id: number;
name: string; name: string;