mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: adding time played / last played
This commit is contained in:
parent
d05150a078
commit
fa2a92d5ed
6 changed files with 70 additions and 13 deletions
|
@ -225,5 +225,8 @@
|
||||||
},
|
},
|
||||||
"forms": {
|
"forms": {
|
||||||
"toggle_password_visibility": "Alternar visibilidade da senha"
|
"toggle_password_visibility": "Alternar visibilidade da senha"
|
||||||
|
},
|
||||||
|
"user_profile": {
|
||||||
|
"amount_hours": "Jogou por {{amount}}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,11 @@ const getUserProfile = async (
|
||||||
? getSteamAppAsset("icon", game.objectId, steamGame.clientIcon)
|
? getSteamAppAsset("icon", game.objectId, steamGame.clientIcon)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
return { ...convertSteamGameToCatalogueEntry(steamGame), iconUrl };
|
return {
|
||||||
|
...game,
|
||||||
|
...convertSteamGameToCatalogueEntry(steamGame),
|
||||||
|
iconUrl,
|
||||||
|
};
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -37,7 +41,11 @@ const getUserProfile = async (
|
||||||
? getSteamAppAsset("icon", game.objectId, steamGame.clientIcon)
|
? getSteamAppAsset("icon", game.objectId, steamGame.clientIcon)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
return { ...convertSteamGameToCatalogueEntry(steamGame), iconUrl };
|
return {
|
||||||
|
...game,
|
||||||
|
...convertSteamGameToCatalogueEntry(steamGame),
|
||||||
|
iconUrl,
|
||||||
|
};
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -144,7 +144,7 @@ export function Sidebar() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClickProfile = () => {
|
const handleClickProfile = () => {
|
||||||
navigate("/profile/pmbk5ezJ");
|
navigate("/profile/olejRejN");
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -1,13 +1,41 @@
|
||||||
import { UserProfile } from "@types";
|
import { ProfileGame, UserProfile } from "@types";
|
||||||
import cn from "classnames";
|
import cn from "classnames";
|
||||||
import * as styles from "./profile.css";
|
import * as styles from "./profile.css";
|
||||||
import { SPACING_UNIT, vars } from "@renderer/theme.css";
|
import { SPACING_UNIT, vars } from "@renderer/theme.css";
|
||||||
|
import { useMemo } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { formatDistance } from "date-fns";
|
||||||
|
|
||||||
export interface ProfileContentProps {
|
export interface ProfileContentProps {
|
||||||
userProfile: UserProfile;
|
userProfile: UserProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MAX_MINUTES_TO_SHOW_IN_PLAYTIME = 120;
|
||||||
|
|
||||||
export const ProfileContent = ({ userProfile }: ProfileContentProps) => {
|
export const ProfileContent = ({ userProfile }: ProfileContentProps) => {
|
||||||
|
const { t, i18n } = useTranslation("user_profile");
|
||||||
|
|
||||||
|
const numberFormatter = useMemo(() => {
|
||||||
|
return new Intl.NumberFormat(i18n.language, {
|
||||||
|
maximumFractionDigits: 0,
|
||||||
|
});
|
||||||
|
}, [i18n.language]);
|
||||||
|
|
||||||
|
const formatPlayTime = (game: ProfileGame) => {
|
||||||
|
console.log(game);
|
||||||
|
const seconds = game.playTimeInSeconds;
|
||||||
|
const minutes = seconds / 60;
|
||||||
|
|
||||||
|
if (minutes < MAX_MINUTES_TO_SHOW_IN_PLAYTIME) {
|
||||||
|
return t("amount_minutes", {
|
||||||
|
amount: minutes.toFixed(0),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const hours = minutes / 60;
|
||||||
|
return t("amount_hours", { amount: numberFormatter.format(hours) });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<section className={styles.profileContentBox}>
|
<section className={styles.profileContentBox}>
|
||||||
|
@ -46,12 +74,18 @@ export const ProfileContent = ({ userProfile }: ProfileContentProps) => {
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={styles.profileContentBox}
|
style={{
|
||||||
style={{ flexDirection: "column" }}
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
gap: `${SPACING_UNIT}px`,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{userProfile.recentGames.map((game) => {
|
{userProfile.recentGames.map((game) => {
|
||||||
return (
|
return (
|
||||||
<div key={game.objectID} className={styles.feedItem}>
|
<div
|
||||||
|
key={game.objectID}
|
||||||
|
className={cn(styles.feedItem, styles.profileContentBox)}
|
||||||
|
>
|
||||||
<img
|
<img
|
||||||
className={styles.gameIcon}
|
className={styles.gameIcon}
|
||||||
src={game.iconUrl}
|
src={game.iconUrl}
|
||||||
|
@ -61,7 +95,11 @@ export const ProfileContent = ({ userProfile }: ProfileContentProps) => {
|
||||||
/>
|
/>
|
||||||
<div className={styles.gameInformation}>
|
<div className={styles.gameInformation}>
|
||||||
<p>{game.title}</p>
|
<p>{game.title}</p>
|
||||||
<p>há 3 horas</p>
|
<p>
|
||||||
|
{formatDistance(game.lastTimePlayed!, new Date(), {
|
||||||
|
addSuffix: true,
|
||||||
|
})}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -91,12 +129,18 @@ export const ProfileContent = ({ userProfile }: ProfileContentProps) => {
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={styles.profileContentBox}
|
style={{
|
||||||
style={{ flexDirection: "column" }}
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
gap: `${SPACING_UNIT}px`,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{userProfile.libraryGames.map((game) => {
|
{userProfile.libraryGames.map((game) => {
|
||||||
return (
|
return (
|
||||||
<div key={game.objectID} className={styles.gameListItem}>
|
<div
|
||||||
|
key={game.objectID}
|
||||||
|
className={cn(styles.gameListItem, styles.profileContentBox)}
|
||||||
|
>
|
||||||
<img
|
<img
|
||||||
className={styles.gameIcon}
|
className={styles.gameIcon}
|
||||||
src={game.iconUrl}
|
src={game.iconUrl}
|
||||||
|
@ -106,7 +150,7 @@ export const ProfileContent = ({ userProfile }: ProfileContentProps) => {
|
||||||
/>
|
/>
|
||||||
<div className={styles.gameInformation}>
|
<div className={styles.gameInformation}>
|
||||||
<p>{game.title}</p>
|
<p>{game.title}</p>
|
||||||
<p>Jogou por 10 horas</p>
|
<p>{formatPlayTime(game)}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -46,7 +46,7 @@ export const profileGameSection = style({
|
||||||
width: "100%",
|
width: "100%",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
gap: `${SPACING_UNIT}px`,
|
gap: `${SPACING_UNIT * 2}px`,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const contentSidebar = style({
|
export const contentSidebar = style({
|
||||||
|
|
|
@ -91,6 +91,8 @@ export interface ProfileGame {
|
||||||
title: string;
|
title: string;
|
||||||
iconUrl;
|
iconUrl;
|
||||||
string?;
|
string?;
|
||||||
|
playTimeInSeconds: number;
|
||||||
|
lastTimePlayed: Date | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DownloadQueue {
|
export interface DownloadQueue {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue