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