comments bug fixed
This commit is contained in:
parent
3f31e76108
commit
c8d40adec3
|
|
@ -6,9 +6,9 @@ class CommentData {
|
|||
int id;
|
||||
final String text;
|
||||
final String createdAt;
|
||||
final bool liked;
|
||||
final bool disliked;
|
||||
FeedbackData feedback;
|
||||
bool liked;
|
||||
bool disliked;
|
||||
final FeedbackData feedback;
|
||||
final UserOverview user;
|
||||
final List<Reply> replies;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
class FeedbackData {
|
||||
final int like;
|
||||
final int dislike;
|
||||
int like;
|
||||
int dislike;
|
||||
|
||||
const FeedbackData({required this.like, required this.dislike});
|
||||
FeedbackData({required this.like, required this.dislike});
|
||||
|
||||
factory FeedbackData.fromJson(Map<String, dynamic> json) => FeedbackData(
|
||||
like: json['like'],
|
||||
|
|
|
|||
|
|
@ -44,9 +44,8 @@ class UserProvider extends CoreProvier {
|
|||
|
||||
Future<void> _registerFirebaseToken() async {
|
||||
final service = RequestService(RequestHelper.firebaseToken, body: {
|
||||
'firebaseToken': AppInitializer.fcmToken,
|
||||
'token': AppInitializer.fcmToken,
|
||||
});
|
||||
|
||||
await service.put();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,6 +85,10 @@ class _CommentsState extends State<Comments> {
|
|||
title: 'اولین نظر را بنویسید...',
|
||||
),
|
||||
builder: (context, state, index) => Comment(
|
||||
key: ValueKey(
|
||||
state.comments[index].id.toString() +
|
||||
state.comments[index].text,
|
||||
),
|
||||
focusNode: _focusNode,
|
||||
comment: state.comments[index],
|
||||
),
|
||||
|
|
|
|||
|
|
@ -44,8 +44,31 @@ class CommentsState extends CoreProvier {
|
|||
appState = AppState.failed;
|
||||
}
|
||||
|
||||
Future<void> feedback(int id, bool like, bool dislike) async {
|
||||
Future<void> feedback({
|
||||
required int id,
|
||||
required bool like,
|
||||
required bool dislike,
|
||||
required int likeCount,
|
||||
required int dislikeCount,
|
||||
int? replyId,
|
||||
}) async {
|
||||
_feedbackQueue.addAll({id: MapEntry(like, dislike)});
|
||||
dynamic comment;
|
||||
if (replyId == null) {
|
||||
comment = comments.firstWhere((comment) => comment.id == id);
|
||||
} else {
|
||||
comment = comments
|
||||
.firstWhere((comment) => comment.id == id)
|
||||
.replies
|
||||
.firstWhere((element) => element.id == replyId);
|
||||
}
|
||||
|
||||
if (comment != null) {
|
||||
comment.feedback.like = likeCount;
|
||||
comment.feedback.dislike = dislikeCount;
|
||||
comment.disliked = dislike;
|
||||
comment.liked = like;
|
||||
}
|
||||
Future.delayed(const Duration(milliseconds: 500), () async {
|
||||
if (!_feedbackQueue.containsKey(id)) return;
|
||||
final service = RequestService(
|
||||
|
|
@ -70,7 +93,7 @@ class CommentsState extends CoreProvier {
|
|||
createdAt: DateTime.now().toString(),
|
||||
liked: false,
|
||||
disliked: false,
|
||||
feedback: const FeedbackData(like: 0, dislike: 0),
|
||||
feedback: FeedbackData(like: 0, dislike: 0),
|
||||
toUser: replyingTo!,
|
||||
user: UserOverview(
|
||||
id: user.id,
|
||||
|
|
@ -88,7 +111,7 @@ class CommentsState extends CoreProvier {
|
|||
createdAt: DateTime.now().toString(),
|
||||
liked: false,
|
||||
disliked: false,
|
||||
feedback: const FeedbackData(like: 0, dislike: 0),
|
||||
feedback: FeedbackData(like: 0, dislike: 0),
|
||||
user: UserOverview(
|
||||
id: user.id,
|
||||
fullName: user.fullName,
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class CommentState extends State<Comment> {
|
|||
duration: DesignConfig.lowAnimationDuration,
|
||||
isVisible: _showSubComments,
|
||||
child: _commentBuilder(
|
||||
isSubComment: true,
|
||||
isReply: true,
|
||||
comment: _comment.replies[i],
|
||||
),
|
||||
),
|
||||
|
|
@ -57,11 +57,10 @@ class CommentState extends State<Comment> {
|
|||
);
|
||||
}
|
||||
|
||||
Widget _commentBuilder({required comment, bool isSubComment = false}) =>
|
||||
Container(
|
||||
Widget _commentBuilder({required comment, bool isReply = false}) => Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
right: isSubComment
|
||||
right: isReply
|
||||
? BorderSide(color: Theme.of(context).colorScheme.caption)
|
||||
: BorderSide.none,
|
||||
),
|
||||
|
|
@ -69,7 +68,7 @@ class CommentState extends State<Comment> {
|
|||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (isSubComment) const SizedBox(width: 12),
|
||||
if (isReply) const SizedBox(width: 12),
|
||||
if (comment.user.photo == null)
|
||||
const Icon(DidvanIcons.avatar_light),
|
||||
if (comment.user.photo != null)
|
||||
|
|
@ -99,7 +98,7 @@ class CommentState extends State<Comment> {
|
|||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (isSubComment)
|
||||
if (isReply)
|
||||
DidvanText(
|
||||
'پاسخ به ${comment.toUser.fullName}',
|
||||
style: Theme.of(context).textTheme.caption,
|
||||
|
|
@ -124,8 +123,8 @@ class CommentState extends State<Comment> {
|
|||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
),
|
||||
if (!isSubComment) const SizedBox(width: 20),
|
||||
if (!isSubComment && comment.replies.isNotEmpty)
|
||||
if (!isReply) const SizedBox(width: 20),
|
||||
if (!isReply && comment.replies.isNotEmpty)
|
||||
InkWrapper(
|
||||
onPressed: () => setState(
|
||||
() => _showSubComments = !_showSubComments,
|
||||
|
|
@ -154,8 +153,15 @@ class CommentState extends State<Comment> {
|
|||
dislikeCount: comment.feedback.dislike,
|
||||
likeValue: comment.liked,
|
||||
dislikeValue: comment.disliked,
|
||||
onFeedback: (like, dislike) =>
|
||||
state.feedback(comment.id, like, dislike),
|
||||
onFeedback: (like, dislike, likeCount, dislikeCount) =>
|
||||
state.feedback(
|
||||
id: _comment.id,
|
||||
like: like,
|
||||
dislike: dislike,
|
||||
likeCount: likeCount,
|
||||
dislikeCount: dislikeCount,
|
||||
replyId: isReply ? comment.id : null,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
@ -172,7 +178,8 @@ class _FeedbackButtons extends StatefulWidget {
|
|||
final int dislikeCount;
|
||||
final bool likeValue;
|
||||
final bool dislikeValue;
|
||||
final void Function(bool like, bool dislike) onFeedback;
|
||||
final void Function(bool like, bool dislike, int likeCount, int dislikeCount)
|
||||
onFeedback;
|
||||
const _FeedbackButtons({
|
||||
Key? key,
|
||||
required this.onFeedback,
|
||||
|
|
@ -228,7 +235,8 @@ class _FeedbackButtonsState extends State<_FeedbackButtons> {
|
|||
}
|
||||
_likeValue = !_likeValue;
|
||||
});
|
||||
widget.onFeedback(_likeValue, _dislikeValue);
|
||||
widget.onFeedback(
|
||||
_likeValue, _dislikeValue, _likeCount, _dislikeCount);
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
|
|
@ -257,7 +265,8 @@ class _FeedbackButtonsState extends State<_FeedbackButtons> {
|
|||
}
|
||||
_dislikeValue = !_dislikeValue;
|
||||
});
|
||||
widget.onFeedback(_likeValue, _dislikeValue);
|
||||
widget.onFeedback(
|
||||
_likeValue, _dislikeValue, _likeCount, _dislikeCount);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in New Issue