Call spaceRoomList.reset when exiting add/remove room flow
This commit is contained in:
parent
e896c7604d
commit
44d33af6dc
8 changed files with 151 additions and 12 deletions
|
|
@ -14,4 +14,5 @@ sealed interface AddRoomToSpaceEvent {
|
|||
data class OnSearchActiveChanged(val active: Boolean) : AddRoomToSpaceEvent
|
||||
data object Save : AddRoomToSpaceEvent
|
||||
data object ResetSaveAction : AddRoomToSpaceEvent
|
||||
data object Dismiss : AddRoomToSpaceEvent
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class AddRoomToSpaceNode(
|
|||
val state by stateFlow.collectAsState()
|
||||
AddRoomToSpaceView(
|
||||
state = state,
|
||||
onBackClick = ::navigateUp,
|
||||
onBackClick = callback::onFinish,
|
||||
onRoomsAdded = callback::onFinish,
|
||||
modifier = modifier
|
||||
)
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import io.element.android.libraries.designsystem.theme.components.SearchBarResul
|
|||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
import io.element.android.libraries.matrix.api.spaces.SpaceRoomList
|
||||
import io.element.android.libraries.matrix.api.spaces.SpaceService
|
||||
import io.element.android.libraries.matrix.api.spaces.resetAndWaitForFullReload
|
||||
import io.element.android.libraries.matrix.ui.model.SelectRoomInfo
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
|
|
@ -50,6 +49,8 @@ class AddRoomToSpacePresenter(
|
|||
val searchQuery = rememberTextFieldState()
|
||||
var isSearchActive by remember { mutableStateOf(false) }
|
||||
val saveAction = remember { mutableStateOf<AsyncAction<Unit>>(AsyncAction.Uninitialized) }
|
||||
// Track whether any rooms were added (for conditional reset on Dismiss)
|
||||
var hasAddedRooms by remember { mutableStateOf(false) }
|
||||
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val dataSource = remember { dataSourceFactory.create(coroutineScope) }
|
||||
|
|
@ -96,6 +97,9 @@ class AddRoomToSpacePresenter(
|
|||
dataSource = dataSource,
|
||||
saveAction = saveAction,
|
||||
onPartialSuccess = { successfullyAdded ->
|
||||
if (successfullyAdded.isNotEmpty()) {
|
||||
hasAddedRooms = true
|
||||
}
|
||||
selectedRooms = selectedRooms.filterNot { it.roomId in successfullyAdded }.toImmutableList()
|
||||
},
|
||||
)
|
||||
|
|
@ -103,6 +107,11 @@ class AddRoomToSpacePresenter(
|
|||
AddRoomToSpaceEvent.ResetSaveAction -> {
|
||||
saveAction.value = AsyncAction.Uninitialized
|
||||
}
|
||||
AddRoomToSpaceEvent.Dismiss -> {
|
||||
if (hasAddedRooms) {
|
||||
coroutineScope.launch { spaceRoomList.reset() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ fun AddRoomToSpaceView(
|
|||
if (state.isSearchActive) {
|
||||
state.eventSink(AddRoomToSpaceEvent.OnSearchActiveChanged(false))
|
||||
} else {
|
||||
state.eventSink(AddRoomToSpaceEvent.Dismiss)
|
||||
onBackClick()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ import kotlinx.collections.immutable.toImmutableSet
|
|||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
|
@ -136,6 +135,16 @@ class SpacePresenter(
|
|||
|
||||
val acceptDeclineInviteState = acceptDeclineInvitePresenter.present()
|
||||
|
||||
suspend fun exitManageMode(shouldReset: Boolean) {
|
||||
isManageMode = false
|
||||
selectedRoomIds = emptySet()
|
||||
removedRoomIds = emptySet()
|
||||
if (shouldReset) {
|
||||
// Reset the space room list to see the updates.
|
||||
spaceRoomList.reset()
|
||||
}
|
||||
}
|
||||
|
||||
fun handleEvent(event: SpaceEvents) {
|
||||
when (event) {
|
||||
// SpaceRoomList is loaded automatically as backend is really slow. Event is kept for future.
|
||||
|
|
@ -168,8 +177,7 @@ class SpacePresenter(
|
|||
selectedRoomIds = emptySet()
|
||||
}
|
||||
SpaceEvents.ExitManageMode -> {
|
||||
isManageMode = false
|
||||
selectedRoomIds = emptySet()
|
||||
localCoroutineScope.launch { exitManageMode(shouldReset = removedRoomIds.isNotEmpty()) }
|
||||
}
|
||||
is SpaceEvents.ToggleRoomSelection -> {
|
||||
selectedRoomIds = if (event.roomId in selectedRoomIds) {
|
||||
|
|
@ -202,10 +210,7 @@ class SpacePresenter(
|
|||
removeRoomsAction = AsyncAction.Failure(Exception("Failed to remove some rooms"))
|
||||
} else {
|
||||
removeRoomsAction = AsyncAction.Success(Unit)
|
||||
isManageMode = false
|
||||
selectedRoomIds = emptySet()
|
||||
// Reset the space room list to see the updates.
|
||||
spaceRoomList.reset()
|
||||
exitManageMode(shouldReset = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue