mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: show current game on other users profile
This commit is contained in:
parent
bde396c7db
commit
629b005ea4
4 changed files with 43 additions and 17 deletions
|
@ -1,7 +1,7 @@
|
||||||
import { registerEvent } from "../register-event";
|
import { registerEvent } from "../register-event";
|
||||||
import { HydraApi } from "@main/services";
|
import { HydraApi } from "@main/services";
|
||||||
import { steamGamesWorker } from "@main/workers";
|
import { steamGamesWorker } from "@main/workers";
|
||||||
import { UserGame, UserProfile } from "@types";
|
import { GameRunning, UserGame, UserProfile } from "@types";
|
||||||
import { convertSteamGameToCatalogueEntry } from "../helpers/search-games";
|
import { convertSteamGameToCatalogueEntry } from "../helpers/search-games";
|
||||||
import { getSteamAppAsset } from "@main/helpers";
|
import { getSteamAppAsset } from "@main/helpers";
|
||||||
import { getUserFriends } from "./get-user-friends";
|
import { getUserFriends } from "./get-user-friends";
|
||||||
|
@ -30,21 +30,34 @@ const getUser = async (
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const currentGame = await getGameRunning(profile.currentGame);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...profile,
|
...profile,
|
||||||
libraryGames,
|
libraryGames,
|
||||||
recentGames,
|
recentGames,
|
||||||
friends: friends.friends,
|
friends: friends.friends,
|
||||||
totalFriends: friends.totalFriends,
|
totalFriends: friends.totalFriends,
|
||||||
currentGame: profile.currentGame
|
currentGame,
|
||||||
? getSteamUserGame(profile.currentGame)
|
|
||||||
: null,
|
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getGameRunning = async (currentGame): Promise<GameRunning | null> => {
|
||||||
|
if (!currentGame) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const gameRunning = await getSteamUserGame(currentGame);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...gameRunning,
|
||||||
|
sessionDurationInMillis: currentGame.sessionDurationInSeconds * 1000,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const getSteamUserGame = async (game): Promise<UserGame> => {
|
const getSteamUserGame = async (game): Promise<UserGame> => {
|
||||||
const steamGame = await steamGamesWorker.run(Number(game.objectId), {
|
const steamGame = await steamGamesWorker.run(Number(game.objectId), {
|
||||||
name: "getById",
|
name: "getById",
|
||||||
|
|
|
@ -78,7 +78,7 @@ export function SidebarProfile() {
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{userDetails && gameRunning && (
|
{userDetails && gameRunning?.iconUrl && (
|
||||||
<img
|
<img
|
||||||
alt={gameRunning.title}
|
alt={gameRunning.title}
|
||||||
width={24}
|
width={24}
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
import { FriendRequestAction, UserGame, UserProfile } from "@types";
|
import {
|
||||||
|
FriendRequestAction,
|
||||||
|
GameRunning,
|
||||||
|
UserGame,
|
||||||
|
UserProfile,
|
||||||
|
} from "@types";
|
||||||
import cn from "classnames";
|
import cn from "classnames";
|
||||||
import * as styles from "./user.css";
|
import * as styles from "./user.css";
|
||||||
import { SPACING_UNIT, vars } from "@renderer/theme.css";
|
import { SPACING_UNIT, vars } from "@renderer/theme.css";
|
||||||
|
@ -44,7 +49,6 @@ export function UserContent({
|
||||||
updateUserProfile,
|
updateUserProfile,
|
||||||
}: ProfileContentProps) {
|
}: ProfileContentProps) {
|
||||||
const { t, i18n } = useTranslation("user_profile");
|
const { t, i18n } = useTranslation("user_profile");
|
||||||
|
|
||||||
const {
|
const {
|
||||||
userDetails,
|
userDetails,
|
||||||
profileBackground,
|
profileBackground,
|
||||||
|
@ -64,6 +68,7 @@ export function UserContent({
|
||||||
useState(false);
|
useState(false);
|
||||||
const [showSignOutModal, setShowSignOutModal] = useState(false);
|
const [showSignOutModal, setShowSignOutModal] = useState(false);
|
||||||
const [showUserBlockModal, setShowUserBlockModal] = useState(false);
|
const [showUserBlockModal, setShowUserBlockModal] = useState(false);
|
||||||
|
const [currentGame, setCurrentGame] = useState<GameRunning | null>(null);
|
||||||
|
|
||||||
const { gameRunning } = useAppSelector((state) => state.gameRunning);
|
const { gameRunning } = useAppSelector((state) => state.gameRunning);
|
||||||
|
|
||||||
|
@ -113,6 +118,15 @@ export function UserContent({
|
||||||
|
|
||||||
const isMe = userDetails?.id == userProfile.id;
|
const isMe = userDetails?.id == userProfile.id;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isMe && gameRunning) {
|
||||||
|
setCurrentGame(gameRunning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setCurrentGame(userProfile.currentGame);
|
||||||
|
}, [gameRunning, isMe]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isMe) fetchFriendRequests();
|
if (isMe) fetchFriendRequests();
|
||||||
}, [isMe, fetchFriendRequests]);
|
}, [isMe, fetchFriendRequests]);
|
||||||
|
@ -284,10 +298,10 @@ export function UserContent({
|
||||||
position: "relative",
|
position: "relative",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{gameRunning && isMe && (
|
{currentGame && (
|
||||||
<img
|
<img
|
||||||
src={steamUrlBuilder.libraryHero(gameRunning.objectID)}
|
src={steamUrlBuilder.libraryHero(currentGame.objectID)}
|
||||||
alt={gameRunning.title}
|
alt={currentGame.title}
|
||||||
className={styles.profileBackground}
|
className={styles.profileBackground}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
@ -315,7 +329,7 @@ export function UserContent({
|
||||||
|
|
||||||
<div className={styles.profileInformation}>
|
<div className={styles.profileInformation}>
|
||||||
<h2 style={{ fontWeight: "bold" }}>{userProfile.displayName}</h2>
|
<h2 style={{ fontWeight: "bold" }}>{userProfile.displayName}</h2>
|
||||||
{isMe && gameRunning && (
|
{currentGame && (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
|
@ -331,14 +345,14 @@ export function UserContent({
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Link to={buildGameDetailsPath(gameRunning)}>
|
<Link to={buildGameDetailsPath(currentGame)}>
|
||||||
{gameRunning.title}
|
{currentGame.title}
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<small>
|
<small>
|
||||||
{t("playing_for", {
|
{t("playing_for", {
|
||||||
amount: formatDiffInMillis(
|
amount: formatDiffInMillis(
|
||||||
gameRunning.sessionDurationInMillis,
|
currentGame.sessionDurationInMillis,
|
||||||
new Date()
|
new Date()
|
||||||
),
|
),
|
||||||
})}
|
})}
|
||||||
|
|
|
@ -141,9 +141,8 @@ export interface Game {
|
||||||
export type LibraryGame = Omit<Game, "repacks">;
|
export type LibraryGame = Omit<Game, "repacks">;
|
||||||
|
|
||||||
export interface GameRunning {
|
export interface GameRunning {
|
||||||
id: number;
|
|
||||||
title: string;
|
title: string;
|
||||||
iconUrl: string;
|
iconUrl: string | null;
|
||||||
objectID: string;
|
objectID: string;
|
||||||
shop: GameShop;
|
shop: GameShop;
|
||||||
sessionDurationInMillis: number;
|
sessionDurationInMillis: number;
|
||||||
|
@ -318,7 +317,7 @@ export interface UserProfile {
|
||||||
friends: UserFriend[];
|
friends: UserFriend[];
|
||||||
totalFriends: number;
|
totalFriends: number;
|
||||||
relation: UserRelation | null;
|
relation: UserRelation | null;
|
||||||
currentGame: UserGame | null;
|
currentGame: GameRunning | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateProfileProps {
|
export interface UpdateProfileProps {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue