feat(chess): add dismiss/clear-all for finished games in lobby
Persist dismissed game IDs locally (SharedPreferences on Android, java.util.prefs on Desktop) so completed games can be permanently hidden from the chess lobby. Adds per-game dismiss button and "Clear all" action when 2+ finished games exist. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+22
-6
@@ -53,6 +53,7 @@ import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
@@ -339,6 +340,8 @@ fun ChessScreen(
|
||||
onOpenOwnChallenge = { viewModel.openOwnChallenge(it) },
|
||||
onWatchGame = { viewModel.loadGameAsSpectator(it) },
|
||||
onSelectGame = { viewModel.selectGame(it) },
|
||||
onDismissGame = { viewModel.dismissCompletedGame(it) },
|
||||
onDismissAllGames = { viewModel.dismissAllCompletedGames() },
|
||||
listState = listState,
|
||||
)
|
||||
}
|
||||
@@ -372,6 +375,8 @@ private fun ChessLobby(
|
||||
onOpenOwnChallenge: (ChessChallenge) -> Unit,
|
||||
onWatchGame: (String) -> Unit,
|
||||
onSelectGame: (String) -> Unit,
|
||||
onDismissGame: (String) -> Unit,
|
||||
onDismissAllGames: () -> Unit,
|
||||
listState: LazyListState = rememberLazyListState(),
|
||||
) {
|
||||
val hasContent =
|
||||
@@ -581,12 +586,22 @@ private fun ChessLobby(
|
||||
if (completedGames.isNotEmpty()) {
|
||||
item {
|
||||
Spacer(Modifier.height(16.dp))
|
||||
Text(
|
||||
"Recent Games",
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
fontWeight = FontWeight.Bold,
|
||||
modifier = Modifier.padding(vertical = 8.dp),
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(
|
||||
"Recent Games",
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
fontWeight = FontWeight.Bold,
|
||||
)
|
||||
if (completedGames.size >= 2) {
|
||||
TextButton(onClick = onDismissAllGames) {
|
||||
Text("Clear all")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
items(
|
||||
@@ -603,6 +618,7 @@ private fun ChessLobby(
|
||||
isDraw = game.isDraw,
|
||||
moveCount = game.moveCount,
|
||||
onClick = { onSelectGame(game.gameId) },
|
||||
onDismiss = { onDismissGame(game.gameId) },
|
||||
avatar = {
|
||||
UserAvatar(
|
||||
userHex = opponentPubkey,
|
||||
|
||||
+7
@@ -22,6 +22,7 @@ package com.vitorpamplona.amethyst.desktop.chess
|
||||
|
||||
import com.vitorpamplona.amethyst.commons.chess.ChessBroadcastStatus
|
||||
import com.vitorpamplona.amethyst.commons.chess.ChessChallenge
|
||||
import com.vitorpamplona.amethyst.commons.chess.ChessDismissedGamesStorage
|
||||
import com.vitorpamplona.amethyst.commons.chess.ChessLobbyLogic
|
||||
import com.vitorpamplona.amethyst.commons.chess.ChessPollingDefaults
|
||||
import com.vitorpamplona.amethyst.commons.chess.ChessSyncStatus
|
||||
@@ -59,6 +60,7 @@ class DesktopChessViewModelNew(
|
||||
private val publisher = DesktopChessPublisher(account, relayManager)
|
||||
private val fetcher = DesktopRelayFetcher(relayManager, account.pubKeyHex)
|
||||
private val metadataProvider = DesktopMetadataProvider(userMetadataCache)
|
||||
private val dismissedStorage = ChessDismissedGamesStorage.create()
|
||||
|
||||
// Shared business logic (creates its own ChessLobbyState internally)
|
||||
private val logic =
|
||||
@@ -69,6 +71,7 @@ class DesktopChessViewModelNew(
|
||||
metadataProvider = metadataProvider,
|
||||
scope = scope,
|
||||
pollingConfig = ChessPollingDefaults.desktop,
|
||||
dismissedStorage = dismissedStorage,
|
||||
)
|
||||
|
||||
// ============================================
|
||||
@@ -164,6 +167,10 @@ class DesktopChessViewModelNew(
|
||||
|
||||
fun dismissGame(gameId: String) = logic.dismissGame(gameId)
|
||||
|
||||
fun dismissCompletedGame(gameId: String) = logic.dismissCompletedGame(gameId)
|
||||
|
||||
fun dismissAllCompletedGames() = logic.dismissAllCompletedGames()
|
||||
|
||||
// ============================================
|
||||
// Spectator operations
|
||||
// ============================================
|
||||
|
||||
Reference in New Issue
Block a user