fix: initialize post with empty like count so posts liking works correctly

This commit is contained in:
Freek van de Ven 2024-05-23 14:40:15 +02:00
parent 6a522f3209
commit 35028b9bb9
4 changed files with 7 additions and 3 deletions

View file

@ -17,6 +17,7 @@
- Fix category key is correctly used for saving timeline posts and category title is shown everywhere - Fix category key is correctly used for saving timeline posts and category title is shown everywhere
- Fix when clicking on post delete in the post screen of the userstory it will now navigate back to the timeline and delete the post - Fix when clicking on post delete in the post screen of the userstory it will now navigate back to the timeline and delete the post
- Fix like icon being used for both like and unliked posts - Fix like icon being used for both like and unliked posts
- Fix post creator can only like the post once and after it is actually created
## 3.0.1 ## 3.0.1

View file

@ -254,7 +254,7 @@ class FirebaseTimelinePostService
// update the post with the new like // update the post with the new like
var updatedPost = post.copyWith( var updatedPost = post.copyWith(
likes: post.likes + 1, likes: post.likes + 1,
likedBy: post.likedBy?..add(userId), likedBy: [...post.likedBy ?? [], userId],
); );
posts = posts posts = posts
.map( .map(

View file

@ -104,6 +104,7 @@ class _TimelinePostCreationScreenState
category: widget.postCategory, category: widget.postCategory,
content: contentController.text, content: contentController.text,
likes: 0, likes: 0,
likedBy: const [],
reaction: 0, reaction: 0,
createdAt: DateTime.now(), createdAt: DateTime.now(),
reactionEnabled: allowComments, reactionEnabled: allowComments,

View file

@ -191,8 +191,9 @@ class _TimelinePostScreenState extends State<TimelinePostScreen> {
), ),
), ),
const Spacer(), const Spacer(),
if (widget.options.allowAllDeletion || if (!(widget.isOverviewScreen ?? false) &&
post.creator?.userId == widget.userId) (widget.options.allowAllDeletion ||
post.creator?.userId == widget.userId))
PopupMenuButton( PopupMenuButton(
onSelected: (value) => widget.onPostDelete.call(), onSelected: (value) => widget.onPostDelete.call(),
itemBuilder: (BuildContext context) => itemBuilder: (BuildContext context) =>
@ -305,6 +306,7 @@ class _TimelinePostScreenState extends State<TimelinePostScreen> {
] else ...[ ] else ...[
InkWell( InkWell(
onTap: () async { onTap: () async {
if (widget.isOverviewScreen ?? false) return;
updatePost( updatePost(
await widget.service.postService.likePost( await widget.service.postService.likePost(
widget.userId, widget.userId,