mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: create achievements page
This commit is contained in:
parent
6d4f957e2b
commit
39af661720
8 changed files with 76 additions and 20 deletions
|
@ -1,13 +1,19 @@
|
||||||
import type { GameAchievement, GameShop } from "@types";
|
import type { GameAchievement, GameShop, UnlockedAchievement } from "@types";
|
||||||
import { registerEvent } from "../register-event";
|
import { registerEvent } from "../register-event";
|
||||||
import { gameAchievementRepository } from "@main/repository";
|
import {
|
||||||
|
gameAchievementRepository,
|
||||||
|
userAuthRepository,
|
||||||
|
} from "@main/repository";
|
||||||
import { getGameAchievementData } from "@main/services/achievements/get-game-achievement-data";
|
import { getGameAchievementData } from "@main/services/achievements/get-game-achievement-data";
|
||||||
|
import { HydraApi } from "@main/services";
|
||||||
|
|
||||||
const getGameAchievements = async (
|
const getAchievements = async (
|
||||||
_event: Electron.IpcMainInvokeEvent,
|
shop: string,
|
||||||
objectId: string,
|
objectId: string,
|
||||||
shop: GameShop
|
userId?: string
|
||||||
): Promise<GameAchievement[]> => {
|
) => {
|
||||||
|
const userAuth = await userAuthRepository.findOne({ where: { userId } });
|
||||||
|
|
||||||
const cachedAchievements = await gameAchievementRepository.findOne({
|
const cachedAchievements = await gameAchievementRepository.findOne({
|
||||||
where: { objectId, shop },
|
where: { objectId, shop },
|
||||||
});
|
});
|
||||||
|
@ -16,9 +22,33 @@ const getGameAchievements = async (
|
||||||
? JSON.parse(cachedAchievements.achievements)
|
? JSON.parse(cachedAchievements.achievements)
|
||||||
: await getGameAchievementData(objectId, shop);
|
: await getGameAchievementData(objectId, shop);
|
||||||
|
|
||||||
const unlockedAchievements = JSON.parse(
|
if (!userId || userAuth) {
|
||||||
cachedAchievements?.unlockedAchievements || "[]"
|
const unlockedAchievements = JSON.parse(
|
||||||
) as { name: string; unlockTime: number }[];
|
cachedAchievements?.unlockedAchievements || "[]"
|
||||||
|
) as UnlockedAchievement[];
|
||||||
|
|
||||||
|
return { achievementsData, unlockedAchievements };
|
||||||
|
}
|
||||||
|
|
||||||
|
const unlockedAchievements = await HydraApi.get<UnlockedAchievement[]>(
|
||||||
|
`/users/${userId}/games/achievements`,
|
||||||
|
{ shop, objectId, language: "en" }
|
||||||
|
);
|
||||||
|
|
||||||
|
return { achievementsData, unlockedAchievements };
|
||||||
|
};
|
||||||
|
|
||||||
|
const getGameAchievements = async (
|
||||||
|
_event: Electron.IpcMainInvokeEvent,
|
||||||
|
objectId: string,
|
||||||
|
shop: GameShop,
|
||||||
|
userId?: string
|
||||||
|
): Promise<GameAchievement[]> => {
|
||||||
|
const { achievementsData, unlockedAchievements } = await getAchievements(
|
||||||
|
shop,
|
||||||
|
objectId,
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
|
||||||
return achievementsData
|
return achievementsData
|
||||||
.map((achievementData) => {
|
.map((achievementData) => {
|
||||||
|
|
|
@ -49,8 +49,8 @@ contextBridge.exposeInMainWorld("electron", {
|
||||||
getGameStats: (objectId: string, shop: GameShop) =>
|
getGameStats: (objectId: string, shop: GameShop) =>
|
||||||
ipcRenderer.invoke("getGameStats", objectId, shop),
|
ipcRenderer.invoke("getGameStats", objectId, shop),
|
||||||
getTrendingGames: () => ipcRenderer.invoke("getTrendingGames"),
|
getTrendingGames: () => ipcRenderer.invoke("getTrendingGames"),
|
||||||
getGameAchievements: (objectId: string, shop: GameShop) =>
|
getGameAchievements: (objectId: string, shop: GameShop, userId?: string) =>
|
||||||
ipcRenderer.invoke("getGameAchievements", objectId, shop),
|
ipcRenderer.invoke("getGameAchievements", objectId, shop, userId),
|
||||||
onAchievementUnlocked: (
|
onAchievementUnlocked: (
|
||||||
cb: (
|
cb: (
|
||||||
objectId: string,
|
objectId: string,
|
||||||
|
|
3
src/renderer/src/declaration.d.ts
vendored
3
src/renderer/src/declaration.d.ts
vendored
|
@ -68,7 +68,8 @@ declare global {
|
||||||
getTrendingGames: () => Promise<TrendingGame[]>;
|
getTrendingGames: () => Promise<TrendingGame[]>;
|
||||||
getGameAchievements: (
|
getGameAchievements: (
|
||||||
objectId: string,
|
objectId: string,
|
||||||
shop: GameShop
|
shop: GameShop,
|
||||||
|
userId?: string
|
||||||
) => Promise<GameAchievement[]>;
|
) => Promise<GameAchievement[]>;
|
||||||
onAchievementUnlocked: (
|
onAchievementUnlocked: (
|
||||||
cb: (
|
cb: (
|
||||||
|
|
|
@ -28,10 +28,11 @@ import {
|
||||||
import { store } from "./store";
|
import { store } from "./store";
|
||||||
|
|
||||||
import resources from "@locales";
|
import resources from "@locales";
|
||||||
import { Achievement } from "./pages/achievement/achievement";
|
import { AchievementNotification } from "./pages/achievement/notification/achievement-notification";
|
||||||
|
|
||||||
import "./workers";
|
import "./workers";
|
||||||
import { RepacksContextProvider } from "./context";
|
import { RepacksContextProvider } from "./context";
|
||||||
|
import { Achievement } from "./pages/achievement/achievements";
|
||||||
|
|
||||||
Sentry.init({});
|
Sentry.init({});
|
||||||
|
|
||||||
|
@ -69,8 +70,12 @@ ReactDOM.createRoot(document.getElementById("root")!).render(
|
||||||
<Route path="/search" Component={SearchResults} />
|
<Route path="/search" Component={SearchResults} />
|
||||||
<Route path="/settings" Component={Settings} />
|
<Route path="/settings" Component={Settings} />
|
||||||
<Route path="/profile/:userId" Component={Profile} />
|
<Route path="/profile/:userId" Component={Profile} />
|
||||||
|
<Route path="/achievements" Component={Achievement} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/achievement-notification" Component={Achievement} />
|
<Route
|
||||||
|
path="/achievement-notification"
|
||||||
|
Component={AchievementNotification}
|
||||||
|
/>
|
||||||
</Routes>
|
</Routes>
|
||||||
</HashRouter>
|
</HashRouter>
|
||||||
</RepacksContextProvider>
|
</RepacksContextProvider>
|
||||||
|
|
11
src/renderer/src/pages/achievement/achievements.tsx
Normal file
11
src/renderer/src/pages/achievement/achievements.tsx
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import { useSearchParams } from "react-router-dom";
|
||||||
|
|
||||||
|
export function Achievement() {
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>Achievement</h1>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
import { recipe } from "@vanilla-extract/recipes";
|
import { recipe } from "@vanilla-extract/recipes";
|
||||||
import { vars } from "../../theme.css";
|
import { vars } from "../../../theme.css";
|
||||||
import { keyframes, style } from "@vanilla-extract/css";
|
import { keyframes, style } from "@vanilla-extract/css";
|
||||||
|
|
||||||
const animationIn = keyframes({
|
const animationIn = keyframes({
|
|
@ -1,7 +1,7 @@
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import achievementSound from "@renderer/assets/audio/achievement.wav";
|
import achievementSound from "@renderer/assets/audio/achievement.wav";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import * as styles from "./achievement.css";
|
import * as styles from "./achievement-notification.css";
|
||||||
|
|
||||||
interface AchievementInfo {
|
interface AchievementInfo {
|
||||||
displayName: string;
|
displayName: string;
|
||||||
|
@ -10,7 +10,7 @@ interface AchievementInfo {
|
||||||
|
|
||||||
const NOTIFICATION_TIMEOUT = 4000;
|
const NOTIFICATION_TIMEOUT = 4000;
|
||||||
|
|
||||||
export function Achievement() {
|
export function AchievementNotification() {
|
||||||
const { t } = useTranslation("achievement");
|
const { t } = useTranslation("achievement");
|
||||||
|
|
||||||
const [isClosing, setIsClosing] = useState(false);
|
const [isClosing, setIsClosing] = useState(false);
|
|
@ -1,7 +1,7 @@
|
||||||
import { useContext, useState } from "react";
|
import { useContext, useState } from "react";
|
||||||
import type { HowLongToBeatCategory, SteamAppDetails } from "@types";
|
import type { HowLongToBeatCategory, SteamAppDetails } from "@types";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Button } from "@renderer/components";
|
import { Button, Link } from "@renderer/components";
|
||||||
|
|
||||||
import * as styles from "./sidebar.css";
|
import * as styles from "./sidebar.css";
|
||||||
import { gameDetailsContext } from "@renderer/context";
|
import { gameDetailsContext } from "@renderer/context";
|
||||||
|
@ -18,7 +18,7 @@ export function Sidebar() {
|
||||||
const [activeRequirement, setActiveRequirement] =
|
const [activeRequirement, setActiveRequirement] =
|
||||||
useState<keyof SteamAppDetails["pc_requirements"]>("minimum");
|
useState<keyof SteamAppDetails["pc_requirements"]>("minimum");
|
||||||
|
|
||||||
const { gameTitle, shopDetails, stats, achievements } =
|
const { gameTitle, shopDetails, stats, achievements, shop, objectID } =
|
||||||
useContext(gameDetailsContext);
|
useContext(gameDetailsContext);
|
||||||
|
|
||||||
const { t } = useTranslation("game_details");
|
const { t } = useTranslation("game_details");
|
||||||
|
@ -26,6 +26,11 @@ export function Sidebar() {
|
||||||
|
|
||||||
const { numberFormatter } = useFormat();
|
const { numberFormatter } = useFormat();
|
||||||
|
|
||||||
|
const buildGameAchievementPath = () => {
|
||||||
|
const urlParams = new URLSearchParams({ objectId: objectID!, shop });
|
||||||
|
return `/achievements?${urlParams.toString()}`;
|
||||||
|
};
|
||||||
|
|
||||||
// useEffect(() => {
|
// useEffect(() => {
|
||||||
// if (objectID) {
|
// if (objectID) {
|
||||||
// setHowLongToBeat({ isLoading: true, data: null });
|
// setHowLongToBeat({ isLoading: true, data: null });
|
||||||
|
@ -61,6 +66,10 @@ export function Sidebar() {
|
||||||
{achievements.length})
|
{achievements.length})
|
||||||
</span>
|
</span>
|
||||||
</h3>
|
</h3>
|
||||||
|
<span>
|
||||||
|
<Link to={buildGameAchievementPath()}>Ver todas</Link>
|
||||||
|
<a></a>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
|
@ -70,7 +79,7 @@ export function Sidebar() {
|
||||||
padding: `${SPACING_UNIT * 2}px`,
|
padding: `${SPACING_UNIT * 2}px`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{achievements.map((achievement, index) => (
|
{achievements.slice(0, 6).map((achievement, index) => (
|
||||||
<div
|
<div
|
||||||
key={index}
|
key={index}
|
||||||
style={{
|
style={{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue