feat: back to top in user detail

This commit is contained in:
Diego Beraldin 2023-10-24 08:54:53 +02:00
parent 745755ff88
commit d89a2169cd
3 changed files with 31 additions and 19 deletions

View File

@ -49,5 +49,6 @@ interface PostDetailMviModel :
sealed interface Effect { sealed interface Effect {
data object Close : Effect data object Close : Effect
data class ScrollToComment(val index: Int) : Effect data class ScrollToComment(val index: Int) : Effect
data object BackToTop : Effect
} }
} }

View File

@ -171,6 +171,12 @@ class PostDetailScreen(
is PostDetailMviModel.Effect.ScrollToComment -> { is PostDetailMviModel.Effect.ScrollToComment -> {
lazyListState.scrollToItem(evt.index) lazyListState.scrollToItem(evt.index)
} }
PostDetailMviModel.Effect.BackToTop -> {
scope.launch {
lazyListState.scrollToItem(0)
}
}
} }
}.launchIn(this) }.launchIn(this)
} }
@ -483,26 +489,27 @@ class PostDetailScreen(
) )
}, },
content = { content = {
CommentCard(modifier = Modifier.background(MaterialTheme.colorScheme.background) CommentCard(
.let { modifier = Modifier.background(MaterialTheme.colorScheme.background)
if (comment.id == highlightCommentId) { .let {
it.background( if (comment.id == highlightCommentId) {
MaterialTheme.colorScheme.surfaceColorAtElevation( it.background(
5.dp MaterialTheme.colorScheme.surfaceColorAtElevation(
).copy( 5.dp
alpha = 0.75f ).copy(
alpha = 0.75f
)
)
} else {
it
}
}.onClick {
model.reduce(
PostDetailMviModel.Intent.ToggleExpandComment(
commentId,
) )
) )
} else { },
it
}
}.onClick {
model.reduce(
PostDetailMviModel.Intent.ToggleExpandComment(
commentId,
)
)
},
comment = comment, comment = comment,
separateUpAndDownVotes = uiState.separateUpAndDownVotes, separateUpAndDownVotes = uiState.separateUpAndDownVotes,
autoLoadImages = uiState.autoLoadImages, autoLoadImages = uiState.autoLoadImages,
@ -614,7 +621,8 @@ class PostDetailScreen(
) )
} }
} }
}) },
)
}, },
) )
Divider( Divider(

View File

@ -295,6 +295,9 @@ class PostDetailViewModel(
private fun applySortType(value: SortType) { private fun applySortType(value: SortType) {
mvi.updateState { it.copy(sortType = value) } mvi.updateState { it.copy(sortType = value) }
mvi.scope?.launch {
mvi.emitEffect(PostDetailMviModel.Effect.BackToTop)
}
refresh() refresh()
} }