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