Skip to content

Commit 5988178

Browse files
committed
fix broken comment dislikes closes #14
1 parent 0abad86 commit 5988178

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

lib/features/api/repositories/fpapi.dart

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -674,28 +674,33 @@ class FPApiRequests {
674674
String whitelabel, String commentId, String blogPostId) async {
675675
final response = await postData('v3/comment/like', whitelabel,
676676
{'comment': commentId, 'blogPost': blogPostId});
677+
if (response.isEmpty || response.toString() == '[]' || response == 'null') {
678+
return 'removed';
679+
}
680+
677681
final decodedres = jsonDecode(response);
678-
if (decodedres.contains('like')) {
682+
if (decodedres != null && decodedres.toString().contains('dislike')) {
679683
return 'success';
680-
} else if (response.toString() == '[]') {
681-
return 'removed';
682-
} else {
683-
return 'fail';
684684
}
685+
686+
return 'fail';
685687
}
686688

687689
Future<String> dislikeComment(
688690
String whitelabel, String commentId, String blogPostId) async {
689691
final response = await postData('v3/comment/dislike', whitelabel,
690692
{'comment': commentId, 'blogPost': blogPostId});
693+
694+
if (response.isEmpty || response.toString() == '[]' || response == 'null') {
695+
return 'removed';
696+
}
697+
691698
final decodedres = jsonDecode(response);
692-
if (decodedres.contains('dislike')) {
699+
if (decodedres != null && decodedres.toString().contains('like')) {
693700
return 'success';
694-
} else if (response.toString() == '[]') {
695-
return 'removed';
696-
} else {
697-
return 'fail';
698701
}
702+
703+
return 'fail';
699704
}
700705

701706
Future<List<BlogPostModelV3>> getRecommended(

lib/features/post/components/comment_item.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class _CommentItemState extends ConsumerState<CommentItem> {
4949
_commentText = widget.comment.text;
5050
_editController = TextEditingController(text: _commentText);
5151
_likeCount = widget.comment.likes;
52+
_dislikeCount = widget.comment.dislikes;
5253
_replyController.addListener(_updateCharCount);
5354
}
5455

0 commit comments

Comments
 (0)