From cbb3e840e95cdf6fb0919504b637ef6d68b2346a Mon Sep 17 00:00:00 2001 From: rupansh Date: Mon, 15 Jan 2024 10:01:11 +0530 Subject: [PATCH] fix(post_view): gracefully handle broken initial post --- src/page/post_view/mod.rs | 37 +++++++++++++++++------------- src/page/post_view/video_loader.rs | 16 +++++++------ 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/page/post_view/mod.rs b/src/page/post_view/mod.rs index c7f4c1a5..639b847b 100644 --- a/src/page/post_view/mod.rs +++ b/src/page/post_view/mod.rs @@ -75,7 +75,7 @@ pub fn ScrollingView() -> impl IntoView { view! {
impl IntoView { } #[component] -pub fn PostViewWithUpdates(initial_post: PostDetails) -> impl IntoView { +pub fn PostViewWithUpdates(initial_post: Option) -> impl IntoView { + let (fetch_cursor, set_fetch_cursor) = create_signal({ + let mut fetch_cursor = FetchCursor { + start: 1, + limit: POST_CNT as u64, + }; + if initial_post.is_some() { + fetch_cursor.limit -= 1; + } + fetch_cursor + }); + // TODO: this is a dead simple with no GC // We're using virtual lists for DOM, so this doesn't consume much memory // as uids only occupy 32 bytes each // but ideally this should be cleaned up - let (video_queue, set_video_queue) = create_signal(vec![initial_post]); + let (video_queue, set_video_queue) = + create_signal(initial_post.map(|p| vec![p]).unwrap_or_default()); let current_idx = create_rw_signal(0); - let (fetch_cursor, set_fetch_cursor) = create_signal(FetchCursor { - start: 1, - limit: POST_CNT as u64 - 1, - }); let fetch_video_uids = Resource::once(move || async move { let canisters = expect_context::(); @@ -182,17 +190,15 @@ pub fn PostView() -> impl IntoView { go_to_root(); return None; }; - let uid = match get_post_uid(&canisters, canister, post).await { - Ok(Some(uid)) => uid, + + match get_post_uid(&canisters, canister, post).await { + Ok(Some(uid)) => Some(uid), Err(e) => { failure_redirect(e); - return None; + None } - Ok(None) => { - panic!("initial post not found"); - } - }; - Some(uid) + Ok(None) => None, + } }, ); @@ -202,7 +208,6 @@ pub fn PostView() -> impl IntoView { {move || { fetch_first_video_uid .get() - .flatten() .map(|post| view! { }) }} diff --git a/src/page/post_view/video_loader.rs b/src/page/post_view/video_loader.rs index e8a5275b..b37c3181 100644 --- a/src/page/post_view/video_loader.rs +++ b/src/page/post_view/video_loader.rs @@ -32,10 +32,11 @@ pub fn HlsVideo(video_ref: NodeRef