feat: returning with edit profile modal

This commit is contained in:
Chubby Granny Chaser
2024-09-13 00:03:58 +01:00
78 changed files with 1810 additions and 906 deletions

View File

@@ -1,10 +1,27 @@
import { registerEvent } from "../register-event";
import { HydraApi } from "@main/services";
import { HydraApi, logger } from "@main/services";
import { steamGamesWorker } from "@main/workers";
import type { UserProfile } from "@types";
import { getUserFriends } from "./get-user-friends";
import { steamUrlBuilder } from "@shared";
const getSteamGame = async (objectId: string) => {
try {
const steamGame = await steamGamesWorker.run(Number(objectId), {
name: "getById",
});
return {
title: steamGame.name,
iconUrl: steamUrlBuilder.icon(objectId, steamGame.clientIcon),
};
} catch (err) {
logger.error("Failed to get Steam game", err);
return null;
}
};
const getUser = async (
_event: Electron.IpcMainInvokeEvent,
userId: string
@@ -20,36 +37,51 @@ const getUser = async (
if (!profile) return null;
const recentGames = await Promise.all(
profile.recentGames.map(async (game) => {
const steamGame = await steamGamesWorker.run(Number(game.objectId), {
name: "getById",
});
profile.recentGames
.map(async (game) => {
const steamGame = await getSteamGame(game.objectId);
return {
...game,
title: steamGame.name,
iconUrl: steamUrlBuilder.icon(game.objectId, steamGame.clientIcon),
};
})
return {
...game,
...steamGame,
};
})
.filter((game) => game)
);
// const libraryGames = await Promise.all(
// profile.libraryGames.map(async (game) => {
// return getSteamUserGame(game);
// })
// );
const libraryGames = await Promise.all(
profile.libraryGames
.map(async (game) => {
const steamGame = await getSteamGame(game.objectId);
// const currentGame = await getGameRunning(profile.currentGame);
return {
...game,
...steamGame,
};
})
.filter((game) => game)
);
if (profile.currentGame) {
const steamGame = await getSteamGame(profile.currentGame.objectId);
if (steamGame) {
profile.currentGame = {
...profile.currentGame,
...steamGame,
};
}
}
return {
...profile,
// libraryGames,
libraryGames,
recentGames,
friends: friends.friends,
totalFriends: friends.totalFriends,
// currentGame,
};
} catch (err) {
console.log("err", err);
return null;
}
};