@@ -33,6 +33,10 @@ export default function ModDashboard({ session }) {
3333 const [ userReportsPage , setUserReportsPage ] = useState ( 1 ) ;
3434 const USER_REPORTS_PER_PAGE = 10 ;
3535
36+ // Game history pagination (lifted from GameHistory to preserve state when viewing a game)
37+ const [ gameHistoryPage , setGameHistoryPage ] = useState ( 1 ) ;
38+ const [ savedScrollPosition , setSavedScrollPosition ] = useState ( 0 ) ;
39+
3640 // Action modal state
3741 const [ actionModal , setActionModal ] = useState ( null ) ;
3842 const [ actionLoading , setActionLoading ] = useState ( false ) ;
@@ -176,6 +180,7 @@ export default function ModDashboard({ session }) {
176180 setTargetUser ( data . targetUser ) ;
177181 setUserHistory ( data . history ) ;
178182 setUserReportsPage ( 1 ) ; // Reset reports pagination
183+ setGameHistoryPage ( 1 ) ; // Reset game history pagination
179184
180185 // Show notice if found by past name
181186 if ( data . foundByPastName ) {
@@ -195,6 +200,8 @@ export default function ModDashboard({ session }) {
195200 } ;
196201
197202 const handleGameClick = ( game ) => {
203+ // Save scroll position before viewing game
204+ setSavedScrollPosition ( window . scrollY ) ;
198205 setSelectedGame ( game ) ;
199206 } ;
200207
@@ -269,6 +276,7 @@ export default function ModDashboard({ session }) {
269276 setTargetUser ( data . targetUser ) ;
270277 setUserHistory ( data . history ) ;
271278 setUserReportsPage ( 1 ) ; // Reset reports pagination
279+ setGameHistoryPage ( 1 ) ; // Reset game history pagination
272280 // Update input if user was found by past name
273281 if ( data . foundByPastName ) {
274282 setUsernameInput ( data . targetUser . username ) ;
@@ -313,6 +321,7 @@ export default function ModDashboard({ session }) {
313321 setUserHistory ( data . history ) ;
314322 setUsernameInput ( data . targetUser . username ) ;
315323 setUserReportsPage ( 1 ) ; // Reset reports pagination
324+ setGameHistoryPage ( 1 ) ; // Reset game history pagination
316325 } else {
317326 const errorData = await response . json ( ) ;
318327 setError ( errorData . message || 'User not found' ) ;
@@ -1123,6 +1132,8 @@ export default function ModDashboard({ session }) {
11231132 onBack = { ( ) => {
11241133 setSelectedGame ( null ) ;
11251134 setReportedUserId ( null ) ;
1135+ // Restore scroll position after component re-renders
1136+ setTimeout ( ( ) => window . scrollTo ( 0 , savedScrollPosition ) , 0 ) ;
11261137 } }
11271138 onUsernameLookup = { handleUsernameLookup }
11281139 options = { {
@@ -1355,9 +1366,8 @@ export default function ModDashboard({ session }) {
13551366 </ div >
13561367 ) }
13571368
1358- { /* Main Dashboard */ }
1359- { ! selectedGame && (
1360- < div className = { styles . modDashboard } >
1369+ { /* Main Dashboard - hidden instead of unmounted when viewing a game to preserve state */ }
1370+ < div className = { styles . modDashboard } style = { { display : selectedGame ? 'none' : undefined } } >
13611371 < div className = { styles . header } >
13621372 < div className = { styles . worldGuessrLogo } >
13631373 < div className = { styles . logoIcon } > 🌍</ div >
@@ -1647,6 +1657,8 @@ export default function ModDashboard({ session }) {
16471657 targetUserSecret = { targetUser . secret }
16481658 targetUserData = { targetUser }
16491659 onGameClick = { handleGameClick }
1660+ page = { gameHistoryPage }
1661+ setPage = { setGameHistoryPage }
16501662 />
16511663 </ div >
16521664 ) : (
@@ -2229,7 +2241,6 @@ export default function ModDashboard({ session }) {
22292241 </ div >
22302242 ) }
22312243 </ div >
2232- ) }
22332244 </ >
22342245 ) ;
22352246}
0 commit comments