mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-09 03:37:45 +03:00
feat: refactor component
This commit is contained in:
parent
065ea0c6fe
commit
89cd970d5a
40
src/renderer/src/pages/achievements/achievement-list.tsx
Normal file
40
src/renderer/src/pages/achievements/achievement-list.tsx
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { useDate } from "@renderer/hooks";
|
||||||
|
import type { UserAchievement } from "@types";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import * as styles from "./achievements.css";
|
||||||
|
|
||||||
|
interface AchievementListProps {
|
||||||
|
achievements: UserAchievement[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AchievementList({ achievements }: AchievementListProps) {
|
||||||
|
const { t } = useTranslation("achievement");
|
||||||
|
const { formatDateTime } = useDate();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ul className={styles.list}>
|
||||||
|
{achievements.map((achievement, index) => (
|
||||||
|
<li key={index} className={styles.listItem} style={{ display: "flex" }}>
|
||||||
|
<img
|
||||||
|
className={styles.listItemImage({
|
||||||
|
unlocked: achievement.unlocked,
|
||||||
|
})}
|
||||||
|
src={achievement.icon}
|
||||||
|
alt={achievement.displayName}
|
||||||
|
loading="lazy"
|
||||||
|
/>
|
||||||
|
<div style={{ flex: 1 }}>
|
||||||
|
<h4>{achievement.displayName}</h4>
|
||||||
|
<p>{achievement.description}</p>
|
||||||
|
</div>
|
||||||
|
{achievement.unlockTime && (
|
||||||
|
<div style={{ whiteSpace: "nowrap" }}>
|
||||||
|
<small>{t("unlocked_at")}</small>
|
||||||
|
<p>{formatDateTime(achievement.unlockTime)}</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
);
|
||||||
|
}
|
@ -1,9 +1,8 @@
|
|||||||
import { setHeaderTitle } from "@renderer/features";
|
import { setHeaderTitle } from "@renderer/features";
|
||||||
import { useAppDispatch, useDate, useUserDetails } from "@renderer/hooks";
|
import { useAppDispatch, useUserDetails } from "@renderer/hooks";
|
||||||
import { steamUrlBuilder } from "@shared";
|
import { steamUrlBuilder } from "@shared";
|
||||||
import { useContext, useEffect, useRef, useState } from "react";
|
import { useContext, useEffect, useRef, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import * as styles from "./achievements.css";
|
|
||||||
import {
|
import {
|
||||||
buildGameDetailsPath,
|
buildGameDetailsPath,
|
||||||
formatDownloadProgress,
|
formatDownloadProgress,
|
||||||
@ -11,11 +10,13 @@ import {
|
|||||||
import { LockIcon, PersonIcon, TrophyIcon } from "@primer/octicons-react";
|
import { LockIcon, PersonIcon, TrophyIcon } from "@primer/octicons-react";
|
||||||
import { SPACING_UNIT, vars } from "@renderer/theme.css";
|
import { SPACING_UNIT, vars } from "@renderer/theme.css";
|
||||||
import { gameDetailsContext } from "@renderer/context";
|
import { gameDetailsContext } from "@renderer/context";
|
||||||
import type { ComparedAchievements, UserAchievement } from "@types";
|
import type { ComparedAchievements } from "@types";
|
||||||
import { average } from "color.js";
|
import { average } from "color.js";
|
||||||
import Color from "color";
|
import Color from "color";
|
||||||
import { Link } from "@renderer/components";
|
import { Link } from "@renderer/components";
|
||||||
import { ComparedAchievementList } from "./compared-achievement-list";
|
import { ComparedAchievementList } from "./compared-achievement-list";
|
||||||
|
import * as styles from "./achievements.css";
|
||||||
|
import { AchievementList } from "./achievement-list";
|
||||||
|
|
||||||
interface UserInfo {
|
interface UserInfo {
|
||||||
id: string;
|
id: string;
|
||||||
@ -30,10 +31,6 @@ interface AchievementsContentProps {
|
|||||||
comparedAchievements: ComparedAchievements | null;
|
comparedAchievements: ComparedAchievements | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AchievementListProps {
|
|
||||||
achievements: UserAchievement[];
|
|
||||||
}
|
|
||||||
|
|
||||||
interface AchievementSummaryProps {
|
interface AchievementSummaryProps {
|
||||||
user: UserInfo;
|
user: UserInfo;
|
||||||
isComparison?: boolean;
|
isComparison?: boolean;
|
||||||
@ -171,38 +168,6 @@ function AchievementSummary({ user, isComparison }: AchievementSummaryProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function AchievementList({ achievements }: AchievementListProps) {
|
|
||||||
const { t } = useTranslation("achievement");
|
|
||||||
const { formatDateTime } = useDate();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ul className={styles.list}>
|
|
||||||
{achievements.map((achievement, index) => (
|
|
||||||
<li key={index} className={styles.listItem} style={{ display: "flex" }}>
|
|
||||||
<img
|
|
||||||
className={styles.listItemImage({
|
|
||||||
unlocked: achievement.unlocked,
|
|
||||||
})}
|
|
||||||
src={achievement.icon}
|
|
||||||
alt={achievement.displayName}
|
|
||||||
loading="lazy"
|
|
||||||
/>
|
|
||||||
<div style={{ flex: 1 }}>
|
|
||||||
<h4>{achievement.displayName}</h4>
|
|
||||||
<p>{achievement.description}</p>
|
|
||||||
</div>
|
|
||||||
{achievement.unlockTime && (
|
|
||||||
<div style={{ whiteSpace: "nowrap" }}>
|
|
||||||
<small>{t("unlocked_at")}</small>
|
|
||||||
<p>{formatDateTime(achievement.unlockTime)}</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function AchievementsContent({
|
export function AchievementsContent({
|
||||||
otherUser,
|
otherUser,
|
||||||
comparedAchievements,
|
comparedAchievements,
|
||||||
|
@ -35,6 +35,7 @@ export interface AchievementData {
|
|||||||
icon: string;
|
icon: string;
|
||||||
icongray: string;
|
icongray: string;
|
||||||
hidden: boolean;
|
hidden: boolean;
|
||||||
|
points?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserAchievement {
|
export interface UserAchievement {
|
||||||
|
Loading…
Reference in New Issue
Block a user