refactor(tui): extract selectedPendingApproval() extension and unify call sites
Add TuiState.selectedPendingApproval() extension and replace the three inline session-lookup expressions in InputReducer and RouterPanel with it.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.correx.apps.tui.components
|
package com.correx.apps.tui.components
|
||||||
|
|
||||||
import com.correx.apps.tui.state.TuiState
|
import com.correx.apps.tui.state.TuiState
|
||||||
|
import com.correx.apps.tui.state.selectedPendingApproval
|
||||||
import dev.tamboui.style.Style
|
import dev.tamboui.style.Style
|
||||||
import dev.tamboui.text.Line
|
import dev.tamboui.text.Line
|
||||||
import dev.tamboui.text.Span
|
import dev.tamboui.text.Span
|
||||||
@@ -23,7 +24,7 @@ fun routerPanelWidget(state: TuiState): Paragraph {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val activeApproval = state.sessions.sessions.find { it.id == state.sessions.selectedId }?.pendingApproval
|
val activeApproval = state.selectedPendingApproval()
|
||||||
val overlayLines: List<Line> = when {
|
val overlayLines: List<Line> = when {
|
||||||
state.approvalOverlayVisible && activeApproval != null -> {
|
state.approvalOverlayVisible && activeApproval != null -> {
|
||||||
buildList {
|
buildList {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.correx.apps.server.protocol.ClientMessage
|
|||||||
import com.correx.apps.tui.input.Action
|
import com.correx.apps.tui.input.Action
|
||||||
import com.correx.apps.tui.state.InputMode
|
import com.correx.apps.tui.state.InputMode
|
||||||
import com.correx.apps.tui.state.TuiState
|
import com.correx.apps.tui.state.TuiState
|
||||||
|
import com.correx.apps.tui.state.selectedPendingApproval
|
||||||
import com.correx.core.events.types.ApprovalRequestId
|
import com.correx.core.events.types.ApprovalRequestId
|
||||||
|
|
||||||
object InputReducer {
|
object InputReducer {
|
||||||
@@ -25,7 +26,7 @@ object InputReducer {
|
|||||||
|
|
||||||
is Action.OpenNewSessionPrompt -> state.copy(inputMode = InputMode.ROUTER, inputBuffer = "") to emptyList()
|
is Action.OpenNewSessionPrompt -> state.copy(inputMode = InputMode.ROUTER, inputBuffer = "") to emptyList()
|
||||||
is Action.OpenSteeringPrompt -> {
|
is Action.OpenSteeringPrompt -> {
|
||||||
val active = state.sessions.sessions.find { it.id == state.sessions.selectedId }?.pendingApproval
|
val active = state.selectedPendingApproval()
|
||||||
if (active != null) {
|
if (active != null) {
|
||||||
state.copy(inputMode = InputMode.STEER, inputBuffer = "") to emptyList()
|
state.copy(inputMode = InputMode.STEER, inputBuffer = "") to emptyList()
|
||||||
} else {
|
} else {
|
||||||
@@ -52,7 +53,7 @@ object InputReducer {
|
|||||||
|
|
||||||
InputMode.STEER -> {
|
InputMode.STEER -> {
|
||||||
val text = state.inputBuffer.trim()
|
val text = state.inputBuffer.trim()
|
||||||
val active = state.sessions.sessions.find { it.id == state.sessions.selectedId }?.pendingApproval
|
val active = state.selectedPendingApproval()
|
||||||
if (active != null && text.isNotBlank()) {
|
if (active != null && text.isNotBlank()) {
|
||||||
state.copy(inputMode = InputMode.ROUTER, inputBuffer = "") to listOf(
|
state.copy(inputMode = InputMode.ROUTER, inputBuffer = "") to listOf(
|
||||||
Effect.SendWs(
|
Effect.SendWs(
|
||||||
|
|||||||
@@ -75,3 +75,6 @@ data class ApprovalInfo(
|
|||||||
val toolName: String?,
|
val toolName: String?,
|
||||||
val preview: String?,
|
val preview: String?,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun TuiState.selectedPendingApproval(): ApprovalInfo? =
|
||||||
|
sessions.sessions.find { it.id == sessions.selectedId }?.pendingApproval
|
||||||
|
|||||||
Reference in New Issue
Block a user