Skip to content

Commit a4de7b4

Browse files
authored
Handle Proper UI States: Success, Progress, Error, and Empty on Home Transaction History (#2895)
1 parent 274472e commit a4de7b4

File tree

1 file changed

+10
-32
lines changed

1 file changed

+10
-32
lines changed

feature/recent-transaction/src/commonMain/kotlin/org/mifos/mobile/feature/recent/transaction/viewmodel/RecentTransactionViewModel.kt

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,6 @@ class RecentTransactionViewModel(
7575
offset: Int?,
7676
limit: Int?,
7777
) {
78-
// viewModelScope.launch {
79-
// recentTransactionRepositoryImpl.recentTransactions(
80-
// clientId,
81-
// offset,
82-
// limit,
83-
// ).catch {
84-
// _recentTransactionUiState.value = RecentTransactionState.Error
85-
// }
86-
// .collect { recentTransactions ->
87-
// val recentTransactionsList = recentTransactions.data?.pageItems
88-
// _recentTransactionUiState.value = if (recentTransactionsList.isNullOrEmpty()) {
89-
// RecentTransactionState.Empty
90-
// } else {
91-
// RecentTransactionState.Success(
92-
// transactions = recentTransactionsList,
93-
// canPaginate = recentTransactionsList.isNotEmpty(),
94-
// )
95-
// }
96-
// _isPaginating.value = false
97-
// _isRefreshing.value = false
98-
// }
99-
// }
10078
viewModelScope.launch {
10179
recentTransactionRepositoryImpl.recentTransactions(clientId, offset, limit)
10280
.onStart {
@@ -112,26 +90,26 @@ class RecentTransactionViewModel(
11290
_isRefreshing.value = false
11391
}
11492
.collect { recentTransactions ->
115-
val recentTransactionsList = recentTransactions.data?.pageItems.orEmpty()
93+
val items = recentTransactions.data?.pageItems
11694

117-
// Avoid flicker: Don't emit Empty if paginating or refreshing
118-
// val isPaginatingOrRefreshing = _isPaginating.value || _isRefreshing.value
119-
val isInitialLoad = !_isPaginating.value && !_isRefreshing.value
95+
if (items == null) {
96+
return@collect
97+
}
98+
99+
val isInitialLoad = offset == 0
120100

121101
_recentTransactionUiState.value = when {
122-
recentTransactionsList.isNotEmpty() -> {
102+
items.isNotEmpty() -> {
123103
RecentTransactionState.Success(
124-
transactions = recentTransactionsList,
125-
canPaginate = recentTransactionsList.size >= (limit ?: 50),
104+
transactions = items,
105+
canPaginate = items.size >= (limit ?: 50),
126106
)
127107
}
128-
129108
isInitialLoad -> {
130109
RecentTransactionState.Empty
131110
}
132-
133111
else -> {
134-
// For pagination/refreshing, retain previous state
112+
// Retain existing UI state if paginating with no new data
135113
_recentTransactionUiState.value
136114
}
137115
}

0 commit comments

Comments
 (0)