mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-17 10:21:33 +03:00
Merge pull request #2075 from ecency/nt/profile-comments
Nt/profile comments
This commit is contained in:
commit
5fccccdaf2
@ -27,6 +27,7 @@ const CommentsTabContent = ({isOwnProfile, username, type, onScroll, selectedUse
|
||||
const [lastAuthor, setLastAuthor] = useState('');
|
||||
const [lastPermlink, setLastPermlink] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const [noMore, setNoMore] = useState(false);
|
||||
|
||||
|
||||
@ -34,21 +35,23 @@ const CommentsTabContent = ({isOwnProfile, username, type, onScroll, selectedUse
|
||||
if(selectedUser){
|
||||
_fetchData();
|
||||
}
|
||||
|
||||
}, [selectedUser])
|
||||
|
||||
|
||||
const _fetchData = async () => {
|
||||
if(loading || noMore){
|
||||
const _fetchData = async ({refresh}:{refresh?:boolean} = {}) => {
|
||||
if(loading || (!refresh && noMore)){
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
if(refresh){
|
||||
setRefreshing(true);
|
||||
}
|
||||
|
||||
const query:any = {
|
||||
account:username,
|
||||
start_author: lastAuthor,
|
||||
start_permlink: lastPermlink,
|
||||
start_author: refresh ? '' : lastAuthor,
|
||||
start_permlink: refresh ? '' : lastPermlink,
|
||||
limit:10,
|
||||
observer:'',
|
||||
sort:type
|
||||
@ -62,7 +65,7 @@ const CommentsTabContent = ({isOwnProfile, username, type, onScroll, selectedUse
|
||||
}
|
||||
|
||||
const result = await getAccountPosts(query)
|
||||
let _comments:any[] = unionBy(data, result, 'permlink');
|
||||
let _comments:any[] = refresh ? result : unionBy(data, result, 'permlink');
|
||||
|
||||
if(Array.isArray(_comments)){
|
||||
setData(_comments);
|
||||
@ -79,6 +82,7 @@ const CommentsTabContent = ({isOwnProfile, username, type, onScroll, selectedUse
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
setRefreshing(false);
|
||||
|
||||
}
|
||||
|
||||
@ -122,7 +126,13 @@ const CommentsTabContent = ({isOwnProfile, username, type, onScroll, selectedUse
|
||||
onScroll:onScroll,
|
||||
ListEmptyComponent:_renderListEmpty,
|
||||
ListFooterComponent:_renderListFooter,
|
||||
onEndReachedThreshold:1
|
||||
onEndReachedThreshold:1,
|
||||
refreshControl:(
|
||||
<RefreshControl
|
||||
refreshing={refreshing}
|
||||
onRefresh={()=>_fetchData({refresh:true})}
|
||||
/>
|
||||
)
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
|
@ -522,7 +522,7 @@ export const getRankedPosts = async (query, currentUserName, filterNsfw) => {
|
||||
|
||||
if (posts) {
|
||||
const areComments = query.sort === 'comments' || query.sort === 'replies';
|
||||
posts = parsePosts(posts, currentUserName, areComments);
|
||||
posts = areComments ? parseComments(posts) : parsePosts(posts, currentUserName);
|
||||
|
||||
if (filterNsfw !== '0') {
|
||||
const updatedPosts = filterNsfwPost(posts, filterNsfw);
|
||||
@ -543,7 +543,7 @@ export const getAccountPosts = async (query, currentUserName, filterNsfw) => {
|
||||
|
||||
if (posts) {
|
||||
const areComments = query.sort === 'comments' || query.sort === 'replies';
|
||||
posts = parsePosts(posts, currentUserName, areComments);
|
||||
posts = areComments ? parseComments(posts) : parsePosts(posts, currentUserName);
|
||||
|
||||
if (filterNsfw !== '0') {
|
||||
const updatedPosts = filterNsfwPost(posts, filterNsfw);
|
||||
|
@ -12,17 +12,17 @@ import { parseReputation } from './user';
|
||||
|
||||
const webp = Platform.OS === 'ios' ? false : true;
|
||||
|
||||
export const parsePosts = (posts, currentUserName, areComments) => {
|
||||
export const parsePosts = (posts, currentUserName) => {
|
||||
if (posts) {
|
||||
const formattedPosts = posts.map((post) =>
|
||||
parsePost(post, currentUserName, false, true, areComments),
|
||||
parsePost(post, currentUserName, false, true),
|
||||
);
|
||||
return formattedPosts;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
export const parsePost = (post, currentUserName, isPromoted, isList = false, isComment = false) => {
|
||||
export const parsePost = (post, currentUserName, isPromoted, isList = false) => {
|
||||
if (!post) {
|
||||
return null;
|
||||
}
|
||||
@ -62,7 +62,7 @@ export const parsePost = (post, currentUserName, isPromoted, isList = false, isC
|
||||
post.post_fetched_at = new Date().getTime();
|
||||
|
||||
//discard post body if list
|
||||
if (isList && !isComment) {
|
||||
if (isList) {
|
||||
post.body = '';
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ export const parseCommentThreads = async (commentsMap:any, author:string, permli
|
||||
|
||||
|
||||
|
||||
export const parseComments = async (comments:any[]) => {
|
||||
export const parseComments = (comments:any[]) => {
|
||||
if(!comments){
|
||||
return null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user