fix(t209): retain login inputs after failure

This commit is contained in:
QiuSW
2026-07-27 16:03:08 +08:00
parent f99744e2ed
commit 5782c3088d
4 changed files with 38 additions and 18 deletions
@@ -358,9 +358,7 @@ class MainActivity : ComponentActivity() {
state = procurementState,
readiness = readiness,
onLogin = { input: LoginInput ->
lifecycleScope.launch {
procurementRepository.login(input)
}
procurementRepository.login(input)
},
onClaim = {
lifecycleScope.launch {
@@ -34,6 +34,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@@ -50,12 +51,13 @@ import com.roubao.autopilot.readiness.DeviceReadinessSnapshot
import com.roubao.autopilot.ui.theme.BaoziTheme
import java.time.Instant
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
@Composable
fun ProcurementScreen(
state: ProcurementUiState,
readiness: DeviceReadinessSnapshot,
onLogin: (LoginInput) -> Unit,
onLogin: suspend (LoginInput) -> Boolean,
onClaim: () -> Unit,
onStart: (ExecutionMode) -> Unit,
onRelease: () -> Unit,
@@ -260,9 +262,10 @@ private fun ExecutionModeSelector(
@Composable
private fun LoginSection(
state: ProcurementUiState,
onLogin: (LoginInput) -> Unit
onLogin: suspend (LoginInput) -> Boolean
) {
val colors = BaoziTheme.colors
val coroutineScope = rememberCoroutineScope()
var backendUrl by remember(state.profile.backendUrl) {
mutableStateOf(state.profile.backendUrl)
}
@@ -274,6 +277,7 @@ private fun LoginSection(
mutableStateOf(state.profile.deviceId)
}
var deviceToken by remember { mutableStateOf("") }
var submitting by remember { mutableStateOf(false) }
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
Text(
@@ -329,19 +333,28 @@ private fun LoginSection(
)
Button(
onClick = {
onLogin(
LoginInput(
if (!submitting) {
val input = LoginInput(
backendUrl = backendUrl,
username = username,
password = password,
deviceId = deviceId,
deviceToken = deviceToken
)
)
password = ""
deviceToken = ""
submitting = true
coroutineScope.launch {
try {
if (onLogin(input)) {
password = ""
deviceToken = ""
}
} finally {
submitting = false
}
}
}
},
enabled = !state.busy,
enabled = !state.busy && !submitting,
modifier = Modifier.fillMaxWidth()
) {
Icon(Icons.Filled.Lock, contentDescription = null)