@@ -14,24 +14,23 @@ import androidx.compose.ui.platform.LocalFocusManager
14
14
import androidx.navigation.NavController
15
15
import com.jerboa.api.uploadPictrsImage
16
16
import com.jerboa.appendMarkdownImage
17
- import com.jerboa.datatypes.api.CreateComment
18
17
import com.jerboa.db.AccountViewModel
19
18
import com.jerboa.imageInputStreamFromUri
20
19
import com.jerboa.isModerator
21
20
import com.jerboa.ui.components.common.getCurrentAccount
21
+ import com.jerboa.ui.components.inbox.InboxViewModel
22
22
import com.jerboa.ui.components.person.PersonProfileViewModel
23
23
import com.jerboa.ui.components.person.personClickWrapper
24
24
import com.jerboa.ui.components.post.PostViewModel
25
25
import kotlinx.coroutines.launch
26
26
27
- // TODO this should probably be refactored to not rely on postViewModel, since you should be able
28
- // to create comments from many other screens.
29
- // It should have its own viewmodel
30
27
@Composable
31
28
fun CommentReplyActivity (
32
- postViewModel : PostViewModel ,
29
+ commentReplyViewModel : CommentReplyViewModel ,
33
30
accountViewModel : AccountViewModel ,
34
31
personProfileViewModel : PersonProfileViewModel ,
32
+ postViewModel : PostViewModel ,
33
+ inboxViewModel : InboxViewModel ,
35
34
navController : NavController ,
36
35
) {
37
36
@@ -50,28 +49,27 @@ fun CommentReplyActivity(
50
49
CommentReplyHeader (
51
50
navController = navController,
52
51
onSendClick = {
53
- postViewModel.postView.value?.also { postView ->
54
- account?.also { account ->
55
- val parentId = postViewModel.replyToCommentParent?.comment?.id
56
- val form =
57
- CreateComment (
58
- content = reply,
59
- parent_id = parentId,
60
- post_id = postView.post.id,
61
- auth = account.jwt
62
- )
63
- postViewModel.createComment(form, ctx, navController, focusManager)
64
- }
52
+ account?.also { acct ->
53
+ commentReplyViewModel.createComment(
54
+ content = reply,
55
+ account = acct,
56
+ ctx = ctx,
57
+ navController = navController,
58
+ focusManager = focusManager,
59
+ personProfileViewModel = personProfileViewModel,
60
+ postViewModel = postViewModel,
61
+ inboxViewModel = inboxViewModel,
62
+ )
65
63
}
66
64
}
67
65
)
68
66
},
69
67
content = {
70
- if (postViewModel.replyLoading .value) {
68
+ if (commentReplyViewModel.loading .value) {
71
69
LinearProgressIndicator (modifier = Modifier .fillMaxWidth())
72
70
} else {
73
71
74
- postViewModel.replyToCommentParent ?.also { commentView ->
72
+ commentReplyViewModel.commentParentView.value ?.also { commentView ->
75
73
CommentReply (
76
74
commentView = commentView,
77
75
reply = reply,
@@ -97,7 +95,7 @@ fun CommentReplyActivity(
97
95
isModerator(commentView.creator, postViewModel.moderators)
98
96
)
99
97
} ? : run {
100
- postViewModel .postView.value?.also { postView ->
98
+ commentReplyViewModel .postView.value?.also { postView ->
101
99
PostReply (
102
100
postView = postView,
103
101
reply = reply,
0 commit comments