From b8388a428625ab1e165e5d2b871c266e8abd34fd Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Sat, 20 Feb 2021 13:33:54 -0500 Subject: fixed loading issues --- src/screens/suggestedPeople/SuggestedPeopleScreen.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/screens/suggestedPeople/SuggestedPeopleScreen.tsx b/src/screens/suggestedPeople/SuggestedPeopleScreen.tsx index 66ad8ee9..d047d038 100644 --- a/src/screens/suggestedPeople/SuggestedPeopleScreen.tsx +++ b/src/screens/suggestedPeople/SuggestedPeopleScreen.tsx @@ -89,15 +89,21 @@ const SuggestedPeopleScreen: React.FC = () => { const loadMore = async (resetData: boolean) => { const loadNextPage = async () => - await getSuggestedPeople(SP_PAGE_SIZE, page * SP_PAGE_SIZE); + await getSuggestedPeople( + SP_PAGE_SIZE, + resetData ? 0 : page * SP_PAGE_SIZE, + ); loadNextPage().then((newUsers) => { + loadUserDataToStore(newUsers.map((ppl) => ppl.user)); + let newPeople = []; if (resetData) { - setPeople([]); + newPeople = newUsers; setPage(0); + } else { + newPeople = people.concat(newUsers); } - loadUserDataToStore(newUsers.map((ppl) => ppl.user)); - setPeople(people.concat(newUsers)); + setPeople(newPeople); }); }; -- cgit v1.2.3-70-g09d2