/* * D8 โ€” drop-in replacement for the private `FeedbackBody` in * `ui/settings/SettingsCardBodies.kt`. * * This file is NOT meant to be added as-is โ€” it lives in the same file as the * other *Body composables and reuses that file's private helpers (SubLabel, * Pill, SubtleButton, Hint). The orchestrator should: * 1. Change the call site at line 78 from `FeedbackBody(fg)` to * `FeedbackBody(fg, vm)`. * 2. Replace the existing `FeedbackBody(fg: Color)` (lines 581-623) with the * `FeedbackBody` below. * 3. Add the imports listed in INTEGRATION.md. * * Behaviour vs. the old version: * - "Send" now calls `vm.sendFeedback(category, message)` instead of flipping * a local `sent` flag. * - State is read from `vm.feedbackState` (FeedbackState): Sending shows a * spinner and disables the button; Sent shows the existing thank-you card; * Error shows an inline breach-coloured message and re-enables Send (retry). * - On entering the card / after a Sent, the VM state resets to Idle (call * `vm.resetFeedback()` from a DisposableEffect โ€” see snippet). */ @OptIn(ExperimentalLayoutApi::class) @Composable private fun FeedbackBody(fg: Color, vm: SettingsViewModel) { val categories = listOf("Bug report", "Feature request", "Question", "Other") var category by remember { mutableStateOf(categories[0]) } var message by remember { mutableStateOf("") } val state by vm.feedbackState.collectAsState() // Reset transient state when the card leaves composition so reopening the // card starts fresh rather than on a stale Sent/Error. DisposableEffect(Unit) { onDispose { vm.resetFeedback() } } if (state is FeedbackState.Sent) { Box( Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(fg.copy(alpha = 0.08f)) .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(10.dp)).padding(16.dp), ) { Column { Text("Thank you", color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp) Text("Your note is in the queue. Someone will process it soon.", color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 12.sp, modifier = Modifier.padding(top = 4.dp)) } } return } val sending = state is FeedbackState.Sending Text("Help us improve Peach. Every report goes directly to our inbox.", color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp) SubLabel("TYPE", fg) FlowRow(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) { categories.forEach { cat -> Pill(cat, category == cat, fg) { if (!sending) category = cat } } } SubLabel("MESSAGE", fg) Box( Modifier.fillMaxWidth().height(110.dp).clip(RoundedCornerShape(8.dp)) .background(Color(0x2E000000)).border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp)) .padding(10.dp), ) { if (message.isEmpty()) Text("Describe the issue or idea...", color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Body, fontSize = 12.sp) BasicTextField( value = message, onValueChange = { message = it }, enabled = !sending, textStyle = TextStyle(color = fg, fontFamily = PeachType.Body, fontSize = 12.sp), cursorBrush = SolidColor(fg), modifier = Modifier.fillMaxWidth(), ) } Spacer(Modifier.height(8.dp)) Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) { // Send is disabled while sending and while the message is blank; on // Error it re-enables to act as a retry. val canSend = !sending && message.isNotBlank() Box( Modifier.clip(RoundedCornerShape(8.dp)) .border(1.dp, fg.copy(alpha = if (canSend) 0.28f else 0.14f), RoundedCornerShape(8.dp)) .background(fg.copy(alpha = if (canSend) 0.08f else 0.04f)) .clickable(enabled = canSend) { vm.sendFeedback(category, message) } .padding(horizontal = 12.dp, vertical = 6.dp), ) { Text( if (state is FeedbackState.Error) "Retry" else "Send", color = fg.copy(alpha = if (canSend) 1f else 0.4f), fontFamily = PeachType.Mono, fontSize = 11.sp, ) } if (sending) { CircularProgressIndicator( color = LocalPeachAccent.current, strokeWidth = 2.dp, modifier = Modifier.size(16.dp), ) } } (state as? FeedbackState.Error)?.let { err -> Text( err.message, modifier = Modifier.padding(top = 8.dp), color = com.peachpasswords.ui.theme.PeachColors.Breach, fontFamily = PeachType.Mono, fontSize = 11.sp, lineHeight = 15.sp, ) } Hint("Sent anonymously ยท no account required", fg) }