show selected participants when clicking on add button

Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
sowjanyakch 2025-05-26 15:52:20 +02:00 committed by Marcel Hibbe
parent c3ebeebcb0
commit b9e9d0ccd1
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
3 changed files with 15 additions and 4 deletions

View File

@ -31,6 +31,7 @@ fun ContactsScreen(contactsViewModel: ContactsViewModel, uiState: ContactsUiStat
val autocompleteUsers by contactsViewModel.selectedParticipantsList.collectAsStateWithLifecycle() val autocompleteUsers by contactsViewModel.selectedParticipantsList.collectAsStateWithLifecycle()
val enableAddButton by contactsViewModel.enableAddButton.collectAsStateWithLifecycle() val enableAddButton by contactsViewModel.enableAddButton.collectAsStateWithLifecycle()
Scaffold( Scaffold(
topBar = { topBar = {
AppBar( AppBar(
@ -51,7 +52,10 @@ fun ContactsScreen(contactsViewModel: ContactsViewModel, uiState: ContactsUiStat
onUpdateAutocompleteUsers = { onUpdateAutocompleteUsers = {
contactsViewModel.getContactsFromSearchParams() contactsViewModel.getContactsFromSearchParams()
}, },
enableAddButton = enableAddButton enableAddButton = enableAddButton,
clickAddButton = {
contactsViewModel.modifyClickAddButton(it)
}
) )
}, },
content = { content = {

View File

@ -41,6 +41,8 @@ class ContactsViewModel @Inject constructor(
private val _selectedContacts = MutableStateFlow<List<AutocompleteUser>>(emptyList()) private val _selectedContacts = MutableStateFlow<List<AutocompleteUser>>(emptyList())
private val _clickAddButton = MutableStateFlow(false)
private var hideAlreadyAddedParticipants: Boolean = false private var hideAlreadyAddedParticipants: Boolean = false
init { init {
@ -51,6 +53,10 @@ class ContactsViewModel @Inject constructor(
_searchQuery.value = query _searchQuery.value = query
} }
fun modifyClickAddButton(value:Boolean){
_clickAddButton.value = value
}
fun selectContact(contact: AutocompleteUser) { fun selectContact(contact: AutocompleteUser) {
val updatedParticipants = selectedParticipants.value + contact val updatedParticipants = selectedParticipants.value + contact
selectedParticipants.value = updatedParticipants selectedParticipants.value = updatedParticipants
@ -101,10 +107,9 @@ class ContactsViewModel @Inject constructor(
) )
val contactsList: MutableList<AutocompleteUser>? = contacts.ocs!!.data?.toMutableList() val contactsList: MutableList<AutocompleteUser>? = contacts.ocs!!.data?.toMutableList()
if (hideAlreadyAddedParticipants) { if (hideAlreadyAddedParticipants && !_clickAddButton.value) {
contactsList?.removeAll(selectedParticipants.value) contactsList?.removeAll(selectedParticipants.value)
} }
_contactsViewState.value = ContactsUiState.Success(contactsList) _contactsViewState.value = ContactsUiState.Success(contactsList)
} catch (exception: Exception) { } catch (exception: Exception) {
_contactsViewState.value = ContactsUiState.Error(exception.message ?: "") _contactsViewState.value = ContactsUiState.Error(exception.message ?: "")

View File

@ -43,7 +43,8 @@ fun AppBar(
onDisableSearch: () -> Unit, onDisableSearch: () -> Unit,
onUpdateSearchQuery: (String) -> Unit, onUpdateSearchQuery: (String) -> Unit,
onUpdateAutocompleteUsers: () -> Unit, onUpdateAutocompleteUsers: () -> Unit,
enableAddButton: Boolean enableAddButton: Boolean,
clickAddButton:(Boolean) -> Unit
) { ) {
val context = LocalContext.current val context = LocalContext.current
@ -97,6 +98,7 @@ fun AppBar(
onClick = { onClick = {
onDisableSearch() onDisableSearch()
onUpdateSearchQuery("") onUpdateSearchQuery("")
clickAddButton(true)
onUpdateAutocompleteUsers() onUpdateAutocompleteUsers()
}, },
enabled = enableAddButton enabled = enableAddButton