Skip to content

Commit

Permalink
Fix: fix like count reset post navigation
Browse files Browse the repository at this point in the history
update likes and liked
 status after user's likes is fetched
  • Loading branch information
adarsh-kumar-yral committed Aug 5, 2024
1 parent 21f9871 commit 3833792
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions ssr/src/page/post_view/overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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 @@ -79,15 +79,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 @@ -106,7 +106,7 @@ 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 3833792

Please sign in to comment.