From 46acc61f7f0744ebdba8c441554fbdb0287662cd Mon Sep 17 00:00:00 2001 From: Nouman Tahir Date: Fri, 23 Apr 2021 00:05:54 +0500 Subject: [PATCH] fixed issues with initial posts, fixed tab sorting --- .../customiseFiltersModal.tsx | 10 ++++++++-- .../tabbedPosts/container/tabbedPosts.tsx | 2 +- .../tabbedPosts/services/tabbedPostsModels.ts | 2 +- src/components/tabbedPosts/view/tabContent.tsx | 14 ++++++++------ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/components/customiseFiltersModal/customiseFiltersModal.tsx b/src/components/customiseFiltersModal/customiseFiltersModal.tsx index 4abcd45c6..ef80fb1ea 100644 --- a/src/components/customiseFiltersModal/customiseFiltersModal.tsx +++ b/src/components/customiseFiltersModal/customiseFiltersModal.tsx @@ -19,6 +19,9 @@ export interface CustomiseFiltersModalRef { } +const getFeedScreenFilterIndex = (key:string) => Object.keys(FEED_SCREEN_FILTER_MAP).indexOf(key) + + const CustomiseFiltersModal = (props:any, ref:Ref) => { const sheetModalRef = useRef(); const dispatch = useDispatch(); @@ -26,7 +29,10 @@ const CustomiseFiltersModal = (props:any, ref:Ref) => const feedScreenFilters = useSelector(state => state.posts.feedScreenFilters || DEFAULT_FEED_FILTERS); const [selectedFilters, setSelectedFilters] = useState>( - new Map(feedScreenFilters.map((key:string, index:number)=>[key, index])) + new Map(feedScreenFilters.map((key:string)=>[ + key, + getFeedScreenFilterIndex(key) + ])) ); const intl = useIntl(); @@ -67,7 +73,7 @@ const CustomiseFiltersModal = (props:any, ref:Ref) => if(isSelected){ selectedFilters.delete(key); }else{ - var index = Object.keys(FEED_SCREEN_FILTER_MAP).indexOf(key); + var index = getFeedScreenFilterIndex(key); selectedFilters.set(key, index); } setSelectedFilters(new Map([...selectedFilters])); diff --git a/src/components/tabbedPosts/container/tabbedPosts.tsx b/src/components/tabbedPosts/container/tabbedPosts.tsx index d700a778c..66c6e30af 100644 --- a/src/components/tabbedPosts/container/tabbedPosts.tsx +++ b/src/components/tabbedPosts/container/tabbedPosts.tsx @@ -79,7 +79,7 @@ export const TabbedPosts = ({ key={filter.filterKey} filterKey={filter.filterKey} isFeedScreen={isFeedScreen} - isFirstTab={ index == 0} + isInitialTab={ initialTabIndex == index } feedUsername={feedUsername} pageType={pageType} filterScrollRequest={filterScrollRequest} diff --git a/src/components/tabbedPosts/services/tabbedPostsModels.ts b/src/components/tabbedPosts/services/tabbedPostsModels.ts index e11480a3f..6177b64a1 100644 --- a/src/components/tabbedPosts/services/tabbedPostsModels.ts +++ b/src/components/tabbedPosts/services/tabbedPostsModels.ts @@ -49,7 +49,7 @@ export interface TabMeta { export interface TabContentProps { filterKey:string, isFeedScreen:boolean, - isFirstTab:boolean, + isInitialTab:boolean, getFor:string, pageType:string, feedUsername:string, diff --git a/src/components/tabbedPosts/view/tabContent.tsx b/src/components/tabbedPosts/view/tabContent.tsx index 6f2b90f45..bef5458c3 100644 --- a/src/components/tabbedPosts/view/tabContent.tsx +++ b/src/components/tabbedPosts/view/tabContent.tsx @@ -20,7 +20,7 @@ const DEFAULT_TAB_META = { const TabContent = ({ filterKey, isFeedScreen, - isFirstTab, + isInitialTab, pageType, forceLoadPosts, filterScrollRequest, @@ -42,7 +42,7 @@ const TabContent = ({ const isConnected = useSelector((state) => state.application.isConnected); const username = useSelector((state) => state.account.currentAccount.name); const initPosts = useSelector((state) => { - if(isFeedScreen && isFirstTab){ + if(isFeedScreen && isInitialTab){ return state.posts.initPosts } return [] @@ -152,7 +152,7 @@ const TabContent = ({ const result = await loadPosts(options) if(_isMounted && result){ - _postProcessLoadResult(result, shouldReset) + _postProcessLoadResult(result) } } @@ -188,7 +188,7 @@ const TabContent = ({ //processes response from loadPost - const _postProcessLoadResult = ({updatedPosts, latestPosts}:any, shouldReset:boolean) => { + const _postProcessLoadResult = ({updatedPosts, latestPosts}:any) => { //process new posts avatart if(latestPosts && Array.isArray(latestPosts)){ if(latestPosts.length > 0){ @@ -200,11 +200,13 @@ const TabContent = ({ //process returned data if(updatedPosts && Array.isArray(updatedPosts)){ - if (isFeedScreen && shouldReset) { + //match new and old first post + const firstPostChanged = posts.length == 0 || (posts[0].permlink !== updatedPosts[0].permlink); + if (isFeedScreen && firstPostChanged) { // //schedule refetch of new posts by checking time of current post _scheduleLatestPostsCheck(updatedPosts[0]); - if (isFirstTab) { + if (isInitialTab) { dispatch(setInitPosts(updatedPosts)); } }