mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-13 11:42:10 +00:00
feat: user profile
This commit is contained in:
parent
8fad9b05e6
commit
a974141360
8 changed files with 77 additions and 0 deletions
|
@ -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,
|
||||||
|
});
|
||||||
|
|
|
@ -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());
|
||||||
|
|
23
src/main/events/profile/get-user-profile.ts
Normal file
23
src/main/events/profile/get-user-profile.ts
Normal 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);
|
|
@ -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),
|
||||||
});
|
});
|
||||||
|
|
3
src/renderer/src/declaration.d.ts
vendored
3
src/renderer/src/declaration.d.ts
vendored
|
@ -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 {
|
||||||
|
|
7
src/renderer/src/pages/profile/profile.css.tsx
Normal file
7
src/renderer/src/pages/profile/profile.css.tsx
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
export const UserProfile = () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<p>Tela do usuarioooooooo</p>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
17
src/renderer/src/pages/profile/profile.tsx
Normal file
17
src/renderer/src/pages/profile/profile.tsx
Normal 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>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue