From 04fb46404f6af71682b3d6489332e075c29b4029 Mon Sep 17 00:00:00 2001 From: natjms Date: Thu, 19 May 2022 17:55:21 -0700 Subject: [PATCH] Ensure event actually fires when the timeline is loaded --- src/components/pages/feed.js | 8 +++++--- src/components/posts/post.js | 9 +++++---- src/components/posts/timeline-view.js | 4 +++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/components/pages/feed.js b/src/components/pages/feed.js index 23b3688..830e2f6 100644 --- a/src/components/pages/feed.js +++ b/src/components/pages/feed.js @@ -64,9 +64,11 @@ const Feed = (props) => { ); }, []); - const _handleTimelineLoaded = () => setState({...state, - postsRendered: true, - }); + const _handleTimelineLoaded = () => { + setState({...state, + postsRendered: true, + }); + }; let endOfTimelineMessage = <>; if (state.postsRendered) { diff --git a/src/components/posts/post.js b/src/components/posts/post.js index 6b89acd..e4f10c8 100644 --- a/src/components/posts/post.js +++ b/src/components/posts/post.js @@ -220,13 +220,14 @@ export const PostByData = (props) => { own, loaded: true }); - - if (props.onPostLoaded != null) { - props.onPostLoaded(); - } }); }, []); + useEffect(() => { + // This is run after the state has been updated + props.onPostLoaded(); + }, [state]) + const _handleFavourite = async () => { let newStatus; diff --git a/src/components/posts/timeline-view.js b/src/components/posts/timeline-view.js index 208603f..8dbc6e4 100644 --- a/src/components/posts/timeline-view.js +++ b/src/components/posts/timeline-view.js @@ -23,7 +23,9 @@ const TimelineView = (props) => { } }, [postsLoaded]); - _handlePostLoaded = () => setPostsLoaded(postsLoaded + 1); + const _handlePostLoaded = () => { + setPostsLoaded(postsLoaded + 1); + } return (