mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-20 03:42:10 +03:00
removed and tested possible breaches for latest post check
This commit is contained in:
parent
7eb95e74c2
commit
f8e1829e97
@ -153,7 +153,7 @@ const postsListContainer = ({
|
|||||||
data={posts}
|
data={posts}
|
||||||
showsVerticalScrollIndicator={false}
|
showsVerticalScrollIndicator={false}
|
||||||
renderItem={_renderItem}
|
renderItem={_renderItem}
|
||||||
keyExtractor={(content) => `${content.author}/${content.permlink}`}
|
keyExtractor={(content, index) => `${content.author}/${content.permlink}-${index}`}
|
||||||
removeClippedSubviews
|
removeClippedSubviews
|
||||||
onEndReachedThreshold={1}
|
onEndReachedThreshold={1}
|
||||||
maxToRenderPerBatch={3}
|
maxToRenderPerBatch={3}
|
||||||
|
@ -75,6 +75,7 @@ export const loadPosts = async ({
|
|||||||
observer: feedUsername,
|
observer: feedUsername,
|
||||||
sort: 'created',
|
sort: 'created',
|
||||||
tag: 'my',
|
tag: 'my',
|
||||||
|
limit,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
func = getAccountPosts;
|
func = getAccountPosts;
|
||||||
|
@ -39,7 +39,7 @@ const NewPostsPopup = ({
|
|||||||
|
|
||||||
{popupAvatars.map((url, index) => (
|
{popupAvatars.map((url, index) => (
|
||||||
<FastImage
|
<FastImage
|
||||||
key={`image_bubble_${url}`}
|
key={`image_bubble_${url}-${index}`}
|
||||||
source={{ uri: url }}
|
source={{ uri: url }}
|
||||||
style={[styles.popupImage, { zIndex: 10 - index }]}
|
style={[styles.popupImage, { zIndex: 10 - index }]}
|
||||||
/>
|
/>
|
||||||
|
@ -30,7 +30,6 @@ const TabContent = ({
|
|||||||
handleOnScroll,
|
handleOnScroll,
|
||||||
...props
|
...props
|
||||||
}: TabContentProps) => {
|
}: TabContentProps) => {
|
||||||
let _postFetchTimer = null;
|
|
||||||
let _isMounted = true;
|
let _isMounted = true;
|
||||||
|
|
||||||
|
|
||||||
@ -50,13 +49,18 @@ const TabContent = ({
|
|||||||
const [sessionUser, setSessionUser] = useState(username);
|
const [sessionUser, setSessionUser] = useState(username);
|
||||||
const [tabMeta, setTabMeta] = useState(DEFAULT_TAB_META);
|
const [tabMeta, setTabMeta] = useState(DEFAULT_TAB_META);
|
||||||
const [latestPosts, setLatestPosts] = useState<any[]>([]);
|
const [latestPosts, setLatestPosts] = useState<any[]>([]);
|
||||||
|
const [postFetchTimer, setPostFetchTimer] = useState(0)
|
||||||
|
|
||||||
//refs
|
//refs
|
||||||
let postsListRef = useRef<PostsListRef>()
|
let postsListRef = useRef<PostsListRef>()
|
||||||
const appState = useRef(AppState.currentState);
|
const appState = useRef(AppState.currentState);
|
||||||
const postsRef = useRef(posts);
|
const postsRef = useRef(posts);
|
||||||
|
const sessionUserRef = useRef(sessionUser);
|
||||||
|
|
||||||
|
//init state refs;
|
||||||
postsRef.current = posts;
|
postsRef.current = posts;
|
||||||
|
sessionUserRef.current = sessionUser;
|
||||||
|
|
||||||
|
|
||||||
//side effects
|
//side effects
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -89,8 +93,8 @@ const TabContent = ({
|
|||||||
|
|
||||||
const _cleanup = () => {
|
const _cleanup = () => {
|
||||||
_isMounted = false;
|
_isMounted = false;
|
||||||
if(_postFetchTimer){
|
if(postFetchTimer){
|
||||||
clearTimeout(_postFetchTimer);
|
clearTimeout(postFetchTimer);
|
||||||
}
|
}
|
||||||
if (isFeedScreen) {
|
if (isFeedScreen) {
|
||||||
AppState.removeEventListener('change', _handleAppStateChange);
|
AppState.removeEventListener('change', _handleAppStateChange);
|
||||||
@ -110,17 +114,22 @@ const TabContent = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const _initContent = (isFirstCall = false, feedUsername:string) => {
|
const _initContent = (isFirstCall = false, _feedUsername:string) => {
|
||||||
_scrollToTop();
|
_scrollToTop();
|
||||||
|
|
||||||
const initialPosts = isFirstCall && isFeedScreen && isInitialTab ? initPosts : [];
|
const initialPosts = isFirstCall && isFeedScreen && isInitialTab ? initPosts : [];
|
||||||
|
|
||||||
setPosts(initialPosts);
|
setPosts(initialPosts);
|
||||||
setTabMeta(DEFAULT_TAB_META)
|
setTabMeta(DEFAULT_TAB_META)
|
||||||
setSessionUser(username);
|
setSessionUser(_feedUsername);
|
||||||
|
setLatestPosts([]);
|
||||||
|
|
||||||
|
if(postFetchTimer){
|
||||||
|
clearTimeout(postFetchTimer);
|
||||||
|
}
|
||||||
|
|
||||||
if(username || (filterKey !== 'friends' && filterKey !== 'communities')){
|
if(username || (filterKey !== 'friends' && filterKey !== 'communities')){
|
||||||
_loadPosts(!isFirstCall, false, feedUsername, initialPosts, DEFAULT_TAB_META );
|
_loadPosts(!isFirstCall, false, _feedUsername, initialPosts, DEFAULT_TAB_META );
|
||||||
_getPromotedPosts();
|
_getPromotedPosts();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,7 +138,7 @@ const TabContent = ({
|
|||||||
const _loadPosts = async (
|
const _loadPosts = async (
|
||||||
shouldReset:boolean = false,
|
shouldReset:boolean = false,
|
||||||
isLatestPostsCheck:boolean = false,
|
isLatestPostsCheck:boolean = false,
|
||||||
_feedUsername:string = feedUsername,
|
_feedUsername:string = isFeedScreen? sessionUserRef.current:feedUsername,
|
||||||
_posts:any[] = postsRef.current,
|
_posts:any[] = postsRef.current,
|
||||||
_tabMeta:TabMeta = tabMeta
|
_tabMeta:TabMeta = tabMeta
|
||||||
) => {
|
) => {
|
||||||
@ -177,17 +186,18 @@ const TabContent = ({
|
|||||||
//schedules post fetch
|
//schedules post fetch
|
||||||
const _scheduleLatestPostsCheck = (firstPost:any) => {
|
const _scheduleLatestPostsCheck = (firstPost:any) => {
|
||||||
if (firstPost) {
|
if (firstPost) {
|
||||||
if (_postFetchTimer) {
|
if (postFetchTimer) {
|
||||||
clearTimeout(_postFetchTimer);
|
clearTimeout(postFetchTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
const timeLeft = calculateTimeLeftForPostCheck(firstPost)
|
const timeLeft = calculateTimeLeftForPostCheck(firstPost)
|
||||||
_postFetchTimer = setTimeout(() => {
|
const _postFetchTimer = setTimeout(() => {
|
||||||
const isLatestPostsCheck = true;
|
const isLatestPostsCheck = true;
|
||||||
_loadPosts(false, isLatestPostsCheck);
|
_loadPosts(false, isLatestPostsCheck);
|
||||||
},
|
},
|
||||||
timeLeft
|
timeLeft
|
||||||
);
|
);
|
||||||
|
setPostFetchTimer(_postFetchTimer)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -210,8 +220,10 @@ const TabContent = ({
|
|||||||
const firstPostChanged = posts.length == 0 || (posts[0].permlink !== updatedPosts[0].permlink);
|
const firstPostChanged = posts.length == 0 || (posts[0].permlink !== updatedPosts[0].permlink);
|
||||||
if (isFeedScreen && firstPostChanged) {
|
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 (isInitialTab) {
|
if (isInitialTab) {
|
||||||
dispatch(setInitPosts(updatedPosts));
|
dispatch(setInitPosts(updatedPosts));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user