feat: showing first content on profile page

This commit is contained in:
Zamitto
2024-06-12 22:23:12 -03:00
parent b8895afc0a
commit 4e73009997
7 changed files with 116 additions and 25 deletions

View File

@@ -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<UserProfile | null> => {
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);