Quick snackbar for unimplemented actions

This commit is contained in:
Benoit Marty 2022-11-22 18:38:45 +01:00
parent 5daa19cc6f
commit 4e05182df4
3 changed files with 31 additions and 6 deletions

View file

@ -69,9 +69,11 @@ fun MessagesScreen(
val roomAvatar by viewModel.collectAsState(MessagesViewState::roomAvatar)
val timelineItems by viewModel.collectAsState(MessagesViewState::timelineItems)
val hasMoreToLoad by viewModel.collectAsState(MessagesViewState::hasMoreToLoad)
val snackBarContent by viewModel.collectAsState(MessagesViewState::snackbarContent)
val composerFullScreen by composerViewModel.collectAsState(MessageComposerViewState::isFullScreen)
val composerCanSendMessage by composerViewModel.collectAsState(MessageComposerViewState::isSendButtonVisible)
val composerText by composerViewModel.collectAsState(MessageComposerViewState::text)
val snackbarHostState = remember { SnackbarHostState() }
MessagesContent(
roomTitle = roomTitle,
roomAvatar = roomAvatar,
@ -96,7 +98,8 @@ fun MessagesScreen(
coroutineScope.launch {
actionsSheetState.show()
}
}
},
snackbarHostState = snackbarHostState,
)
val itemActionsSheetState by viewModel.collectAsState(prop1 = MessagesViewState::itemActionsSheetState)
TimelineItemActionsScreen(
@ -109,6 +112,12 @@ fun MessagesScreen(
}
}
)
snackBarContent?.let {
coroutineScope.launch {
snackbarHostState.showSnackbar(it)
}
viewModel.onSnackbarShown()
}
}
@Composable
@ -121,15 +130,17 @@ fun MessagesContent(
onBackPressed: () -> Unit,
onSendMessage: (String) -> Unit,
onClick: (MessagesTimelineItemState.MessageEvent) -> Unit,
onLongClick: ((MessagesTimelineItemState.MessageEvent)) -> Unit,
onLongClick: (MessagesTimelineItemState.MessageEvent) -> Unit,
composerFullScreen: Boolean,
onComposerFullScreenChange: () -> Unit,
onComposerTextChange: (CharSequence) -> Unit,
composerCanSendMessage: Boolean,
composerText: StableCharSequence?,
snackbarHostState: SnackbarHostState,
) {
LogCompositions(tag = "MessagesScreen", msg = "Content")
val lazyListState = rememberLazyListState()
Scaffold(
topBar = {
TopAppBar(
@ -194,7 +205,8 @@ fun MessagesContent(
},
)
}
}
},
snackbarHost = { SnackbarHost(snackbarHostState) },
)
}

View file

@ -77,13 +77,25 @@ class MessagesViewModel(
val targetEvent =
currentState.itemActionsSheetState.invoke()?.targetItem ?: return@launch
when (action) {
MessagesItemAction.Copy -> Unit // TODO
MessagesItemAction.Forward -> Unit // TODO
MessagesItemAction.Copy -> notImplementedYet()
MessagesItemAction.Forward -> notImplementedYet()
MessagesItemAction.Redact -> handleActionRedact(targetEvent)
}
}
}
private fun notImplementedYet() {
setSnackbarContent("Not implemented yet!")
}
fun onSnackbarShown() {
setSnackbarContent(null)
}
private fun setSnackbarContent(message: String?) {
setState { copy(snackbarContent = message) }
}
private fun handleActionRedact(event: MessagesTimelineItemState.MessageEvent) {
viewModelScope.launch {
room.redactEvent(event.id)

View file

@ -11,7 +11,8 @@ data class MessagesViewState(
val roomAvatar: AvatarData? = null,
val timelineItems: Async<List<MessagesTimelineItemState>> = Uninitialized,
val hasMoreToLoad: Boolean = true,
val itemActionsSheetState: Async<MessagesItemActionsSheetState> = Uninitialized
val itemActionsSheetState: Async<MessagesItemActionsSheetState> = Uninitialized,
val snackbarContent: String? = null,
) : MavericksState {
@Suppress("unused")