fixed issues with initial posts, fixed tab sorting

This commit is contained in:
Nouman Tahir 2021-04-23 00:05:54 +05:00
parent 8fac936079
commit 46acc61f7f
4 changed files with 18 additions and 10 deletions

View File

@ -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<CustomiseFiltersModalRef>) => { const CustomiseFiltersModal = (props:any, ref:Ref<CustomiseFiltersModalRef>) => {
const sheetModalRef = useRef<ActionSheet>(); const sheetModalRef = useRef<ActionSheet>();
const dispatch = useDispatch(); const dispatch = useDispatch();
@ -26,7 +29,10 @@ const CustomiseFiltersModal = (props:any, ref:Ref<CustomiseFiltersModalRef>) =>
const feedScreenFilters = useSelector(state => state.posts.feedScreenFilters || DEFAULT_FEED_FILTERS); const feedScreenFilters = useSelector(state => state.posts.feedScreenFilters || DEFAULT_FEED_FILTERS);
const [selectedFilters, setSelectedFilters] = useState<Map<string, number>>( const [selectedFilters, setSelectedFilters] = useState<Map<string, number>>(
new Map(feedScreenFilters.map((key:string, index:number)=>[key, index])) new Map(feedScreenFilters.map((key:string)=>[
key,
getFeedScreenFilterIndex(key)
]))
); );
const intl = useIntl(); const intl = useIntl();
@ -67,7 +73,7 @@ const CustomiseFiltersModal = (props:any, ref:Ref<CustomiseFiltersModalRef>) =>
if(isSelected){ if(isSelected){
selectedFilters.delete(key); selectedFilters.delete(key);
}else{ }else{
var index = Object.keys(FEED_SCREEN_FILTER_MAP).indexOf(key); var index = getFeedScreenFilterIndex(key);
selectedFilters.set(key, index); selectedFilters.set(key, index);
} }
setSelectedFilters(new Map([...selectedFilters])); setSelectedFilters(new Map([...selectedFilters]));

View File

@ -79,7 +79,7 @@ export const TabbedPosts = ({
key={filter.filterKey} key={filter.filterKey}
filterKey={filter.filterKey} filterKey={filter.filterKey}
isFeedScreen={isFeedScreen} isFeedScreen={isFeedScreen}
isFirstTab={ index == 0} isInitialTab={ initialTabIndex == index }
feedUsername={feedUsername} feedUsername={feedUsername}
pageType={pageType} pageType={pageType}
filterScrollRequest={filterScrollRequest} filterScrollRequest={filterScrollRequest}

View File

@ -49,7 +49,7 @@ export interface TabMeta {
export interface TabContentProps { export interface TabContentProps {
filterKey:string, filterKey:string,
isFeedScreen:boolean, isFeedScreen:boolean,
isFirstTab:boolean, isInitialTab:boolean,
getFor:string, getFor:string,
pageType:string, pageType:string,
feedUsername:string, feedUsername:string,

View File

@ -20,7 +20,7 @@ const DEFAULT_TAB_META = {
const TabContent = ({ const TabContent = ({
filterKey, filterKey,
isFeedScreen, isFeedScreen,
isFirstTab, isInitialTab,
pageType, pageType,
forceLoadPosts, forceLoadPosts,
filterScrollRequest, filterScrollRequest,
@ -42,7 +42,7 @@ const TabContent = ({
const isConnected = useSelector((state) => state.application.isConnected); const isConnected = useSelector((state) => state.application.isConnected);
const username = useSelector((state) => state.account.currentAccount.name); const username = useSelector((state) => state.account.currentAccount.name);
const initPosts = useSelector((state) => { const initPosts = useSelector((state) => {
if(isFeedScreen && isFirstTab){ if(isFeedScreen && isInitialTab){
return state.posts.initPosts return state.posts.initPosts
} }
return [] return []
@ -152,7 +152,7 @@ const TabContent = ({
const result = await loadPosts(options) const result = await loadPosts(options)
if(_isMounted && result){ if(_isMounted && result){
_postProcessLoadResult(result, shouldReset) _postProcessLoadResult(result)
} }
} }
@ -188,7 +188,7 @@ const TabContent = ({
//processes response from loadPost //processes response from loadPost
const _postProcessLoadResult = ({updatedPosts, latestPosts}:any, shouldReset:boolean) => { const _postProcessLoadResult = ({updatedPosts, latestPosts}:any) => {
//process new posts avatart //process new posts avatart
if(latestPosts && Array.isArray(latestPosts)){ if(latestPosts && Array.isArray(latestPosts)){
if(latestPosts.length > 0){ if(latestPosts.length > 0){
@ -200,11 +200,13 @@ const TabContent = ({
//process returned data //process returned data
if(updatedPosts && Array.isArray(updatedPosts)){ 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 // //schedule refetch of new posts by checking time of current post
_scheduleLatestPostsCheck(updatedPosts[0]); _scheduleLatestPostsCheck(updatedPosts[0]);
if (isFirstTab) { if (isInitialTab) {
dispatch(setInitPosts(updatedPosts)); dispatch(setInitPosts(updatedPosts));
} }
} }