Revert "executed latest waves check on app resume"

This reverts commit 06c029141a.
This commit is contained in:
Nouman Tahir 2023-09-28 00:28:06 +05:00
parent 27c02e8e23
commit cb8fa4c1fb

View File

@ -1,5 +1,5 @@
import React, { useEffect, useRef, useState } from 'react'; import React, { useRef, useState } from 'react';
import { ActivityIndicator, NativeScrollEvent, NativeSyntheticEvent, RefreshControl, View, FlatList, AppState, Alert } from 'react-native'; import { ActivityIndicator, NativeScrollEvent, NativeSyntheticEvent, RefreshControl, View, FlatList } from 'react-native';
import { Comments, EmptyScreen, Header, PostOptionsModal } from '../../../components'; import { Comments, EmptyScreen, Header, PostOptionsModal } from '../../../components';
import styles from '../styles/wavesScreen.styles'; import styles from '../styles/wavesScreen.styles';
import { wavesQueries } from '../../../providers/queries'; import { wavesQueries } from '../../../providers/queries';
@ -19,42 +19,14 @@ const WavesScreen = () => {
const postsListRef = useRef<FlatList>(); const postsListRef = useRef<FlatList>();
const blockPopupRef = useRef(false); const blockPopupRef = useRef(false);
const scrollOffsetRef = useRef(0); const scrollOffsetRef = useRef(0);
const appState = useRef(AppState.currentState);
const wavesQuery = wavesQueries.useWavesQuery('ecency.waves'); const wavesQuery = wavesQueries.useWavesQuery('ecency.waves');
const isDarkTheme = useAppSelector(state => state.application.isDarkTheme) const isDarkTheme = useAppSelector(state => state.application.isDarkTheme)
const [enableScrollTop, setEnableScrollTop] = useState(false); const [enableScrollTop, setEnableScrollTop] = useState(false);
const [popupAvatars, setPopupAvatars] = useState<any[]>([])
useEffect(() => {
const _stateSub = AppState.addEventListener('change', _handleAppStateChange);
return () => {
_stateSub.remove();
}
}, [])
//actions
const _handleAppStateChange = async (nextAppState) => {
if (
appState.current.match(/inactive|background/) &&
nextAppState === 'active' &&
wavesQuery.data.length > 0
) {
const latestWaves = await wavesQuery.latestWavesFetch()
if (latestWaves.length > 0) {
Alert.alert("latest waves: " + latestWaves.length);
setPopupAvatars(latestWaves.map((item) => item.avatar))
setEnableScrollTop(true)
}
}
appState.current = nextAppState;
};
const _fetchData = ({ refresh }: { refresh?: boolean }) => { const _fetchData = ({ refresh }: { refresh?: boolean }) => {
if (refresh) { if (refresh) {
wavesQuery.refresh(); wavesQuery.refresh();
@ -66,7 +38,7 @@ const WavesScreen = () => {
//scrolls to top, blocks scroll popup for 2 seconds to reappear after scroll //scrolls to top, blocks scroll popup for 2 seconds to reappear after scroll
const _scrollTop = () => { const _scrollTop = () => {
if (postsListRef.current) { if (postsListRef.current) {
postsListRef.current.scrollToOffset({ offset: 0 }); postsListRef.current.scrollToOffset({offset:0});
setEnableScrollTop(false); setEnableScrollTop(false);
scrollPopupDebouce.cancel(); scrollPopupDebouce.cancel();
blockPopupRef.current = true; blockPopupRef.current = true;
@ -143,12 +115,11 @@ const WavesScreen = () => {
}} }}
/> />
<ScrollTopPopup <ScrollTopPopup
popupAvatars={popupAvatars} popupAvatars={[]}
enableScrollTop={enableScrollTop} enableScrollTop={enableScrollTop}
onPress={_scrollTop} onPress={_scrollTop}
onClose={() => { onClose={() => {
setEnableScrollTop(false); setEnableScrollTop(false);
setPopupAvatars([])
}} }}
/> />
</View> </View>