Skip to content

Commit

Permalink
Merge pull request #288 from go-bazzinga/fix/like-count
Browse files Browse the repository at this point in the history
Fix like count reset post navigation
  • Loading branch information
adarsh-kumar-yral authored Aug 9, 2024
2 parents 641dab8 + c3e496e commit 84ccca6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions ssr/src/page/post_view/overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn LikeAndAuthCanLoader(post: PostDetails) -> impl IntoView {

let post_canister = post.canister_id;
let post_id = post.post_id;
let initial_liked = post.liked_by_user;
let initial_liked = (post.liked_by_user, post.likes);
let canisters = auth_canisters_store();

let like_toggle = create_action(move |&()| {
Expand Down Expand Up @@ -72,15 +72,15 @@ fn LikeAndAuthCanLoader(post: PostDetails) -> impl IntoView {
});

let liked_fetch = move |cans: Canisters<true>| async move {
if let Some(liked) = initial_liked {
return liked;
if let Some(liked) = initial_liked.0 {
return (liked, initial_liked.1);
}

match post_liked_by_me(&cans, post_canister, post_id).await {
Ok(liked) => liked,
Err(e) => {
failure_redirect(e);
false
(false, likes.get())
}
}
};
Expand All @@ -98,7 +98,10 @@ fn LikeAndAuthCanLoader(post: PostDetails) -> impl IntoView {
<span class="absolute -bottom-5 text-sm md:text-md">{likes}</span>
</div>
<WithAuthCans with=liked_fetch let:d>
{move || liked.set(Some(d.1))}
{move || {
likes.set(d.1.1);
liked.set(Some(d.1.0))
}}
</WithAuthCans>
}
}
Expand Down
4 changes: 2 additions & 2 deletions ssr/src/page/post_view/video_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ pub async fn post_liked_by_me(
canisters: &Canisters<true>,
post_canister: Principal,
post_id: u64,
) -> Result<bool, PostViewError> {
) -> Result<(bool, u64), PostViewError> {
let individual = canisters.individual_user(post_canister).await?;
let post = individual
.get_individual_post_details_by_id(post_id)
.await?;
Ok(post.liked_by_me)
Ok((post.liked_by_me, post.like_count))
}

type PostsStream<'a> = Pin<Box<dyn Stream<Item = Vec<Result<PostDetails, PostViewError>>> + 'a>>;
Expand Down

0 comments on commit 84ccca6

Please sign in to comment.