mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:30:43 +00:00
Debounce SpaceState.hasMoreToLoad
This commit is contained in:
+14
-6
@@ -6,6 +6,8 @@
|
|||||||
* Please see LICENSE files in the repository root for full details.
|
* Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@file:OptIn(FlowPreview::class)
|
||||||
|
|
||||||
package io.element.android.features.space.impl.root
|
package io.element.android.features.space.impl.root
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -47,10 +49,13 @@ import kotlinx.collections.immutable.toImmutableList
|
|||||||
import kotlinx.collections.immutable.toImmutableMap
|
import kotlinx.collections.immutable.toImmutableMap
|
||||||
import kotlinx.collections.immutable.toImmutableSet
|
import kotlinx.collections.immutable.toImmutableSet
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.FlowPreview
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.awaitAll
|
import kotlinx.coroutines.awaitAll
|
||||||
|
import kotlinx.coroutines.flow.debounce
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlin.time.Duration.Companion.milliseconds
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
class SpacePresenter(
|
class SpacePresenter(
|
||||||
@@ -80,13 +85,16 @@ class SpacePresenter(
|
|||||||
val localCoroutineScope = rememberCoroutineScope()
|
val localCoroutineScope = rememberCoroutineScope()
|
||||||
|
|
||||||
val hasMoreToLoad by remember {
|
val hasMoreToLoad by remember {
|
||||||
spaceRoomList.paginationStatusFlow.mapState { status ->
|
spaceRoomList.paginationStatusFlow
|
||||||
when (status) {
|
.mapState { status ->
|
||||||
is SpaceRoomList.PaginationStatus.Idle -> status.hasMoreToLoad
|
when (status) {
|
||||||
SpaceRoomList.PaginationStatus.Loading -> true
|
is SpaceRoomList.PaginationStatus.Idle -> status.hasMoreToLoad
|
||||||
|
SpaceRoomList.PaginationStatus.Loading -> true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
// Debounce to give more time for spaceRoomList to updates
|
||||||
}.collectAsState()
|
.debounce(100.milliseconds)
|
||||||
|
}.collectAsState(true)
|
||||||
|
|
||||||
val permissions by room.permissionsAsState(SpacePermissions.DEFAULT) { perms ->
|
val permissions by room.permissionsAsState(SpacePermissions.DEFAULT) { perms ->
|
||||||
perms.spacePermissions()
|
perms.spacePermissions()
|
||||||
|
|||||||
Reference in New Issue
Block a user