feat: separate game assets from game stats

This commit is contained in:
Zamitto
2025-10-11 11:26:05 -03:00
parent 6146a1fbf1
commit 9bada771df
14 changed files with 111 additions and 84 deletions

View File

@@ -142,29 +142,23 @@ export function GameDetailsContextProvider({
}
});
const statsPromise = window.electron
.getGameStats(objectId, shop)
.then((result) => {
if (abortController.signal.aborted) return null;
setStats(result);
return result;
});
window.electron.getGameStats(objectId, shop).then((result) => {
if (abortController.signal.aborted) return;
setStats(result);
});
Promise.all([shopDetailsPromise, statsPromise])
.then(([_, stats]) => {
if (stats) {
const assets = stats.assets;
if (assets) {
window.electron.saveGameShopAssets(objectId, shop, assets);
const assetsPromise = window.electron.getGameAssets(objectId, shop);
setShopDetails((prev) => {
if (!prev) return null;
return {
...prev,
assets,
};
});
}
Promise.all([shopDetailsPromise, assetsPromise])
.then(([_, assets]) => {
if (assets) {
setShopDetails((prev) => {
if (!prev) return null;
return {
...prev,
assets,
};
});
}
})
.finally(() => {
@@ -207,8 +201,8 @@ export function GameDetailsContextProvider({
setShowRepacksModal(true);
try {
window.history.replaceState({}, document.title, location.pathname);
} catch (_e) {
void _e;
} catch (e) {
console.error(e);
}
}
}, [location]);

View File

@@ -39,6 +39,7 @@ import type {
AchievementCustomNotificationPosition,
AchievementNotificationInfo,
UserLibraryResponse,
Game,
} from "@types";
import type { AxiosProgressEvent } from "axios";
import type disk from "diskusage";
@@ -77,11 +78,6 @@ declare global {
skip: number
) => Promise<{ edges: CatalogueSearchResult[]; count: number }>;
getCatalogue: (category: CatalogueCategory) => Promise<ShopAssets[]>;
saveGameShopAssets: (
objectId: string,
shop: GameShop,
assets: ShopAssets
) => Promise<void>;
getGameShopDetails: (
objectId: string,
shop: GameShop,
@@ -93,6 +89,10 @@ declare global {
shop: GameShop
) => Promise<HowLongToBeatCategory[] | null>;
getGameStats: (objectId: string, shop: GameShop) => Promise<GameStats>;
getGameAssets: (
objectId: string,
shop: GameShop
) => Promise<ShopAssets | null>;
getTrendingGames: () => Promise<TrendingGame[]>;
createGameReview: (
shop: GameShop,

View File

@@ -233,9 +233,18 @@ export function Sidebar() {
{t("rating_count")}
</p>
<StarRating
rating={stats?.averageScore === 0 ? null : stats?.averageScore ?? null}
rating={
stats?.averageScore === 0
? null
: (stats?.averageScore ?? null)
}
size={16}
showCalculating={!!(stats && (stats.averageScore === null || stats.averageScore === 0))}
showCalculating={
!!(
stats &&
(stats.averageScore === null || stats.averageScore === 0)
)
}
calculatingText={t("calculating", { ns: "game_card" })}
hideIcon={true}
/>

View File

@@ -234,7 +234,7 @@ export function UserLibraryGameCard({
</div>
<img
src={game.coverImageUrl}
src={game.coverImageUrl ?? undefined}
alt={game.title}
className="user-library-game__game-image"
/>