fix: resolve race condition where Detail screen shows infinite spinner
When navigating to a section before schema fetch completes, onSectionSelected() would silently return due to null schema. Introduce pendingSectionKey so loadData() auto-triggers loadSection() once the fetch finishes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
86550e0ab6
commit
ac66b252c5
1 changed files with 9 additions and 0 deletions
|
|
@ -28,6 +28,7 @@ class ConfigViewModel(private val apiClient: ConfigApiClient) : ViewModel() {
|
|||
private var schema: ConfigSchema? = null
|
||||
private var configValues: JsonObject? = null
|
||||
private var saveJob: Job? = null
|
||||
private var pendingSectionKey: String? = null
|
||||
|
||||
init {
|
||||
loadData()
|
||||
|
|
@ -40,6 +41,10 @@ class ConfigViewModel(private val apiClient: ConfigApiClient) : ViewModel() {
|
|||
fun onSectionSelected(sectionKey: String) {
|
||||
val current = _uiState.value.detailState
|
||||
if (current != null && current.sectionKey == sectionKey) return
|
||||
if (schema == null) {
|
||||
pendingSectionKey = sectionKey
|
||||
return
|
||||
}
|
||||
loadSection(sectionKey)
|
||||
}
|
||||
|
||||
|
|
@ -133,6 +138,10 @@ class ConfigViewModel(private val apiClient: ConfigApiClient) : ViewModel() {
|
|||
_uiState.update {
|
||||
it.copy(listState = ListState.Loaded(s.toSummaries()))
|
||||
}
|
||||
pendingSectionKey?.let { key ->
|
||||
pendingSectionKey = null
|
||||
loadSection(key)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue