diff --git a/src/page/post_view/mod.rs b/src/page/post_view/mod.rs index c35dd529..639b847b 100644 --- a/src/page/post_view/mod.rs +++ b/src/page/post_view/mod.rs @@ -36,7 +36,7 @@ struct FetchCursor { struct VideoCtx { video_queue: ReadSignal>, current_idx: RwSignal, - trigger_fetch: Action<(), ()>, + trigger_fetch: Resource<(), ()>, } const POST_CNT: usize = 25; @@ -75,7 +75,7 @@ pub fn ScrollingView() -> impl IntoView { view! {
impl IntoView { key=|u| (u.0, u.1.uid.clone()) children=move |(queue_idx, details)| { 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 = create_action(move |&()| async move { + let fetch_video_uids = Resource::once(move || async move { let canisters = expect_context::(); let cursor = fetch_cursor.get_untracked(); let fetch_stream = VideoFetchStream::new(&canisters, cursor); - let chunks = try_or_redirect!(fetch_stream.fetch_post_uids_chunked(10).await); + let chunks = try_or_redirect!(fetch_stream.fetch_post_uids_chunked(8).await); let mut chunks = pin!(chunks); while let Some(chunk) = chunks.next().await { set_video_queue.update(|q| { @@ -135,10 +143,6 @@ pub fn PostViewWithUpdates(initial_post: PostDetails) -> impl IntoView { }); }); - create_effect(move |_| { - fetch_video_uids.dispatch(()); - }); - provide_context(VideoCtx { video_queue, current_idx, @@ -186,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, + } }, ); @@ -206,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 869bb66c..b37c3181 100644 --- a/src/page/post_view/video_loader.rs +++ b/src/page/post_view/video_loader.rs @@ -14,10 +14,10 @@ use super::VideoCtx; pub fn BgView(uid: String, children: Children) -> impl IntoView { view! {
-
+
{children()}
@@ -32,21 +32,28 @@ pub fn HlsVideo(video_ref: NodeRef