11import { LibraryGame } from "@types" ;
22import { useGameCard } from "@renderer/hooks" ;
33import { ClockIcon , AlertFillIcon , TrophyIcon } from "@primer/octicons-react" ;
4- import { memo , useMemo } from "react" ;
4+ import { memo , useEffect , useMemo , useState } from "react" ;
55import "./library-game-card-large.scss" ;
66
77interface LibraryGameCardLargeProps {
@@ -48,6 +48,20 @@ export const LibraryGameCardLarge = memo(function LibraryGameCardLarge({
4848 ]
4949 ) ;
5050
51+ const [ unlockedAchievementsCount , setUnlockedAchievementsCount ] = useState (
52+ game . unlockedAchievementCount ?? 0
53+ ) ;
54+
55+ useEffect ( ( ) => {
56+ if ( game . unlockedAchievementCount ) return ;
57+
58+ window . electron
59+ . getUnlockedAchievements ( game . objectId , game . shop )
60+ . then ( ( achievements ) => {
61+ setUnlockedAchievementsCount ( achievements . length ) ;
62+ } ) ;
63+ } , [ game ] ) ;
64+
5165 const backgroundStyle = useMemo (
5266 ( ) =>
5367 backgroundImage ? { backgroundImage : `url(${ backgroundImage } )` } : { } ,
@@ -56,9 +70,9 @@ export const LibraryGameCardLarge = memo(function LibraryGameCardLarge({
5670
5771 const achievementBarStyle = useMemo (
5872 ( ) => ( {
59- width : `${ ( ( game . unlockedAchievementCount ?? 0 ) / ( game . achievementCount ?? 1 ) ) * 100 } %` ,
73+ width : `${ ( unlockedAchievementsCount / ( game . achievementCount ?? 1 ) ) * 100 } %` ,
6074 } ) ,
61- [ game . unlockedAchievementCount , game . achievementCount ]
75+ [ unlockedAchievementsCount , game . achievementCount ]
6276 ) ;
6377
6478 const logoImage = game . customLogoImageUrl ?? game . logoImageUrl ;
@@ -116,14 +130,12 @@ export const LibraryGameCardLarge = memo(function LibraryGameCardLarge({
116130 className = "library-game-card-large__achievement-trophy"
117131 />
118132 < span className = "library-game-card-large__achievement-count" >
119- { game . unlockedAchievementCount ?? 0 } /{ " " }
120- { game . achievementCount ?? 0 }
133+ { unlockedAchievementsCount } / { game . achievementCount ?? 0 }
121134 </ span >
122135 </ div >
123136 < span className = "library-game-card-large__achievement-percentage" >
124137 { Math . round (
125- ( ( game . unlockedAchievementCount ?? 0 ) /
126- ( game . achievementCount ?? 1 ) ) *
138+ ( unlockedAchievementsCount / ( game . achievementCount ?? 1 ) ) *
127139 100
128140 ) }
129141 %
0 commit comments