mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-19 03:11:38 +03:00
minor fixes
This commit is contained in:
parent
25ff7c79bc
commit
bbc36ebc2c
@ -55,7 +55,7 @@ export const onLoadComplete = (filter:string) => ({
|
||||
type:CacheActions.ON_LOAD_COMPLETE
|
||||
})
|
||||
|
||||
export const calculateTimeLeftForPostCheck = (firstPost) => {
|
||||
export const calculateTimeLeftForPostCheck = (firstPost:any) => {
|
||||
const refetchTime = 600000;
|
||||
|
||||
//schedules refresh 30 minutes after last post creation time
|
||||
|
@ -7,6 +7,7 @@ import TabEmptyView from './listEmptyView';
|
||||
import { setInitPosts } from '../../../redux/actions/postsAction';
|
||||
import NewPostsPopup from './newPostsPopup';
|
||||
import { calculateTimeLeftForPostCheck } from '../services/tabbedPostsReducer';
|
||||
import { AppState } from 'react-native';
|
||||
|
||||
|
||||
const TabContent = ({
|
||||
@ -49,17 +50,23 @@ const TabContent = ({
|
||||
|
||||
//refs
|
||||
let postsListRef = useRef<PostsListRef>()
|
||||
const appState = useRef(AppState.currentState);
|
||||
const postsRef = useRef(posts);
|
||||
postsRef.current = posts;
|
||||
|
||||
|
||||
//side effects
|
||||
useEffect(() => {
|
||||
_initContent(initPosts);
|
||||
return () => {
|
||||
_isMounted = false;
|
||||
|
||||
if (isFeedScreen) {
|
||||
AppState.addEventListener('change', _handleAppStateChange);
|
||||
_initContent(true);
|
||||
}
|
||||
|
||||
return _cleanup;
|
||||
}, [])
|
||||
|
||||
|
||||
useEffect(()=>{
|
||||
if(isConnected && (username !== sessionUser || forceLoadPosts)){
|
||||
if(filterKey !== 'friends'){
|
||||
@ -68,14 +75,34 @@ const TabContent = ({
|
||||
setPosts([])
|
||||
}
|
||||
}
|
||||
},[username, forceLoadPosts])
|
||||
}, [username, forceLoadPosts])
|
||||
|
||||
|
||||
const _cleanup = () => {
|
||||
_isMounted = false;
|
||||
if(_postFetchTimer){
|
||||
clearTimeout(_postFetchTimer);
|
||||
}
|
||||
if (isFeedScreen) {
|
||||
AppState.removeEventListener('change', _handleAppStateChange);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//actions
|
||||
const _initContent = (_initPosts:any[] = []) => {
|
||||
setPosts(_initPosts);
|
||||
const _handleAppStateChange = (nextAppState) => {
|
||||
if (appState.current.match(/inactive|background/) && nextAppState === 'active') {
|
||||
const isLatestPostsCheck = true;
|
||||
_loadPosts(false, isLatestPostsCheck);
|
||||
}
|
||||
|
||||
appState.current = nextAppState;
|
||||
};
|
||||
|
||||
|
||||
const _initContent = (isFirstCall = false) => {
|
||||
setPosts(initPosts || []);
|
||||
setTabMeta({
|
||||
startAuthor:'',
|
||||
startPermlink:'',
|
||||
@ -85,7 +112,7 @@ const TabContent = ({
|
||||
setSessionUser(username);
|
||||
|
||||
if(username || (filterKey !== 'friends' && filterKey !== 'communities')){
|
||||
_loadPosts(true);
|
||||
_loadPosts(!isFirstCall);
|
||||
_getPromotedPosts();
|
||||
}
|
||||
}
|
||||
@ -133,12 +160,12 @@ const TabContent = ({
|
||||
|
||||
//schedules post fetch
|
||||
const _scheduleLatestPostsCheck = (firstPost:any) => {
|
||||
if (firstPost) {
|
||||
if (_postFetchTimer) {
|
||||
clearTimeout(_postFetchTimer);
|
||||
}
|
||||
|
||||
const timeLeft = calculateTimeLeftForPostCheck(firstPost)
|
||||
if (firstPost) {
|
||||
_postFetchTimer = setTimeout(() => {
|
||||
const isLatestPostsCheck = true;
|
||||
_loadPosts(false, isLatestPostsCheck);
|
||||
|
Loading…
Reference in New Issue
Block a user