@@ -15,6 +15,9 @@ export function MobileThemeContent() {
1515 const { setTheme, theme } = useTheme ( ) ;
1616 const [ mounted , setMounted ] = useState ( false ) ;
1717 const [ unlockedThemes , setUnlockedThemes ] = useState < Record < ShopId , boolean > > ( ) ;
18+ const [ page , setPage ] = useState < number > ( 0 ) ;
19+ const [ maxPages , setMaxPages ] = useState < number > ( 0 ) ;
20+ const themesPerPage = 3 ;
1821
1922 useEffect ( ( ) => {
2023 setMounted ( true ) ;
@@ -28,21 +31,28 @@ export function MobileThemeContent() {
2831 return ( ) => {
2932 shopUnsubscribe ( ) ;
3033 }
31- } , [ ] )
34+ } , [ ] ) ;
35+
36+ useEffect ( ( ) => {
37+ setMaxPages ( Math . ceil ( Object . keys ( THEME_DATA ) . length / themesPerPage - 1 ) ) ;
38+ } , [ ] ) ;
3239
3340 if ( ! mounted )
3441 return null ;
3542
3643 return (
3744 < div className = "flex flex-col gap-4" >
38- { Object . values ( THEME_DATA ) . map ( ( themeInstance , idx ) => {
45+ { Object . values ( THEME_DATA )
46+ . slice ( page * themesPerPage , page * themesPerPage + themesPerPage )
47+ . map ( ( themeInstance , idx ) => {
3948 const isUnlocked : boolean = [ "light" , "dark" ] . includes ( themeInstance . id )
4049 || unlockedThemes ! [ themeInstance . id . toUpperCase ( ) as ShopId ] == true ;
4150
4251 const isSelected : boolean = isUnlocked && theme == themeInstance . id ;
4352
4453 return (
4554 < Fragment key = { themeInstance . id } >
55+ { idx != 0 && < div className = "my-4 bg-foreground/60 w-full min-h-[1px]" /> }
4656 < div className = "flex flex-row justify-between items-center" >
4757 < div className = "flex flex-row gap-2 items-center" >
4858 < ThemeBox theme = { themeInstance . id } colors = { themeInstance . colors } />
@@ -65,11 +75,19 @@ export function MobileThemeContent() {
6575 { isSelected && < Check /> }
6676 </ Button >
6777 </ div >
68- { idx != Object . keys ( THEME_DATA ) . length - 1 && < div className = "my-4 bg-foreground/60 w-full min-h-[1px]" /> }
6978 </ Fragment >
7079 )
7180 }
7281 ) }
82+ < div className = "flex flex-row justify-between items-center mt-6" >
83+ < Button variant = "outline" size = "icon" onClick = { ( ) => setPage ( page - 1 ) } disabled = { page == 0 } >
84+ < ArrowLeft />
85+ </ Button >
86+ < p > { page + 1 } /{ maxPages + 1 } </ p >
87+ < Button variant = "outline" size = "icon" onClick = { ( ) => setPage ( page + 1 ) } disabled = { page == maxPages } >
88+ < ArrowRight />
89+ </ Button >
90+ </ div >
7391 </ div >
7492 )
7593}
@@ -125,6 +143,9 @@ export function MobileAchievementContent() {
125143
126144export function MobileShopContent ( ) {
127145 const [ fetchedShopItems , setFetchedShopItems ] = useState < ShopItemProps [ ] > ( [ ] )
146+ const [ page , setPage ] = useState < number > ( 0 ) ;
147+ const [ maxPages , setMaxPages ] = useState < number > ( 0 ) ;
148+ const itemsPerPage = 3 ;
128149
129150 useEffect ( ( ) => {
130151 setFetchedShopItems ( shop . fetchItems ( ) ) ;
@@ -138,21 +159,36 @@ export function MobileShopContent() {
138159 shopUnsubscribe ( ) ;
139160 }
140161 } , [ ] )
162+
163+ useEffect ( ( ) => {
164+ setMaxPages ( Math . ceil ( fetchedShopItems . length / itemsPerPage - 1 ) ) ;
165+ } )
166+
141167 return (
142168 < div >
143169 < div className = "flex flex-row items-center justify-center gap-1 text-foreground/60 mb-4" >
144170 < h1 className = "w-fit" > { shop . getPoints ( ) } </ h1 >
145171 < BadgeCent className = "w-4 h-4" />
146172 </ div >
147- { fetchedShopItems . map ( ( props , idx ) =>
173+ { fetchedShopItems
174+ . slice ( page * itemsPerPage , page * itemsPerPage + itemsPerPage )
175+ . map ( ( props , idx ) =>
148176 < Fragment key = { props . title } >
177+ { idx != 0 && < div className = "my-6 bg-foreground/60 w-full min-h-[1px]" /> }
149178 < ShopItem
150179 { ...props }
151180 />
152- { idx != fetchedShopItems . length - 1 &&
153- < div className = "my-6 bg-foreground/60 w-full min-h-[1px]" /> }
154181 </ Fragment >
155182 ) }
183+ < div className = "flex flex-row justify-between items-center mt-6" >
184+ < Button variant = "outline" size = "icon" onClick = { ( ) => setPage ( page - 1 ) } disabled = { page == 0 } >
185+ < ArrowLeft />
186+ </ Button >
187+ < p > { page + 1 } /{ maxPages + 1 } </ p >
188+ < Button variant = "outline" size = "icon" onClick = { ( ) => setPage ( page + 1 ) } disabled = { page == maxPages } >
189+ < ArrowRight />
190+ </ Button >
191+ </ div >
156192 </ div >
157193 )
158194}
0 commit comments