feature (space) : some code clean up
This commit is contained in:
@@ -11,6 +11,6 @@ import io.element.android.libraries.matrix.api.spaces.SpaceRoom
|
||||
|
||||
sealed interface SpaceEvents {
|
||||
data object LoadMore : SpaceEvents
|
||||
data class Join(val spaceRoom: SpaceRoom): SpaceEvents
|
||||
data class Join(val spaceRoom: SpaceRoom) : SpaceEvents
|
||||
data object ClearFailures : SpaceEvents
|
||||
}
|
||||
|
||||
@@ -20,9 +20,8 @@ import kotlinx.collections.immutable.toImmutableSet
|
||||
open class SpaceStateProvider : PreviewParameterProvider<SpaceState> {
|
||||
override val values: Sequence<SpaceState>
|
||||
get() = sequenceOf(
|
||||
aSpaceState(),
|
||||
aSpaceState(
|
||||
|
||||
), aSpaceState(
|
||||
parentSpace = aSpaceRoom(
|
||||
name = null,
|
||||
numJoinedMembers = 5,
|
||||
@@ -30,11 +29,14 @@ open class SpaceStateProvider : PreviewParameterProvider<SpaceState> {
|
||||
worldReadable = true,
|
||||
),
|
||||
hasMoreToLoad = true,
|
||||
), aSpaceState(
|
||||
),
|
||||
aSpaceState(
|
||||
hasMoreToLoad = true,
|
||||
children = aListOfSpaceRooms(),
|
||||
), aSpaceState(
|
||||
hasMoreToLoad = false, children = aListOfSpaceRooms()
|
||||
),
|
||||
aSpaceState(
|
||||
hasMoreToLoad = false,
|
||||
children = aListOfSpaceRooms()
|
||||
)
|
||||
// Add other states here
|
||||
)
|
||||
@@ -59,7 +61,8 @@ fun aSpaceState(
|
||||
hideInvitesAvatar = hideInvitesAvatar,
|
||||
hasMoreToLoad = hasMoreToLoad,
|
||||
joinActions = joiningRooms.associateWith { AsyncAction.Uninitialized }.toImmutableMap(),
|
||||
eventSink = {})
|
||||
eventSink = {}
|
||||
)
|
||||
|
||||
private fun aListOfSpaceRooms(): List<SpaceRoom> {
|
||||
return listOf(
|
||||
|
||||
@@ -12,7 +12,6 @@ import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.statusBarsPadding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
@@ -77,7 +76,8 @@ fun SpaceView(
|
||||
modifier = modifier,
|
||||
topBar = {
|
||||
SpaceViewTopBar(
|
||||
currentSpace = state.currentSpace, onBackClick = onBackClick,
|
||||
currentSpace = state.currentSpace,
|
||||
onBackClick = onBackClick,
|
||||
onLeaveSpaceClick = onLeaveSpaceClick,
|
||||
onShareSpace = onShareSpace,
|
||||
)
|
||||
@@ -90,13 +90,13 @@ fun SpaceView(
|
||||
state = state,
|
||||
onRoomClick = onRoomClick
|
||||
)
|
||||
JoinRoomFailureEffect(
|
||||
hasAnyFailure = state.hasAnyFailure,
|
||||
eventSink = state.eventSink
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
JoinRoomFailureEffect(
|
||||
hasAnyFailure = state.hasAnyFailure,
|
||||
eventSink = state.eventSink
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -105,14 +105,15 @@ private fun JoinRoomFailureEffect(
|
||||
eventSink: (SpaceEvents) -> Unit,
|
||||
) {
|
||||
val asyncIndicatorState = rememberAsyncIndicatorState()
|
||||
AsyncIndicatorHost(modifier = Modifier.statusBarsPadding(), asyncIndicatorState)
|
||||
val updatedEventSink by rememberUpdatedState(eventSink)
|
||||
AsyncIndicatorHost(modifier = Modifier, asyncIndicatorState)
|
||||
LaunchedEffect(hasAnyFailure) {
|
||||
if (hasAnyFailure) {
|
||||
asyncIndicatorState.enqueue {
|
||||
AsyncIndicator.Failure(text = stringResource(CommonStrings.common_something_went_wrong))
|
||||
}
|
||||
delay(AsyncIndicator.DURATION_SHORT)
|
||||
eventSink(SpaceEvents.ClearFailures)
|
||||
updatedEventSink(SpaceEvents.ClearFailures)
|
||||
} else {
|
||||
asyncIndicatorState.clear()
|
||||
}
|
||||
@@ -256,7 +257,6 @@ private fun SpaceViewTopBar(
|
||||
)
|
||||
*/
|
||||
}
|
||||
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -20,10 +20,8 @@ import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
import androidx.compose.material3.ripple
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.ReadOnlyComposable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
@@ -46,10 +44,8 @@ import io.element.android.libraries.designsystem.components.avatar.AvatarType
|
||||
import io.element.android.libraries.designsystem.modifiers.onKeyboardContextMenuAction
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||
import io.element.android.libraries.designsystem.theme.components.ButtonSize
|
||||
import io.element.android.libraries.designsystem.theme.components.Icon
|
||||
import io.element.android.libraries.designsystem.theme.components.Text
|
||||
import io.element.android.libraries.designsystem.theme.components.TextButton
|
||||
import io.element.android.libraries.designsystem.theme.unreadIndicator
|
||||
import io.element.android.libraries.matrix.api.room.CurrentUserMembership
|
||||
import io.element.android.libraries.matrix.api.room.join.JoinRule
|
||||
@@ -78,11 +74,14 @@ fun SpaceRoomItemView(
|
||||
trailingAction = trailingAction,
|
||||
) {
|
||||
NameAndIndicatorRow(
|
||||
isSpace = spaceRoom.isSpace, name = spaceRoom.name, showIndicator = showUnreadIndicator
|
||||
isSpace = spaceRoom.isSpace,
|
||||
name = spaceRoom.name,
|
||||
showIndicator = showUnreadIndicator
|
||||
)
|
||||
Spacer(modifier = Modifier.height(1.dp))
|
||||
SubtitleRow(
|
||||
visibilityIcon = spaceRoom.visibilityIcon(), subtitle = spaceRoom.subtitle()
|
||||
visibilityIcon = spaceRoom.visibilityIcon(),
|
||||
subtitle = spaceRoom.subtitle()
|
||||
)
|
||||
Spacer(modifier = Modifier.height(1.dp))
|
||||
Text(
|
||||
@@ -181,7 +180,8 @@ private fun SpaceRoomItemScaffold(
|
||||
onLongClick = onLongClick,
|
||||
onLongClickLabel = stringResource(CommonStrings.action_open_context_menu),
|
||||
indication = ripple(),
|
||||
interactionSource = remember { MutableInteractionSource() })
|
||||
interactionSource = remember { MutableInteractionSource() }
|
||||
)
|
||||
.onKeyboardContextMenuAction { onLongClick }
|
||||
Row(
|
||||
modifier = modifier
|
||||
|
||||
Reference in New Issue
Block a user