@@ -2,8 +2,8 @@ import { For } from "solid-js";
22import type { Stats } from "~/types" ;
33
44const GuessDistributionRow = ( props : { v : number ; i : number ; p : number } ) => (
5- < div class = "guess-row " >
6- < div class = "guess-label " > { props . i + 1 } </ div >
5+ < div class = "flex items-center w-9/10 " >
6+ < div class = "w-5 text-right mr-2.5 font-bold text-base " > { props . i + 1 } </ div >
77 < div class = "guess-bar" >
88 < div class = "guess-bar-fill" style = { { width : `${ props . p } %` } } />
99 < div class = "guess-count" > { props . v } </ div >
@@ -12,7 +12,7 @@ const GuessDistributionRow = (props: { v: number; i: number; p: number }) => (
1212) ;
1313
1414const GuessDistribution = ( props : { guessDistribution : number [ ] } ) => (
15- < div id = "guess-distribution ">
15+ < div class = "flex flex-col gap-[5px] w-full ">
1616 < For each = { props . guessDistribution } >
1717 { ( v , i ) => (
1818 < GuessDistributionRow
@@ -25,43 +25,41 @@ const GuessDistribution = (props: { guessDistribution: number[] }) => (
2525 </ div >
2626) ;
2727
28+ const StatBox = ( props : {
29+ id ?: string ;
30+ value : string | number ;
31+ label : string ;
32+ } ) => (
33+ < div class = "stat-box" >
34+ < div class = "text-2xl font-bold mb-[5px]" id = { props . id } >
35+ { props . value }
36+ </ div >
37+ < div class = "text-base" > { props . label } </ div >
38+ </ div >
39+ ) ;
40+
41+ const getNormalizedPercentage = ( part : number , total : number ) =>
42+ total === 0 ? 0 : Math . round ( ( part / total ) * 100 ) ;
43+
2844const StatsContainer = ( props : { stats : Stats } ) => (
29- < div id = "stats-container" class = "content-container" >
30- < div id = "stats-grid" >
31- < div class = "stat-box" >
32- < div class = "stat-number" id = "games-played" >
33- { props . stats . gamesPlayed }
34- </ div >
35- < div class = "stat-label" > Played</ div >
36- </ div >
45+ < div class = "content-container" >
46+ < div class = "grid grid-cols-2 gap-5 mb-5" >
47+ < StatBox label = "Played" value = { props . stats . gamesPlayed } />
3748
38- < div class = "stat-box" >
39- < div class = "stat-number" id = "win-percentage" >
40- { props . stats . gamesPlayed === 0
41- ? "0%"
42- : Math . round (
43- ( props . stats . gamesWon / props . stats . gamesPlayed ) * 100
44- ) + "%" }
45- </ div >
46- < div class = "stat-label" > Win %</ div >
47- </ div >
49+ < StatBox
50+ label = "Win %"
51+ value = { `${ getNormalizedPercentage (
52+ props . stats . gamesWon ,
53+ props . stats . gamesPlayed
54+ ) } %`}
55+ />
4856
49- < div class = "stat-box" >
50- < div class = "stat-number" id = "current-streak" >
51- { props . stats . currentStreak }
52- </ div >
53- < div class = "stat-label" > Current Streak</ div >
54- </ div >
57+ < StatBox label = "Current Streak" value = { props . stats . currentStreak } />
5558
56- < div class = "stat-box" >
57- < div class = "stat-number" id = "max-streak" >
58- { props . stats . maxStreak }
59- </ div >
60- < div class = "stat-label" > Max Streak</ div >
61- </ div >
59+ < StatBox label = "Max Streak" value = { props . stats . maxStreak } />
6260 </ div >
6361
64- < h3 class = "my-[10px] " > Guess Distribution</ h3 >
62+ < h3 class = "font-bold text-lg text-center my-2.5 " > Guess Distribution</ h3 >
6563
6664 < GuessDistribution guessDistribution = { props . stats . guessDistribution } />
6765 </ div >
0 commit comments