Skip to content

Commit

Permalink
Merge pull request #34 from skydoves/remove/toast-ui-state
Browse files Browse the repository at this point in the history
Reset the ui state toast
  • Loading branch information
skydoves authored Dec 16, 2022
2 parents 1d51b2c + 01f060c commit 1a4c92a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import androidx.lifecycle.viewModelScope
import com.skydoves.chatgpt.core.data.repository.GPTChannelRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import io.getstream.chat.android.client.utils.onError
import io.getstream.chat.android.client.utils.onSuccess
import io.getstream.chat.android.client.utils.onSuccessSuspend
import javax.inject.Inject
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -54,8 +55,10 @@ class ChatGPTChannelsViewModel @Inject constructor(
viewModelScope.launch {
channelsMutableUiState.value = GPTChannelUiState.Loading
val result = gptChannelRepository.createRandomChannel()
result.onSuccess {
result.onSuccessSuspend {
channelsMutableUiState.value = GPTChannelUiState.Success(it.id)
delay(100L)
channelsMutableUiState.value = GPTChannelUiState.Nothing
}.onError {
channelsMutableUiState.value = GPTChannelUiState.Error
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ private fun HandleToastMessages(

LaunchedEffect(key1 = error) {
if (error.isNotEmpty()) {
viewModel.sendStreamChatMessage(error)
viewModel.sendStreamChatMessage("$error: ${context.getString(R.string.toast_hello)}")
}
}
}
2 changes: 1 addition & 1 deletion feature-chat/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
<string name="stream_top_bar">Stream</string>
<string name="toast_success_create_channel">A random ChatGPT channel is created!</string>
<string name="toast_hello">Hi, I\'m OpenAI\'s ChatGPT with Stream SDK. Ask me anything!</string>
<string name="toast_error">Something went wrong</string>
<string name="toast_error">Something went wrong. Please re-install this app.</string>
<string name="toast_error_session">Something went wrong. Please check out your session and CF_CLEARANCE is valid.</string>
</resources>

0 comments on commit 1a4c92a

Please sign in to comment.