upgraded <Posts/> to <TabbedPosts/>

This commit is contained in:
Nouman Tahir 2021-04-10 22:38:28 +05:00
parent b14191604f
commit ff07db328a
8 changed files with 18 additions and 13 deletions

View File

@ -151,7 +151,7 @@ const postsListContainer = ({
data={posts} data={posts}
showsVerticalScrollIndicator={false} showsVerticalScrollIndicator={false}
renderItem={_renderItem} renderItem={_renderItem}
keyExtractor={(content) => content.permlink} keyExtractor={(content) => `${content.author}/${content.permlink}`}
removeClippedSubviews removeClippedSubviews
onEndReachedThreshold={1} onEndReachedThreshold={1}
maxToRenderPerBatch={3} maxToRenderPerBatch={3}

View File

@ -23,6 +23,7 @@ import { getFormatedCreatedDate } from '../../utils/time';
// Styles // Styles
import styles from './profileStyles'; import styles from './profileStyles';
import globalStyles from '../../globalStyles'; import globalStyles from '../../globalStyles';
import { TabbedPosts } from '../tabbedPosts';
class ProfileView extends PureComponent { class ProfileView extends PureComponent {
constructor(props) { constructor(props) {
@ -191,7 +192,7 @@ class ProfileView extends PureComponent {
tabLabel={this._getTabLabel(intl.formatMessage({ id: 'profile.post' }))} tabLabel={this._getTabLabel(intl.formatMessage({ id: 'profile.post' }))}
style={styles.postTabBar} style={styles.postTabBar}
> >
<Posts <TabbedPosts
filterOptions={PROFILE_FILTERS} filterOptions={PROFILE_FILTERS}
filterOptionsValue={PROFILE_FILTERS_VALUE} filterOptionsValue={PROFILE_FILTERS_VALUE}
selectedOptionIndex={0} selectedOptionIndex={0}

View File

@ -13,7 +13,7 @@ import TabContent from '../view/tabContent';
export const TabbedPosts = ({ export const TabbedPosts = ({
filterOptions, filterOptions,
filterOptionsValue, filterOptionsValue,
initialFilterIndex, selectedOptionIndex,
feedSubfilterOptions, feedSubfilterOptions,
feedSubfilterOptionsValue, feedSubfilterOptionsValue,
isFeedScreen, isFeedScreen,
@ -31,7 +31,7 @@ export const TabbedPosts = ({
//initialize state //initialize state
const [initialTabIndex] = useState(initialFilterIndex == 0 && isFeedScreen ? filterOptions.length : initialFilterIndex) const [initialTabIndex] = useState(selectedOptionIndex == 0 && isFeedScreen ? filterOptions.length : selectedOptionIndex)
// const [promotedPosts, setPromotedPosts] = useState([]); // const [promotedPosts, setPromotedPosts] = useState([]);
const [mainFilters] = useState<TabItem[]>( const [mainFilters] = useState<TabItem[]>(
@ -42,10 +42,12 @@ export const TabbedPosts = ({
) )
const [subFilters] = useState<TabItem[]>( const [subFilters] = useState<TabItem[]>(
feedSubfilterOptions.map((label, index)=>({ feedSubfilterOptions
? feedSubfilterOptions.map((label, index)=>({
filterKey:feedSubfilterOptionsValue[index], filterKey:feedSubfilterOptionsValue[index],
label label
} as TabItem)) } as TabItem))
: []
) )
const [combinedFilters] = useState([...mainFilters, ...subFilters]); const [combinedFilters] = useState([...mainFilters, ...subFilters]);
@ -121,7 +123,7 @@ export const TabbedPosts = ({
shouldStack={isFeedScreen && feedUsername} shouldStack={isFeedScreen && feedUsername}
firstStack={mainFilters} firstStack={mainFilters}
secondStack={subFilters} secondStack={subFilters}
initialFirstStackIndex={initialFilterIndex} initialFirstStackIndex={selectedOptionIndex}
onFilterSelect={_onFilterSelect} onFilterSelect={_onFilterSelect}
toggleHideImagesFlag={_toggleHideImagesFlag} toggleHideImagesFlag={_toggleHideImagesFlag}
/> />
@ -132,6 +134,7 @@ export const TabbedPosts = ({
return ( return (
<ScrollableTabView <ScrollableTabView
scrollWithoutAnimation={true} scrollWithoutAnimation={true}
locked={true}
initialPage={initialTabIndex} initialPage={initialTabIndex}
renderTabBar={_renderTabBar}> renderTabBar={_renderTabBar}>
{pages} {pages}

View File

@ -4,7 +4,7 @@ export interface TabbedPostsProps {
filterOptionsValue:string[], filterOptionsValue:string[],
isFeedScreen:boolean, isFeedScreen:boolean,
feedUsername:string, feedUsername:string,
initialFilterIndex:number, selectedOptionIndex:number,
feedSubfilterOptions:string[], feedSubfilterOptions:string[],
feedSubfilterOptionsValue:string[], feedSubfilterOptionsValue:string[],
getFor:string, getFor:string,

View File

@ -60,9 +60,10 @@ const TabContent = ({
if (isFeedScreen) { if (isFeedScreen) {
AppState.addEventListener('change', _handleAppStateChange); AppState.addEventListener('change', _handleAppStateChange);
_initContent(true);
} }
_initContent(true);
return _cleanup; return _cleanup;
}, []) }, [])

View File

@ -3,7 +3,7 @@ import { View, Text } from 'react-native';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
// Components // Components
import { Posts, CollapsibleCard, Header, BasicHeader } from '../../../components'; import { Posts, CollapsibleCard, Header, BasicHeader, TabbedPosts } from '../../../components';
import { Tag, ProfileSummaryPlaceHolder } from '../../../components/basicUIElements'; import { Tag, ProfileSummaryPlaceHolder } from '../../../components/basicUIElements';
import CommunityContainer from '../container/communityContainer'; import CommunityContainer from '../container/communityContainer';
@ -100,7 +100,7 @@ const CommunityScreen = ({ navigation }) => {
<ProfileSummaryPlaceHolder /> <ProfileSummaryPlaceHolder />
)} )}
<View tabLabel={intl.formatMessage({ id: 'search.posts' })} style={styles.tabbarItem}> <View tabLabel={intl.formatMessage({ id: 'search.posts' })} style={styles.tabbarItem}>
<Posts <TabbedPosts
key={tag} key={tag}
filterOptions={GLOBAL_POST_FILTERS} filterOptions={GLOBAL_POST_FILTERS}
filterOptionsValue={GLOBAL_POST_FILTERS_VALUE} filterOptionsValue={GLOBAL_POST_FILTERS_VALUE}

View File

@ -31,7 +31,7 @@ const FeedScreen = () => {
feedSubfilterOptions={[...FEED_SUBFILTERS]} feedSubfilterOptions={[...FEED_SUBFILTERS]}
feedSubfilterOptionsValue={[...FEED_SUBFILTERS_VALUE]} feedSubfilterOptionsValue={[...FEED_SUBFILTERS_VALUE]}
getFor={get(currentAccount, 'name', null) ? 'feed' : 'hot'} getFor={get(currentAccount, 'name', null) ? 'feed' : 'hot'}
initialFilterIndex={get(currentAccount, 'name', null) ? 0 : 2} selectedOptionIndex={get(currentAccount, 'name', null) ? 0 : 2}
feedUsername={get(currentAccount, 'name', null)} feedUsername={get(currentAccount, 'name', null)}
isFeedScreen={true} isFeedScreen={true}
/> />

View File

@ -4,7 +4,7 @@ import ScrollableTabView from 'react-native-scrollable-tab-view';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
// Components // Components
import { SearchInput, Posts, TabBar } from '../../../components'; import { SearchInput, Posts, TabBar, TabbedPosts } from '../../../components';
// Styles // Styles
import styles from './tagResultStyles'; import styles from './tagResultStyles';
@ -52,7 +52,7 @@ const TagResultScreen = ({ navigation }) => {
</SafeAreaView> </SafeAreaView>
<ScrollableTabView style={globalStyles.tabView} renderTabBar={_renderTabbar}> <ScrollableTabView style={globalStyles.tabView} renderTabBar={_renderTabbar}>
<View tabLabel={intl.formatMessage({ id: 'search.posts' })} style={styles.tabbarItem}> <View tabLabel={intl.formatMessage({ id: 'search.posts' })} style={styles.tabbarItem}>
<Posts <TabbedPosts
key={tag} key={tag}
filterOptions={GLOBAL_POST_FILTERS} filterOptions={GLOBAL_POST_FILTERS}
filterOptionsValue={GLOBAL_POST_FILTERS_VALUE} filterOptionsValue={GLOBAL_POST_FILTERS_VALUE}