点赞和评论
This commit is contained in:
@@ -58,8 +58,8 @@ import kotlinx.coroutines.launch
|
||||
|
||||
class CommentModalViewModel(
|
||||
postId: Int?
|
||||
):ViewModel(){
|
||||
val commentService:CommentService = TestCommentServiceImpl()
|
||||
) : ViewModel() {
|
||||
val commentService: CommentService = TestCommentServiceImpl()
|
||||
val commentsFlow: Flow<PagingData<Comment>> = Pager(
|
||||
config = PagingConfig(pageSize = 20, enablePlaceholders = false),
|
||||
pagingSourceFactory = {
|
||||
@@ -70,10 +70,16 @@ class CommentModalViewModel(
|
||||
}
|
||||
).flow.cachedIn(viewModelScope)
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun CommentModalContent(postId: Int? = null, onDismiss: () -> Unit = {}) {
|
||||
fun CommentModalContent(
|
||||
postId: Int? = null,
|
||||
onCommentAdded: () -> Unit = {},
|
||||
onDismiss: () -> Unit = {}
|
||||
) {
|
||||
val model = viewModel<CommentModalViewModel>(
|
||||
key = "CommentModalViewModel_$postId",
|
||||
factory = object : ViewModelProvider.Factory {
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
return CommentModalViewModel(postId) as T
|
||||
@@ -102,6 +108,7 @@ fun CommentModalContent(postId: Int? = null, onDismiss: () -> Unit = {}) {
|
||||
commentText = ""
|
||||
}
|
||||
comments.refresh()
|
||||
onCommentAdded()
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier
|
||||
@@ -129,8 +136,7 @@ fun CommentModalContent(postId: Int? = null, onDismiss: () -> Unit = {}) {
|
||||
.padding(horizontal = 16.dp)
|
||||
.weight(1f)
|
||||
) {
|
||||
CommentsSection(lazyPagingItems = comments, onLike = {
|
||||
comment: Comment ->
|
||||
CommentsSection(lazyPagingItems = comments, onLike = { comment: Comment ->
|
||||
scope.launch {
|
||||
model.commentService.likeComment(comment.id)
|
||||
comments.refresh()
|
||||
|
||||
Reference in New Issue
Block a user