From fc3e3ae8444191f360e789f63e11362d03c9dea6 Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Wed, 16 Mar 2022 10:48:40 +0800 Subject: [PATCH] Fix debug mode fetch of FYP + some formatting cleanup --- ui/component/recommendedPersonal/view.jsx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/ui/component/recommendedPersonal/view.jsx b/ui/component/recommendedPersonal/view.jsx index 72e0182c2..18e96de2d 100644 --- a/ui/component/recommendedPersonal/view.jsx +++ b/ui/component/recommendedPersonal/view.jsx @@ -66,12 +66,17 @@ export default function RecommendedPersonal(props: Props) { const countCollapsed = getSuitablePageSizeForScreen(8, isLargeScreen, isMediumScreen); const finalCount = view === VIEW.ALL_VISIBLE ? count : view === VIEW.COLLAPSED ? countCollapsed : count; + // ************************************************************************** + // Effects + // ************************************************************************** + React.useEffect(() => { + // -- Update parent's callback request onLoad(count > 0); }, [count, onLoad]); - // Resolve the view state: React.useEffect(() => { + // -- Resolve the view state: let newView; if (count <= countCollapsed) { newView = VIEW.ALL_VISIBLE; @@ -86,18 +91,23 @@ export default function RecommendedPersonal(props: Props) { } }, [count, countCollapsed, view, setView]); - // Mark recommendations when rendered: React.useEffect(() => { + // -- Mark recommendations when rendered: if (userId && markedGid !== personalRecommendations.gid) { setMarkedGid(personalRecommendations.gid); recsysFyp.markPersonalRecommendations(userId, personalRecommendations.gid); } }, [userId, markedGid, personalRecommendations.gid]); - // Fetch on mount: React.useEffect(() => { - hasMembership && doFetchPersonalRecommendations(); - }, [hasMembership]); // eslint-disable-line react-hooks/exhaustive-deps + // -- Fetch FYP + if (hasMembership || process.env.ENABLE_WIP_FEATURES) { + doFetchPersonalRecommendations(); + } + }, [hasMembership, doFetchPersonalRecommendations]); + + // ************************************************************************** + // ************************************************************************** if ((!hasMembership && !process.env.ENABLE_WIP_FEATURES) || count < 1) { return null;