Fix debug mode fetch of FYP + some formatting cleanup

This commit is contained in:
infinite-persistence 2022-03-16 10:48:40 +08:00
parent e62031f0a2
commit fc3e3ae844
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0

View file

@ -66,12 +66,17 @@ export default function RecommendedPersonal(props: Props) {
const countCollapsed = getSuitablePageSizeForScreen(8, isLargeScreen, isMediumScreen); const countCollapsed = getSuitablePageSizeForScreen(8, isLargeScreen, isMediumScreen);
const finalCount = view === VIEW.ALL_VISIBLE ? count : view === VIEW.COLLAPSED ? countCollapsed : count; const finalCount = view === VIEW.ALL_VISIBLE ? count : view === VIEW.COLLAPSED ? countCollapsed : count;
// **************************************************************************
// Effects
// **************************************************************************
React.useEffect(() => { React.useEffect(() => {
// -- Update parent's callback request
onLoad(count > 0); onLoad(count > 0);
}, [count, onLoad]); }, [count, onLoad]);
// Resolve the view state:
React.useEffect(() => { React.useEffect(() => {
// -- Resolve the view state:
let newView; let newView;
if (count <= countCollapsed) { if (count <= countCollapsed) {
newView = VIEW.ALL_VISIBLE; newView = VIEW.ALL_VISIBLE;
@ -86,18 +91,23 @@ export default function RecommendedPersonal(props: Props) {
} }
}, [count, countCollapsed, view, setView]); }, [count, countCollapsed, view, setView]);
// Mark recommendations when rendered:
React.useEffect(() => { React.useEffect(() => {
// -- Mark recommendations when rendered:
if (userId && markedGid !== personalRecommendations.gid) { if (userId && markedGid !== personalRecommendations.gid) {
setMarkedGid(personalRecommendations.gid); setMarkedGid(personalRecommendations.gid);
recsysFyp.markPersonalRecommendations(userId, personalRecommendations.gid); recsysFyp.markPersonalRecommendations(userId, personalRecommendations.gid);
} }
}, [userId, markedGid, personalRecommendations.gid]); }, [userId, markedGid, personalRecommendations.gid]);
// Fetch on mount:
React.useEffect(() => { React.useEffect(() => {
hasMembership && doFetchPersonalRecommendations(); // -- Fetch FYP
}, [hasMembership]); // eslint-disable-line react-hooks/exhaustive-deps if (hasMembership || process.env.ENABLE_WIP_FEATURES) {
doFetchPersonalRecommendations();
}
}, [hasMembership, doFetchPersonalRecommendations]);
// **************************************************************************
// **************************************************************************
if ((!hasMembership && !process.env.ENABLE_WIP_FEATURES) || count < 1) { if ((!hasMembership && !process.env.ENABLE_WIP_FEATURES) || count < 1) {
return null; return null;