Skip to content

Commit

Permalink
Fixed logic for showing empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury committed Oct 4, 2024
1 parent 452106d commit 5bc4ea5
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import javax.inject.Named
class SelfHostedUsersViewModel @Inject constructor(
@Named(UI_THREAD) mainDispatcher: CoroutineDispatcher,
) : ScopedViewModel(mainDispatcher) {
private val users = ArrayList<UserWithEditContext>()
private val userList = ArrayList<UserWithEditContext>()
private var selectedUser: UserWithEditContext? = null

private val _uiState = MutableStateFlow<SelfHostedUserState>(SelfHostedUserState.Loading)
Expand All @@ -40,9 +40,14 @@ class SelfHostedUsersViewModel @Inject constructor(
_uiState.value = SelfHostedUserState.Loading
launch {
delay(1000L)
users.clear()
users.addAll(SampleUsers.getSampleUsers())
_uiState.value = SelfHostedUserState.UserList(users)
userList.clear()
val users = SampleUsers.getSampleUsers()
if (users.isEmpty()) {
_uiState.value = SelfHostedUserState.EmptyUserList
} else {
userList.addAll(users)
_uiState.value = SelfHostedUserState.UserList(userList)
}
}
}

Expand All @@ -52,7 +57,7 @@ class SelfHostedUsersViewModel @Inject constructor(
fun onCloseClick(context: Context) {
when (_uiState.value) {
is SelfHostedUserState.UserDetail -> {
_uiState.value = SelfHostedUserState.UserList(users)
_uiState.value = SelfHostedUserState.UserList(userList)
}

is SelfHostedUserState.UserAvatar -> {
Expand Down

0 comments on commit 5bc4ea5

Please sign in to comment.