fix: member list reactivity and online category size
Signed-off-by: Infi <wingit@geist.ga>
This commit is contained in:
parent
8fdf442747
commit
89c292778b
|
|
@ -31,6 +31,7 @@ import androidx.compose.runtime.mutableStateListOf
|
|||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
|
|
@ -55,6 +56,7 @@ import chat.revolt.components.generic.UserAvatar
|
|||
import chat.revolt.components.generic.presenceFromStatus
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -127,6 +129,7 @@ class MemberListSheetViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
// Online
|
||||
if (!categories[defaultCategoryName].isNullOrEmpty()) {
|
||||
fullItemList.add(
|
||||
MemberListItem.CategoryItem(
|
||||
defaultCategoryName,
|
||||
|
|
@ -136,9 +139,10 @@ class MemberListSheetViewModel @Inject constructor(
|
|||
categories[defaultCategoryName]?.forEach { member ->
|
||||
fullItemList.add(MemberListItem.MemberItem(member))
|
||||
}
|
||||
}
|
||||
|
||||
// Offline
|
||||
if (categories[offlineCategoryName].isNullOrEmpty()) return@launch
|
||||
if (!categories[offlineCategoryName].isNullOrEmpty()) {
|
||||
fullItemList.add(
|
||||
MemberListItem.CategoryItem(
|
||||
offlineCategoryName,
|
||||
|
|
@ -151,6 +155,7 @@ class MemberListSheetViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
|
|
@ -161,9 +166,12 @@ fun MemberListSheet(
|
|||
var showUserContextSheet by remember { mutableStateOf(false) }
|
||||
var userContextSheetTarget by remember { mutableStateOf("") }
|
||||
|
||||
LaunchedEffect(serverId) {
|
||||
// We use LaunchedEffect to make sure that this is called every time any of the users status changes
|
||||
LaunchedEffect(RevoltAPI.userCache) {
|
||||
snapshotFlow { RevoltAPI.userCache }.distinctUntilChanged().collect {
|
||||
viewModel.fetchMemberList(serverId)
|
||||
}
|
||||
}
|
||||
|
||||
if (showUserContextSheet) {
|
||||
val userContextSheetState = rememberModalBottomSheetState()
|
||||
|
|
|
|||
Loading…
Reference in New Issue