Fixed errors not being displayed
This commit is contained in:
parent
2354602e6d
commit
fe718fdfec
@ -1,24 +1,28 @@
|
||||
package app.app
|
||||
package app
|
||||
|
||||
import app.di.TabScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.withContext
|
||||
import javax.inject.Inject
|
||||
|
||||
@TabScope
|
||||
class ErrorsManager @Inject constructor() {
|
||||
private val _errorsList = MutableStateFlow(listOf<Error>())
|
||||
val errorsList: StateFlow<List<Error>>
|
||||
get() = _errorsList
|
||||
|
||||
private val _lastError = MutableStateFlow<Error?>(null)
|
||||
val lastError: StateFlow<Error?>
|
||||
get() = _lastError
|
||||
val lastError: StateFlow<Error?> = _lastError
|
||||
|
||||
fun addError(error: Error) {
|
||||
suspend fun addError(error: Error) = withContext(Dispatchers.IO) {
|
||||
_errorsList.value = _errorsList.value.toMutableList().apply {
|
||||
add(error)
|
||||
}
|
||||
|
||||
_lastError.value = error
|
||||
println("LastError flow: ${_lastError.value}")
|
||||
}
|
||||
|
||||
fun removeError(error: Error) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package app.git
|
||||
|
||||
import app.app.Error
|
||||
import app.app.newErrorNow
|
||||
import app.ErrorsManager
|
||||
import app.newErrorNow
|
||||
import app.di.TabScope
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -18,7 +18,9 @@ import javax.inject.Inject
|
||||
import kotlin.coroutines.cancellation.CancellationException
|
||||
|
||||
@TabScope
|
||||
class TabState @Inject constructor() {
|
||||
class TabState @Inject constructor(
|
||||
val errorsManager: ErrorsManager,
|
||||
) {
|
||||
var git: Git? = null
|
||||
val safeGit: Git
|
||||
get() {
|
||||
@ -34,10 +36,7 @@ class TabState @Inject constructor() {
|
||||
|
||||
private val _refreshData = MutableSharedFlow<RefreshType>()
|
||||
val refreshData: Flow<RefreshType> = _refreshData
|
||||
suspend fun refreshData(refreshType: RefreshType) = _refreshData.emit(refreshType)
|
||||
|
||||
private val _errors = MutableSharedFlow<Error>()
|
||||
val errors: Flow<Error> = _errors
|
||||
val managerScope = CoroutineScope(SupervisorJob())
|
||||
|
||||
|
||||
@ -65,7 +64,7 @@ class TabState @Inject constructor() {
|
||||
ex.printStackTrace()
|
||||
|
||||
if (showError)
|
||||
_errors.emit(newErrorNow(ex, ex.localizedMessage))
|
||||
errorsManager.addError(newErrorNow(ex, ex.localizedMessage))
|
||||
} finally {
|
||||
_processing.value = false
|
||||
operationRunning = false
|
||||
@ -88,7 +87,7 @@ class TabState @Inject constructor() {
|
||||
ex.printStackTrace()
|
||||
|
||||
if (showError)
|
||||
_errors.emit(newErrorNow(ex, ex.localizedMessage))
|
||||
errorsManager.addError(newErrorNow(ex, ex.localizedMessage))
|
||||
} finally {
|
||||
_processing.value = false
|
||||
operationRunning = false
|
||||
|
@ -37,12 +37,16 @@ fun AppTab(
|
||||
val lastError by errorManager.lastError.collectAsState()
|
||||
var showError by remember { mutableStateOf(false) }
|
||||
|
||||
if (lastError != null)
|
||||
println("lastError $lastError")
|
||||
|
||||
|
||||
if (lastError != null) {
|
||||
LaunchedEffect(lastError) {
|
||||
showError = true
|
||||
delay(5000)
|
||||
showError = false
|
||||
}
|
||||
}
|
||||
|
||||
val repositorySelectionStatus by tabViewModel.repositorySelectionStatus.collectAsState()
|
||||
val isProcessing by tabViewModel.processing.collectAsState()
|
||||
@ -68,7 +72,6 @@ fun AppTab(
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
Crossfade(targetState = repositorySelectionStatus) {
|
||||
|
||||
@Suppress("UnnecessaryVariable") // Don't inline it because smart cast won't work
|
||||
when (repositorySelectionStatus) {
|
||||
RepositorySelectionStatus.None -> {
|
||||
@ -90,6 +93,7 @@ fun AppTab(
|
||||
|
||||
val safeLastError = lastError
|
||||
if (safeLastError != null) {
|
||||
println("safeLastError $safeLastError\nshowError $showError")
|
||||
AnimatedVisibility(
|
||||
visible = showError,
|
||||
modifier = Modifier
|
||||
@ -122,7 +126,7 @@ fun AppTab(
|
||||
) // TODO Add more descriptive title
|
||||
|
||||
Text(
|
||||
text = safeLastError.message,
|
||||
text = lastError?.message ?: "",
|
||||
modifier = Modifier
|
||||
.padding(top = 8.dp, bottom = 16.dp)
|
||||
.widthIn(max = 600.dp)
|
||||
|
@ -1,16 +1,19 @@
|
||||
package app.viewmodels
|
||||
|
||||
import app.AppStateManager
|
||||
import app.app.ErrorsManager
|
||||
import app.app.newErrorNow
|
||||
import app.ErrorsManager
|
||||
import app.newErrorNow
|
||||
import app.credentials.CredentialsState
|
||||
import app.credentials.CredentialsStateManager
|
||||
import app.git.*
|
||||
import app.ui.SelectedItem
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.lib.ObjectId
|
||||
import org.eclipse.jgit.lib.Repository
|
||||
@ -34,10 +37,10 @@ class TabViewModel @Inject constructor(
|
||||
private val repositoryManager: RepositoryManager,
|
||||
private val remoteOperationsManager: RemoteOperationsManager,
|
||||
private val tabState: TabState,
|
||||
val errorsManager: ErrorsManager,
|
||||
val appStateManager: AppStateManager,
|
||||
private val fileChangesWatcher: FileChangesWatcher,
|
||||
) {
|
||||
val errorsManager: ErrorsManager = tabState.errorsManager
|
||||
private val _selectedItem = MutableStateFlow<SelectedItem>(SelectedItem.None)
|
||||
val selectedItem: StateFlow<SelectedItem> = _selectedItem
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user