mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-09 03:37:45 +03:00
Merge branch 'main' into feat/launch-options
This commit is contained in:
commit
d8e7fca224
@ -1,7 +1,5 @@
|
|||||||
!macro customUnInstall
|
!macro customUnInstall
|
||||||
${ifNot} ${isUpdated}
|
${ifNot} ${isUpdated}
|
||||||
RMDir /r "$APPDATA\${APP_PACKAGE_NAME}"
|
|
||||||
RMDir /r "$APPDATA\hydra"
|
|
||||||
RMDir /r "$LOCALAPPDATA\hydralauncher-updater"
|
RMDir /r "$LOCALAPPDATA\hydralauncher-updater"
|
||||||
${endIf}
|
${endIf}
|
||||||
!macroend
|
!macroend
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
"developers": "Desarrolladores",
|
"developers": "Desarrolladores",
|
||||||
"genres": "Géneros",
|
"genres": "Géneros",
|
||||||
"tags": "Marcadores",
|
"tags": "Marcadores",
|
||||||
"publishers": "Distribuidoras",
|
"publishers": "Editores",
|
||||||
"download_sources": "Fuentes de descarga",
|
"download_sources": "Fuentes de descarga",
|
||||||
"result_count": "{{resultCount}} resultados",
|
"result_count": "{{resultCount}} resultados",
|
||||||
"filter_count": "{{filterCount}} disponibles",
|
"filter_count": "{{filterCount}} disponibles",
|
||||||
@ -175,7 +175,7 @@
|
|||||||
"backup_from": "Copia de seguridad de {{date}}",
|
"backup_from": "Copia de seguridad de {{date}}",
|
||||||
"custom_backup_location_set": "Se configuró la carpeta de copia de seguridad",
|
"custom_backup_location_set": "Se configuró la carpeta de copia de seguridad",
|
||||||
"clear": "Limpiar",
|
"clear": "Limpiar",
|
||||||
"no_directory_selected": "No se seleccionó un directório"
|
"no_directory_selected": "No se seleccionó un directorio"
|
||||||
},
|
},
|
||||||
"activation": {
|
"activation": {
|
||||||
"title": "Activar Hydra",
|
"title": "Activar Hydra",
|
||||||
@ -208,7 +208,11 @@
|
|||||||
"queued": "En cola",
|
"queued": "En cola",
|
||||||
"no_downloads_title": "Esto está tan... vacío",
|
"no_downloads_title": "Esto está tan... vacío",
|
||||||
"no_downloads_description": "No has descargado nada con Hydra... aún, ¡pero nunca es tarde para comenzar!.",
|
"no_downloads_description": "No has descargado nada con Hydra... aún, ¡pero nunca es tarde para comenzar!.",
|
||||||
"checking_files": "Verificando archivos…"
|
"checking_files": "Verificando archivos…",
|
||||||
|
"seeding": "Seeding",
|
||||||
|
"stop_seeding": "Detener seeding",
|
||||||
|
"resume_seeding": "Continuar seeding",
|
||||||
|
"options": "Gestionar"
|
||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"downloads_path": "Ruta de descarga",
|
"downloads_path": "Ruta de descarga",
|
||||||
@ -265,7 +269,9 @@
|
|||||||
"user_unblocked": "El usuario ha sido desbloqueado",
|
"user_unblocked": "El usuario ha sido desbloqueado",
|
||||||
"enable_achievement_notifications": "Cuando un logro se desbloquea",
|
"enable_achievement_notifications": "Cuando un logro se desbloquea",
|
||||||
"launch_minimized": "Iniciar Hydra minimizado",
|
"launch_minimized": "Iniciar Hydra minimizado",
|
||||||
"disable_nsfw_alert": "Desactivar alerta NSFW"
|
"disable_nsfw_alert": "Desactivar alerta NSFW",
|
||||||
|
"seed_after_download_complete": "Realizar seeding después de que se completa la descarga",
|
||||||
|
"show_hidden_achievement_description": "Ocultar descripción de logros ocultos antes de desbloquearlos"
|
||||||
},
|
},
|
||||||
"notifications": {
|
"notifications": {
|
||||||
"download_complete": "Descarga completada",
|
"download_complete": "Descarga completada",
|
||||||
@ -366,7 +372,16 @@
|
|||||||
"upload_banner": "Subir un banner",
|
"upload_banner": "Subir un banner",
|
||||||
"uploading_banner": "Subiendo banner…",
|
"uploading_banner": "Subiendo banner…",
|
||||||
"background_image_updated": "Imagen de fondo actualizada",
|
"background_image_updated": "Imagen de fondo actualizada",
|
||||||
"playing": "Jugando {{game}}"
|
"playing": "Jugando {{game}}",
|
||||||
|
"achievements": "logros",
|
||||||
|
"achievements_unlocked": "Logros desbloqueados",
|
||||||
|
"earned_points": "Puntos Obtenidos",
|
||||||
|
"show_achievements_on_profile": "Mostrar tus logros en tu perfil",
|
||||||
|
"show_points_on_profile": "Mostrar tus puntos obtenidos en tu perfil",
|
||||||
|
"games": "Juegos",
|
||||||
|
"ranking_updated_weekly": "El Ranking se actualiza semanalmente",
|
||||||
|
"stats": "Estadísticas",
|
||||||
|
"top_percentile": "Top {{percentile}}%"
|
||||||
},
|
},
|
||||||
"achievement": {
|
"achievement": {
|
||||||
"achievement_unlocked": "Logro desbloqueado",
|
"achievement_unlocked": "Logro desbloqueado",
|
||||||
@ -376,7 +391,12 @@
|
|||||||
"subscription_needed": "Se necesita una suscripción a Hydra Cloud necesita para ver este contenido",
|
"subscription_needed": "Se necesita una suscripción a Hydra Cloud necesita para ver este contenido",
|
||||||
"new_achievements_unlocked": "Desbloqueados {{achievementCount}} nuevos logros de {{gameCount}} juegos",
|
"new_achievements_unlocked": "Desbloqueados {{achievementCount}} nuevos logros de {{gameCount}} juegos",
|
||||||
"achievement_progress": "{{unlockedCount}}/{{totalCount}} logros",
|
"achievement_progress": "{{unlockedCount}}/{{totalCount}} logros",
|
||||||
"achievements_unlocked_for_game": "Se han desbloqueado {{achievementCount}} nuevos logros de {{gameTitle}}"
|
"achievements_unlocked_for_game": "Se han desbloqueado {{achievementCount}} nuevos logros de {{gameTitle}}",
|
||||||
|
"hidden_achievement_tooltip": "Este es un logro oculto",
|
||||||
|
"achievement_earn_points": "Obtén {{points}} puntos con este logro",
|
||||||
|
"earned_points": "Puntos obtenidos:",
|
||||||
|
"available_points": "Puntos disponibles:",
|
||||||
|
"how_to_earn_achievements_points": "¿Cómo obtener puntos de logros?"
|
||||||
},
|
},
|
||||||
"hydra_cloud": {
|
"hydra_cloud": {
|
||||||
"subscription_tour_title": "Suscripción Hydra Cloud",
|
"subscription_tour_title": "Suscripción Hydra Cloud",
|
||||||
@ -386,6 +406,9 @@
|
|||||||
"animated_profile_picture": "Fotos de perfil animadas",
|
"animated_profile_picture": "Fotos de perfil animadas",
|
||||||
"premium_support": "Soporte Premium",
|
"premium_support": "Soporte Premium",
|
||||||
"show_and_compare_achievements": "Muestra y compara tus logros con otros usuarios",
|
"show_and_compare_achievements": "Muestra y compara tus logros con otros usuarios",
|
||||||
"animated_profile_banner": "Fondo de perfil animado"
|
"animated_profile_banner": "Fondo de perfil animado",
|
||||||
|
"hydra_cloud": "Hydra Cloud",
|
||||||
|
"hydra_cloud_feature_found": "¡Has descubierto una característica de Hydra Cloud!",
|
||||||
|
"learn_more": "Aprender más"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,7 +244,7 @@ export class DownloadManager {
|
|||||||
private static async getDownloadPayload(game: Game) {
|
private static async getDownloadPayload(game: Game) {
|
||||||
switch (game.downloader) {
|
switch (game.downloader) {
|
||||||
case Downloader.Gofile: {
|
case Downloader.Gofile: {
|
||||||
const id = game!.uri!.split("/").pop();
|
const id = game.uri!.split("/").pop();
|
||||||
|
|
||||||
const token = await GofileApi.authorize();
|
const token = await GofileApi.authorize();
|
||||||
const downloadLink = await GofileApi.getDownloadLink(id!);
|
const downloadLink = await GofileApi.getDownloadLink(id!);
|
||||||
@ -258,7 +258,7 @@ export class DownloadManager {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
case Downloader.PixelDrain: {
|
case Downloader.PixelDrain: {
|
||||||
const id = game!.uri!.split("/").pop();
|
const id = game.uri!.split("/").pop();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
action: "start",
|
action: "start",
|
||||||
|
@ -2,14 +2,17 @@ import type { GameShop } from "@types";
|
|||||||
|
|
||||||
import Color from "color";
|
import Color from "color";
|
||||||
|
|
||||||
export const formatDownloadProgress = (progress?: number) => {
|
export const formatDownloadProgress = (
|
||||||
|
progress?: number,
|
||||||
|
fractionDigits?: number
|
||||||
|
) => {
|
||||||
if (!progress) return "0%";
|
if (!progress) return "0%";
|
||||||
const progressPercentage = progress * 100;
|
const progressPercentage = progress * 100;
|
||||||
|
|
||||||
if (Number(progressPercentage.toFixed(2)) % 1 === 0)
|
if (Number(progressPercentage.toFixed(fractionDigits ?? 2)) % 1 === 0)
|
||||||
return `${Math.floor(progressPercentage)}%`;
|
return `${Math.floor(progressPercentage)}%`;
|
||||||
|
|
||||||
return `${progressPercentage.toFixed(2)}%`;
|
return `${progressPercentage.toFixed(fractionDigits ?? 2)}%`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getSteamLanguage = (language: string) => {
|
export const getSteamLanguage = (language: string) => {
|
||||||
|
@ -228,3 +228,11 @@ export const link = style({
|
|||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const gameCardStats = style({
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
transition: "transform 0.5s ease-in-out",
|
||||||
|
flexShrink: "0",
|
||||||
|
flexGrow: "0",
|
||||||
|
});
|
||||||
|
@ -1,31 +1,27 @@
|
|||||||
import { userProfileContext } from "@renderer/context";
|
import { userProfileContext } from "@renderer/context";
|
||||||
import { useCallback, useContext, useEffect, useMemo } from "react";
|
import { useContext, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { ProfileHero } from "../profile-hero/profile-hero";
|
import { ProfileHero } from "../profile-hero/profile-hero";
|
||||||
import { useAppDispatch, useFormat } from "@renderer/hooks";
|
import { useAppDispatch, useFormat } from "@renderer/hooks";
|
||||||
import { setHeaderTitle } from "@renderer/features";
|
import { setHeaderTitle } from "@renderer/features";
|
||||||
import { steamUrlBuilder } from "@shared";
|
import { SPACING_UNIT } from "@renderer/theme.css";
|
||||||
import { SPACING_UNIT, vars } from "@renderer/theme.css";
|
|
||||||
|
|
||||||
import * as styles from "./profile-content.css";
|
import * as styles from "./profile-content.css";
|
||||||
import { ClockIcon, TelescopeIcon, TrophyIcon } from "@primer/octicons-react";
|
import { TelescopeIcon } from "@primer/octicons-react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { LockedProfile } from "./locked-profile";
|
import { LockedProfile } from "./locked-profile";
|
||||||
import { ReportProfile } from "../report-profile/report-profile";
|
import { ReportProfile } from "../report-profile/report-profile";
|
||||||
import { FriendsBox } from "./friends-box";
|
import { FriendsBox } from "./friends-box";
|
||||||
import { RecentGamesBox } from "./recent-games-box";
|
import { RecentGamesBox } from "./recent-games-box";
|
||||||
import type { UserGame } from "@types";
|
|
||||||
import {
|
|
||||||
buildGameAchievementPath,
|
|
||||||
buildGameDetailsPath,
|
|
||||||
formatDownloadProgress,
|
|
||||||
} from "@renderer/helpers";
|
|
||||||
import { MAX_MINUTES_TO_SHOW_IN_PLAYTIME } from "@renderer/constants";
|
|
||||||
import { UserStatsBox } from "./user-stats-box";
|
import { UserStatsBox } from "./user-stats-box";
|
||||||
import HydraIcon from "@renderer/assets/icons/hydra.svg?react";
|
import { UserLibraryGameCard } from "./user-library-game-card";
|
||||||
|
|
||||||
|
const GAME_STATS_ANIMATION_DURATION_IN_MS = 3500;
|
||||||
|
|
||||||
export function ProfileContent() {
|
export function ProfileContent() {
|
||||||
const { userProfile, isMe, userStats } = useContext(userProfileContext);
|
const { userProfile, isMe, userStats } = useContext(userProfileContext);
|
||||||
|
const [statsIndex, setStatsIndex] = useState(0);
|
||||||
|
const [isAnimationRunning, setIsAnimationRunning] = useState(true);
|
||||||
|
const statsAnimation = useRef(-1);
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
@ -39,6 +35,35 @@ export function ProfileContent() {
|
|||||||
}
|
}
|
||||||
}, [userProfile, dispatch]);
|
}, [userProfile, dispatch]);
|
||||||
|
|
||||||
|
const handleOnMouseEnterGameCard = () => {
|
||||||
|
setIsAnimationRunning(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOnMouseLeaveGameCard = () => {
|
||||||
|
setIsAnimationRunning(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let zero = performance.now();
|
||||||
|
if (!isAnimationRunning) return;
|
||||||
|
|
||||||
|
statsAnimation.current = requestAnimationFrame(
|
||||||
|
function animateGameStats(time) {
|
||||||
|
if (time - zero <= GAME_STATS_ANIMATION_DURATION_IN_MS) {
|
||||||
|
statsAnimation.current = requestAnimationFrame(animateGameStats);
|
||||||
|
} else {
|
||||||
|
setStatsIndex((index) => index + 1);
|
||||||
|
zero = performance.now();
|
||||||
|
statsAnimation.current = requestAnimationFrame(animateGameStats);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
cancelAnimationFrame(statsAnimation.current);
|
||||||
|
};
|
||||||
|
}, [setStatsIndex, isAnimationRunning]);
|
||||||
|
|
||||||
const { numberFormatter } = useFormat();
|
const { numberFormatter } = useFormat();
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@ -47,42 +72,6 @@ export function ProfileContent() {
|
|||||||
return userProfile?.relation?.status === "ACCEPTED";
|
return userProfile?.relation?.status === "ACCEPTED";
|
||||||
}, [userProfile]);
|
}, [userProfile]);
|
||||||
|
|
||||||
const buildUserGameDetailsPath = useCallback(
|
|
||||||
(game: UserGame) => {
|
|
||||||
if (!userProfile?.hasActiveSubscription || game.achievementCount === 0) {
|
|
||||||
return buildGameDetailsPath({
|
|
||||||
...game,
|
|
||||||
objectId: game.objectId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const userParams = userProfile
|
|
||||||
? {
|
|
||||||
userId: userProfile.id,
|
|
||||||
}
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
return buildGameAchievementPath({ ...game }, userParams);
|
|
||||||
},
|
|
||||||
[userProfile]
|
|
||||||
);
|
|
||||||
|
|
||||||
const formatPlayTime = useCallback(
|
|
||||||
(playTimeInSeconds = 0) => {
|
|
||||||
const minutes = playTimeInSeconds / 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) });
|
|
||||||
},
|
|
||||||
[numberFormatter, t]
|
|
||||||
);
|
|
||||||
|
|
||||||
const content = useMemo(() => {
|
const content = useMemo(() => {
|
||||||
if (!userProfile) return null;
|
if (!userProfile) return null;
|
||||||
|
|
||||||
@ -129,137 +118,13 @@ export function ProfileContent() {
|
|||||||
|
|
||||||
<ul className={styles.gamesGrid}>
|
<ul className={styles.gamesGrid}>
|
||||||
{userProfile?.libraryGames?.map((game) => (
|
{userProfile?.libraryGames?.map((game) => (
|
||||||
<li
|
<UserLibraryGameCard
|
||||||
|
game={game}
|
||||||
key={game.objectId}
|
key={game.objectId}
|
||||||
style={{
|
statIndex={statsIndex}
|
||||||
borderRadius: 4,
|
onMouseEnter={handleOnMouseEnterGameCard}
|
||||||
overflow: "hidden",
|
onMouseLeave={handleOnMouseLeaveGameCard}
|
||||||
position: "relative",
|
/>
|
||||||
display: "flex",
|
|
||||||
}}
|
|
||||||
title={game.title}
|
|
||||||
className={styles.game}
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
style={{
|
|
||||||
cursor: "pointer",
|
|
||||||
}}
|
|
||||||
className={styles.gameCover}
|
|
||||||
onClick={() => navigate(buildUserGameDetailsPath(game))}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: "absolute",
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "column",
|
|
||||||
alignItems: "flex-start",
|
|
||||||
justifyContent: "space-between",
|
|
||||||
height: "100%",
|
|
||||||
width: "100%",
|
|
||||||
background:
|
|
||||||
"linear-gradient(0deg, rgba(0, 0, 0, 0.75) 25%, transparent 100%)",
|
|
||||||
padding: 8,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<small
|
|
||||||
style={{
|
|
||||||
backgroundColor: vars.color.background,
|
|
||||||
color: vars.color.muted,
|
|
||||||
border: `solid 1px ${vars.color.border}`,
|
|
||||||
borderRadius: 4,
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: 4,
|
|
||||||
padding: "4px",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<ClockIcon size={11} />
|
|
||||||
{formatPlayTime(game.playTimeInSeconds)}
|
|
||||||
</small>
|
|
||||||
|
|
||||||
{userProfile.hasActiveSubscription &&
|
|
||||||
game.achievementCount > 0 && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
color: "#fff",
|
|
||||||
width: "100%",
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "column",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{game.achievementsPointsEarnedSum > 0 && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: "flex",
|
|
||||||
justifyContent: "start",
|
|
||||||
gap: 8,
|
|
||||||
marginBottom: 4,
|
|
||||||
color: vars.color.muted,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<HydraIcon width={16} height={16} />
|
|
||||||
{numberFormatter.format(
|
|
||||||
game.achievementsPointsEarnedSum
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: "flex",
|
|
||||||
justifyContent: "space-between",
|
|
||||||
marginBottom: 8,
|
|
||||||
color: vars.color.muted,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: 8,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<TrophyIcon size={13} />
|
|
||||||
<span>
|
|
||||||
{game.unlockedAchievementCount} /{" "}
|
|
||||||
{game.achievementCount}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<span>
|
|
||||||
{formatDownloadProgress(
|
|
||||||
game.unlockedAchievementCount /
|
|
||||||
game.achievementCount
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<progress
|
|
||||||
max={1}
|
|
||||||
value={
|
|
||||||
game.unlockedAchievementCount /
|
|
||||||
game.achievementCount
|
|
||||||
}
|
|
||||||
className={styles.achievementsProgressBar}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<img
|
|
||||||
src={steamUrlBuilder.cover(game.objectId)}
|
|
||||||
alt={game.title}
|
|
||||||
style={{
|
|
||||||
objectFit: "cover",
|
|
||||||
borderRadius: 4,
|
|
||||||
width: "100%",
|
|
||||||
height: "100%",
|
|
||||||
minWidth: "100%",
|
|
||||||
minHeight: "100%",
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
</>
|
</>
|
||||||
@ -271,7 +136,6 @@ export function ProfileContent() {
|
|||||||
<UserStatsBox />
|
<UserStatsBox />
|
||||||
<RecentGamesBox />
|
<RecentGamesBox />
|
||||||
<FriendsBox />
|
<FriendsBox />
|
||||||
|
|
||||||
<ReportProfile />
|
<ReportProfile />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@ -284,9 +148,8 @@ export function ProfileContent() {
|
|||||||
userStats,
|
userStats,
|
||||||
numberFormatter,
|
numberFormatter,
|
||||||
t,
|
t,
|
||||||
buildUserGameDetailsPath,
|
|
||||||
formatPlayTime,
|
|
||||||
navigate,
|
navigate,
|
||||||
|
statsIndex,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -0,0 +1,227 @@
|
|||||||
|
import { UserGame } from "@types";
|
||||||
|
import * as styles from "./profile-content.css";
|
||||||
|
import HydraIcon from "@renderer/assets/icons/hydra.svg?react";
|
||||||
|
import { useFormat } from "@renderer/hooks";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { useCallback, useContext } from "react";
|
||||||
|
import {
|
||||||
|
buildGameAchievementPath,
|
||||||
|
buildGameDetailsPath,
|
||||||
|
formatDownloadProgress,
|
||||||
|
} from "@renderer/helpers";
|
||||||
|
import { userProfileContext } from "@renderer/context";
|
||||||
|
import { vars } from "@renderer/theme.css";
|
||||||
|
import { ClockIcon, TrophyIcon } from "@primer/octicons-react";
|
||||||
|
import { MAX_MINUTES_TO_SHOW_IN_PLAYTIME } from "@renderer/constants";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { steamUrlBuilder } from "@shared";
|
||||||
|
|
||||||
|
interface UserLibraryGameCardProps {
|
||||||
|
game: UserGame;
|
||||||
|
statIndex: number;
|
||||||
|
onMouseEnter: () => void;
|
||||||
|
onMouseLeave: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function UserLibraryGameCard({
|
||||||
|
game,
|
||||||
|
statIndex,
|
||||||
|
onMouseEnter,
|
||||||
|
onMouseLeave,
|
||||||
|
}: UserLibraryGameCardProps) {
|
||||||
|
const { userProfile } = useContext(userProfileContext);
|
||||||
|
const { t } = useTranslation("user_profile");
|
||||||
|
const { numberFormatter } = useFormat();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const getStatsItemCount = useCallback(() => {
|
||||||
|
let statsCount = 1;
|
||||||
|
if (game.achievementsPointsEarnedSum > 0) statsCount++;
|
||||||
|
return statsCount;
|
||||||
|
}, [game]);
|
||||||
|
|
||||||
|
const buildUserGameDetailsPath = useCallback(
|
||||||
|
(game: UserGame) => {
|
||||||
|
if (!userProfile?.hasActiveSubscription || game.achievementCount === 0) {
|
||||||
|
return buildGameDetailsPath({
|
||||||
|
...game,
|
||||||
|
objectId: game.objectId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const userParams = userProfile
|
||||||
|
? {
|
||||||
|
userId: userProfile.id,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
return buildGameAchievementPath({ ...game }, userParams);
|
||||||
|
},
|
||||||
|
[userProfile]
|
||||||
|
);
|
||||||
|
|
||||||
|
const formatAchievementPoints = (number: number) => {
|
||||||
|
if (number < 100_000) return numberFormatter.format(number);
|
||||||
|
|
||||||
|
if (number < 1_000_000) return `${(number / 1000).toFixed(1)}K`;
|
||||||
|
|
||||||
|
return `${(number / 1_000_000).toFixed(1)}M`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatPlayTime = useCallback(
|
||||||
|
(playTimeInSeconds = 0) => {
|
||||||
|
const minutes = playTimeInSeconds / 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) });
|
||||||
|
},
|
||||||
|
[numberFormatter, t]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<li
|
||||||
|
onMouseEnter={onMouseEnter}
|
||||||
|
onMouseLeave={onMouseLeave}
|
||||||
|
style={{
|
||||||
|
borderRadius: 4,
|
||||||
|
overflow: "hidden",
|
||||||
|
position: "relative",
|
||||||
|
display: "flex",
|
||||||
|
}}
|
||||||
|
title={game.title}
|
||||||
|
className={styles.game}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
style={{
|
||||||
|
cursor: "pointer",
|
||||||
|
}}
|
||||||
|
className={styles.gameCover}
|
||||||
|
onClick={() => navigate(buildUserGameDetailsPath(game))}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: "absolute",
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
alignItems: "flex-start",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
height: "100%",
|
||||||
|
width: "100%",
|
||||||
|
background:
|
||||||
|
"linear-gradient(0deg, rgba(0, 0, 0, 0.70) 20%, transparent 100%)",
|
||||||
|
padding: 8,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<small
|
||||||
|
style={{
|
||||||
|
backgroundColor: vars.color.background,
|
||||||
|
color: vars.color.muted,
|
||||||
|
border: `solid 1px ${vars.color.border}`,
|
||||||
|
borderRadius: 4,
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 4,
|
||||||
|
padding: "4px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ClockIcon size={11} />
|
||||||
|
{formatPlayTime(game.playTimeInSeconds)}
|
||||||
|
</small>
|
||||||
|
|
||||||
|
{userProfile?.hasActiveSubscription && game.achievementCount > 0 && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: "100%",
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
marginBottom: 8,
|
||||||
|
color: vars.color.muted,
|
||||||
|
overflow: "hidden",
|
||||||
|
height: 18,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className={styles.gameCardStats}
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 8,
|
||||||
|
transform: `translateY(${-100 * (statIndex % getStatsItemCount())}%)`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TrophyIcon size={13} />
|
||||||
|
<span>
|
||||||
|
{game.unlockedAchievementCount} / {game.achievementCount}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{game.achievementsPointsEarnedSum > 0 && (
|
||||||
|
<div
|
||||||
|
className={styles.gameCardStats}
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
gap: 5,
|
||||||
|
transform: `translateY(${-100 * (statIndex % getStatsItemCount())}%)`,
|
||||||
|
alignItems: "center",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<HydraIcon width={16} height={16} />
|
||||||
|
{formatAchievementPoints(
|
||||||
|
game.achievementsPointsEarnedSum
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span>
|
||||||
|
{formatDownloadProgress(
|
||||||
|
game.unlockedAchievementCount / game.achievementCount,
|
||||||
|
1
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<progress
|
||||||
|
max={1}
|
||||||
|
value={game.unlockedAchievementCount / game.achievementCount}
|
||||||
|
className={styles.achievementsProgressBar}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<img
|
||||||
|
src={steamUrlBuilder.cover(game.objectId)}
|
||||||
|
alt={game.title}
|
||||||
|
style={{
|
||||||
|
objectFit: "cover",
|
||||||
|
borderRadius: 4,
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
minWidth: "100%",
|
||||||
|
minHeight: "100%",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user