diff --git a/src/main/events/catalogue/get-trending-games.ts b/src/main/events/catalogue/get-trending-games.ts new file mode 100644 index 00000000..8f8e02c0 --- /dev/null +++ b/src/main/events/catalogue/get-trending-games.ts @@ -0,0 +1,22 @@ +import { registerEvent } from "../register-event"; +import { HydraApi } from "@main/services"; +import { userPreferencesRepository } from "@main/repository"; +import { TrendingGame } from "@types"; + +const getTrendingGames = async (_event: Electron.IpcMainInvokeEvent) => { + const userPreferences = await userPreferencesRepository.findOne({ + where: { id: 1 }, + }); + + const language = userPreferences?.language || "en"; + + const trendingGames = await HydraApi.get( + "/games/trending", + { language }, + { needsAuth: false } + ).catch(() => []); + + return trendingGames; +}; + +registerEvent("getTrendingGames", getTrendingGames); diff --git a/src/main/events/index.ts b/src/main/events/index.ts index e12ce19f..d44510ac 100644 --- a/src/main/events/index.ts +++ b/src/main/events/index.ts @@ -9,6 +9,7 @@ import "./catalogue/get-random-game"; import "./catalogue/search-games"; import "./catalogue/search-game-repacks"; import "./catalogue/get-game-stats"; +import "./catalogue/get-trending-games"; import "./hardware/get-disk-free-space"; import "./library/add-game-to-library"; import "./library/create-game-shortcut"; diff --git a/src/preload/index.ts b/src/preload/index.ts index 3c71eff1..ac22e37d 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -48,6 +48,7 @@ contextBridge.exposeInMainWorld("electron", { ipcRenderer.invoke("searchGameRepacks", query), getGameStats: (objectId: string, shop: GameShop) => ipcRenderer.invoke("getGameStats", objectId, shop), + getTrendingGames: () => ipcRenderer.invoke("getTrendingGames"), /* User preferences */ getUserPreferences: () => ipcRenderer.invoke("getUserPreferences"), diff --git a/src/renderer/src/components/hero/hero.tsx b/src/renderer/src/components/hero/hero.tsx index fbb6e171..df0f8a7f 100644 --- a/src/renderer/src/components/hero/hero.tsx +++ b/src/renderer/src/components/hero/hero.tsx @@ -1,17 +1,14 @@ import { useNavigate } from "react-router-dom"; import * as styles from "./hero.css"; import { useEffect, useState } from "react"; -import { ShopDetails } from "@types"; -import { buildGameDetailsPath, getSteamLanguage } from "@renderer/helpers"; +import { TrendingGame } from "@types"; import { useTranslation } from "react-i18next"; -import { steamUrlBuilder } from "@shared"; - -const FEATURED_GAME_TITLE = "ELDEN RING"; -const FEATURED_GAME_ID = "1245620"; +import Skeleton from "react-loading-skeleton"; export function Hero() { - const [featuredGameDetails, setFeaturedGameDetails] = - useState(null); + const [featuredGameDetails, setFeaturedGameDetails] = useState< + TrendingGame[] | null + >(null); const [isLoading, setIsLoading] = useState(false); const { i18n } = useTranslation(); @@ -22,11 +19,7 @@ export function Hero() { setIsLoading(true); window.electron - .getGameShopDetails( - FEATURED_GAME_ID, - "steam", - getSteamLanguage(i18n.language) - ) + .getTrendingGames() .then((result) => { setFeaturedGameDetails(result); }) @@ -35,41 +28,32 @@ export function Hero() { }); }, [i18n.language]); - return ( - - ); + + )); + } + + return null; } diff --git a/src/renderer/src/declaration.d.ts b/src/renderer/src/declaration.d.ts index 0b406b41..3d34b647 100644 --- a/src/renderer/src/declaration.d.ts +++ b/src/renderer/src/declaration.d.ts @@ -21,6 +21,7 @@ import type { UserBlocks, UpdateProfileRequest, GameStats, + TrendingGame, } from "@types"; import type { DiskSpace } from "check-disk-space"; @@ -60,6 +61,7 @@ declare global { ) => Promise<{ results: CatalogueEntry[]; cursor: number }>; searchGameRepacks: (query: string) => Promise; getGameStats: (objectId: string, shop: GameShop) => Promise; + getTrendingGames: () => Promise; /* Library */ addGameToLibrary: ( diff --git a/src/types/index.ts b/src/types/index.ts index a2ca7409..e6c2a039 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -345,3 +345,9 @@ export interface GameStats { downloadCount: number; playerCount: number; } + +export interface TrendingGame { + uri: string; + description: string; + background: string; +}