Skip to content

Commit

Permalink
Merge pull request #758 from enaboapps/iss757
Browse files Browse the repository at this point in the history
Improve setup screen
  • Loading branch information
OwenMcGirr authored Nov 7, 2024
2 parents cbbda48 + a6c431d commit 810e83f
Show file tree
Hide file tree
Showing 4 changed files with 265 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,6 @@ fun SwitchesScreen(navController: NavController) {
}
}

uiState.error != null -> {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Text(
text = uiState.error!!,
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.error
)
}
}

else -> {
Column(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class SwitchesScreenModel(private val store: SwitchEventStore) : ViewModel() {
}
.onFailure { error ->
_uiState.value = _uiState.value.copy(
error = error.message ?: "Failed to load remote switches",
isLoading = false
)
}
Expand All @@ -65,7 +64,6 @@ class SwitchesScreenModel(private val store: SwitchEventStore) : ViewModel() {
}
.onFailure { error ->
_uiState.value = _uiState.value.copy(
error = error.message ?: "Failed to import switch",
importingSwitch = null
)
}
Expand All @@ -77,17 +75,13 @@ class SwitchesScreenModel(private val store: SwitchEventStore) : ViewModel() {
*/
fun deleteRemoteSwitch(remoteSwitch: RemoteSwitchInfo) {
viewModelScope.launch {
_uiState.value = _uiState.value.copy(
error = null
)
store.removeRemote(remoteSwitch.code)
.onSuccess {
updateLocalSwitches()
loadEvents()
}
.onFailure { error ->
_uiState.value = _uiState.value.copy(
error = error.message ?: "Failed to delete switch",
importingSwitch = null
)
}
Expand All @@ -102,13 +96,6 @@ class SwitchesScreenModel(private val store: SwitchEventStore) : ViewModel() {
localSwitches = store.getSwitchEvents()
)
}

/**
* Clears the current error message.
*/
fun clearError() {
_uiState.value = _uiState.value.copy(error = null)
}
}

/**
Expand All @@ -118,6 +105,5 @@ data class SwitchesUiState(
val localSwitches: Set<SwitchEvent> = emptySet(),
val remoteSwitches: List<RemoteSwitchInfo> = emptyList(),
val isLoading: Boolean = false,
val importingSwitch: String? = null,
val error: String? = null
val importingSwitch: String? = null
)
Loading

0 comments on commit 810e83f

Please sign in to comment.