Merge pull request #1827 from ecency/performance

Performance
This commit is contained in:
Feruz M 2021-01-19 13:22:30 +02:00 committed by GitHub
commit 0fdac9e24e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 46 additions and 33 deletions

View File

@ -28,35 +28,33 @@ const TagContainer = ({
style,
textStyle,
disabled,
communityTitle,
}) => {
const [label, setLabel] = useState(value);
const [isCommunity, setIsCommunity] = useState(false);
useEffect(() => {
let isCancelled = false;
if (value && /^hive-\d+/.test(value)) {
if (value && /hive-[1-3]\d{4,6}$/.test(value)) {
if (communityTitle) {
setLabel(communityTitle);
setIsCommunity(true);
} else {
getCommunityTitle(value)
.then((r) => {
if (!isCancelled) {
setLabel(r);
setIsCommunity(value !== r);
return r;
}
})
.catch((e) => {
if (!isCancelled) {
setLabel(value);
setIsCommunity(/^hive-\d+/.test(value));
setIsCommunity(/hive-[1-3]\d{4,6}$/.test(value));
return value;
}
});
}
} else {
setLabel(value);
setIsCommunity(false);
}
return () => {
isCancelled = true;
};
});
// Component Functions

View File

@ -37,7 +37,7 @@ const SelectCommunityModalView = ({
renderItem={({ item, index, separators }) => (
<CommunityCard
community={item}
key={index}
key={index.toString()}
onPress={onPressCommunity}
separators={separators}
/>

View File

@ -39,25 +39,25 @@ const PostCardContainer = ({
}, [isRefresh]);
useEffect(() => {
if (content) {
setActiveVotes(get(content, 'active_votes', []));
if (_content) {
setActiveVotes(get(_content, 'active_votes', []));
getPostReblogs(content).then((result) => {
getPostReblogs(_content).then((result) => {
setReblogs(result);
});
setContent(content);
setContent(_content);
}
}, [content]);
}, [_content]);
const _handleOnUserPress = () => {
if (content && get(currentAccount, 'name') !== get(content, 'author')) {
if (_content && get(currentAccount, 'name') !== get(_content, 'author')) {
navigation.navigate({
routeName: ROUTES.SCREENS.PROFILE,
params: {
username: get(content, 'author'),
reputation: get(content, 'author_reputation'),
username: get(_content, 'author'),
reputation: get(_content, 'author_reputation'),
},
key: get(content, 'author'),
key: get(_content, 'author'),
});
}
};
@ -79,9 +79,9 @@ const PostCardContainer = ({
routeName: ROUTES.SCREENS.VOTERS,
params: {
activeVotes,
content,
content: _content,
},
key: get(content, 'permlink'),
key: get(_content, 'permlink'),
});
};
@ -91,12 +91,16 @@ const PostCardContainer = ({
params: {
reblogs,
},
key: get(content, 'permlink', get(content, 'author', '')),
key: get(_content, 'permlink', get(_content, 'author', '')),
});
};
const _fetchPost = async () => {
await getPost(get(content, 'author'), get(content, 'permlink'), get(currentAccount, 'username'))
await getPost(
get(_content, 'author'),
get(_content, 'permlink'),
get(currentAccount, 'username'),
)
.then((result) => {
if (result) {
setContent(result);

View File

@ -102,7 +102,7 @@ const PostCardView = ({
profileOnPress={_handleOnUserPress}
reputation={get(content, 'author_reputation')}
size={36}
tag={content.category}
content={content}
rebloggedBy={rebloggedBy}
isPromoted={get(content, 'is_promoted')}
/>

View File

@ -46,6 +46,7 @@ class PostHeaderDescription extends PureComponent {
reputation,
size,
tag,
content,
tagOnPress,
isShowOwnerIndicator,
isPromoted,
@ -90,6 +91,16 @@ class PostHeaderDescription extends PureComponent {
</View>
</View>
<View style={styles.rightContainer}>
{!!content && (
<TouchableOpacity onPress={() => tagOnPress && tagOnPress()}>
<Tag
isPostCardTag={!isPromoted}
isPin
value={content.category}
communityTitle={content.community_title}
/>
</TouchableOpacity>
)}
{!!tag && (
<TouchableOpacity onPress={() => tagOnPress && tagOnPress()}>
<Tag isPostCardTag={!isPromoted} isPin value={tag} />

View File

@ -198,7 +198,7 @@ const PostDisplayView = ({
name={author || post.author}
currentAccountUsername={name}
reputation={post.author_reputation}
tag={post.category}
content={post}
size={36}
/>
<PostBody body={post.body} />

View File

@ -255,7 +255,7 @@ const PostsContainer = ({
const filter = type || selectedFilterValue;
const subfilter = selectedFeedSubfilterValue;
let options = {};
const limit = 7;
const limit = 5;
let func = null;
if (
@ -319,7 +319,7 @@ const PostsContainer = ({
_posts = unionBy(posts, _posts, 'permlink');
}
}
if (posts.length <= 7 && pageType !== 'profiles') {
if (posts.length <= 5 && pageType !== 'profiles') {
_setFeedPosts(_posts);
}