Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix like count reset post navigation #288

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading