From 3833792f0c4701318a6ad449ffd2820ac42ecc01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAdarsh?= Date: Mon, 5 Aug 2024 11:54:35 +0530 Subject: [PATCH] Fix: fix like count reset post navigation update likes and liked status after user's likes is fetched --- ssr/src/page/post_view/overlay.rs | 10 +++++----- ssr/src/page/post_view/video_iter.rs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ssr/src/page/post_view/overlay.rs b/ssr/src/page/post_view/overlay.rs index c37b7e336..aaffe65bf 100644 --- a/ssr/src/page/post_view/overlay.rs +++ b/ssr/src/page/post_view/overlay.rs @@ -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 |&()| { @@ -79,15 +79,15 @@ fn LikeAndAuthCanLoader(post: PostDetails) -> impl IntoView { }); let liked_fetch = move |cans: Canisters| 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()) } } }; @@ -106,7 +106,7 @@ fn LikeAndAuthCanLoader(post: PostDetails) -> impl IntoView { {likes} - {move || liked.set(Some(d.1))} + {move || {likes.set(d.1.1);liked.set(Some(d.1.0))}} } } diff --git a/ssr/src/page/post_view/video_iter.rs b/ssr/src/page/post_view/video_iter.rs index f4a768d62..c41a83285 100644 --- a/ssr/src/page/post_view/video_iter.rs +++ b/ssr/src/page/post_view/video_iter.rs @@ -13,12 +13,12 @@ pub async fn post_liked_by_me( canisters: &Canisters, post_canister: Principal, post_id: u64, -) -> Result { +) -> 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>> + 'a>>;