From 5ff633fc4d88806a1a0c6e7656153bab2c29120b Mon Sep 17 00:00:00 2001 From: Eugene Date: Mon, 14 Sep 2026 19:28:39 +0300 Subject: [PATCH] test --- .../presentation/auth/AuthComponent.kt | 11 +++-- .../gigawear/presentation/auth/AuthScreen.kt | 5 +- .../presentation/chat/ChatComponent.kt | 46 ++++++++++--------- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/auth/AuthComponent.kt b/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/auth/AuthComponent.kt index ac54132..918d378 100644 --- a/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/auth/AuthComponent.kt +++ b/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/auth/AuthComponent.kt @@ -25,21 +25,22 @@ class AuthComponent( private val authRepository: AuthRepository, private val goToChat: () -> Unit ) : ComponentContext by context { - private val scope = coroutineScope(SupervisorJob() + Dispatchers.Main.immediate) - private val _state = MutableStateFlow(AuthState()) - val state = _state.asStateFlow() private val exceptionHandler = CoroutineExceptionHandler { _, throwable -> _state.value = AuthState(isLoading = false, error = throwable) } + private val scope = coroutineScope(exceptionHandler + SupervisorJob() + Dispatchers.Main.immediate) + private val _state = MutableStateFlow(AuthState()) + val state = _state.asStateFlow() + init { - scope.launch(exceptionHandler) { + scope.launch { if (tokenStorage.token.firstOrNull() != null) goToChat() } } fun login(code: Int) { - scope.launch(exceptionHandler) { + scope.launch { _state.value = AuthState(isLoading = true, error = null) val token = authRepository.login(LoginRequest(code)) tokenStorage.updateToken(token) diff --git a/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/auth/AuthScreen.kt b/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/auth/AuthScreen.kt index 219f25d..3984d23 100644 --- a/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/auth/AuthScreen.kt +++ b/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/auth/AuthScreen.kt @@ -89,11 +89,12 @@ private fun CodeStep( } } + val title = stringResource(R.string.auth_code_title) val openCodeInput = { val intent = RemoteInputIntentHelper.createActionRemoteInputIntent() val remoteInputs = listOf( RemoteInput.Builder(CODE_INPUT_KEY) - .setLabel("Код") + .setLabel(title) .build() ) RemoteInputIntentHelper.putRemoteInputsExtra(intent, remoteInputs) @@ -107,7 +108,7 @@ private fun CodeStep( ) { item { WearText( - text = stringResource(R.string.auth_code_title), + text = title, style = MaterialTheme.typography.bodyMedium ) } diff --git a/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/chat/ChatComponent.kt b/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/chat/ChatComponent.kt index e04f646..e7f4602 100644 --- a/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/chat/ChatComponent.kt +++ b/apps/giga-wear/client/src/main/kotlin/ru/shadowsparky/gigawear/presentation/chat/ChatComponent.kt @@ -2,11 +2,14 @@ package ru.shadowsparky.gigawear.presentation.chat import com.arkivanov.decompose.ComponentContext import com.arkivanov.decompose.childContext -import com.arkivanov.decompose.value.MutableValue -import com.arkivanov.decompose.value.Value -import com.arkivanov.decompose.value.update import com.arkivanov.essenty.lifecycle.coroutines.coroutineScope +import kotlinx.coroutines.CoroutineExceptionHandler +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.launch import org.koin.core.annotation.Factory @@ -25,11 +28,15 @@ class ChatComponent( private val repository: ChatRepository, private val updateComponentFactory: UpdateComponentFactory ) : ComponentContext by context { - private val scope = coroutineScope() + private val _state = MutableStateFlow(ChatUiState()) + val state: StateFlow = _state.asStateFlow() + + private val exceptionHandler = CoroutineExceptionHandler { _, throwable -> + _state.value = ChatUiState(isLoading = false, error = throwable) + } + private val scope = coroutineScope(exceptionHandler + SupervisorJob() + Dispatchers.Main.immediate) val updateComponent = updateComponentFactory.create(childContext("updater")) - private val _state = MutableValue(ChatUiState()) - val state: Value = _state private val _events = Channel(Channel.BUFFERED) val events = _events.receiveAsFlow() @@ -46,21 +53,17 @@ class ChatComponent( fun onSpeechRecognized(text: String) { _state.value = _state.value.copy(userText = text, isLoading = true, error = null) scope.launch { - try { - val userMessage = Message( - role = ChatRoles.USER, - content = text, - timestamp = System.currentTimeMillis() - ) - val responseMessage = repository.send(userMessage) - _state.value = _state.value.copy( - assistantText = responseMessage.content, - isLoading = false - ) - _events.send(ComponentEvent.RequestSpeak(responseMessage.content)) - } catch (e: Exception) { - _state.update { it.copy(error = e, isLoading = false) } - } + val userMessage = Message( + role = ChatRoles.USER, + content = text, + timestamp = System.currentTimeMillis() + ) + val responseMessage = repository.send(userMessage) + _state.value = _state.value.copy( + assistantText = responseMessage.content, + isLoading = false + ) + _events.send(ComponentEvent.RequestSpeak(responseMessage.content)) } } @@ -77,7 +80,6 @@ class ChatComponent( ) } - @Factory @Named(Route.CHAT) class ChatComponentFactory(