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 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 post creator can only like the post once and after it is actually created
## 3.0.1

View file

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

View file

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

View file

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