update app version when refreshing feed

This commit is contained in:
Adolfo Reyna
2025-02-06 23:28:31 -05:00
parent 7cf6f99503
commit a85d9779b8
2 changed files with 29 additions and 13 deletions

1
App.js
View File

@@ -30,6 +30,7 @@ import Slideshow from './Views/Slideshow.js';
import SongPlayer from './Views/SongPlayer.js'; import SongPlayer from './Views/SongPlayer.js';
import { Platform } from 'react-native'; import { Platform } from 'react-native';
import { PostHogProvider } from 'posthog-react-native' import { PostHogProvider } from 'posthog-react-native'
import * as Updates from 'expo-updates';
const Tab = createBottomTabNavigator(); const Tab = createBottomTabNavigator();

View File

@@ -6,7 +6,7 @@ import PostPopularUsers from '../components/PostPopularUsers.js';
import GlobalState from '../contexts/GlobalState.js'; import GlobalState from '../contexts/GlobalState.js';
import * as Linking from 'expo-linking'; import * as Linking from 'expo-linking';
import { posthog } from './../PostHog.js'; import { posthog } from './../PostHog.js';
import * as Updates from 'expo-updates';
import AsyncStorage from '@react-native-async-storage/async-storage'; import AsyncStorage from '@react-native-async-storage/async-storage';
@@ -32,12 +32,12 @@ const getFeed = async () => {
let prevLink = ''; let prevLink = '';
const handleURL = (url, navigation) => { const handleURL = (url, navigation) => {
const { hostname, path, queryParams } = Linking.parse(url); const { hostname, path, queryParams } = Linking.parse(url);
if(!path) return; if (!path) return;
if(path.includes("feed/post/")){ if (path.includes("feed/post/")) {
const postid = path.substring(10); const postid = path.substring(10);
return navigation.navigate('SinglePost', { postid }); return navigation.navigate('SinglePost', { postid });
} }
if(path.includes("feed/")){ if (path.includes("feed/")) {
const profileid = path.substring(5); const profileid = path.substring(5);
return navigation.navigate('Profile', { profileid }); return navigation.navigate('Profile', { profileid });
} }
@@ -48,6 +48,20 @@ const handleURL = (url, navigation) => {
} }
} }
async function onFetchUpdateAsync() {
try {
const update = await Updates.checkForUpdateAsync();
if (update.isAvailable) {
await Updates.fetchUpdateAsync();
await Updates.reloadAsync();
}
} catch (error) {
// You can also add an alert() to see the error message in case of an error when fetching updates.
console.log(`Error fetching latest Expo update: ${error}`);
}
}
let Feed = ({ navigation, route }) => { let Feed = ({ navigation, route }) => {
let [Posts, setPosts] = useState([]); let [Posts, setPosts] = useState([]);
const flatListRef = React.useRef() const flatListRef = React.useRef()
@@ -63,7 +77,7 @@ let Feed = ({ navigation, route }) => {
const getData = async () => { const getData = async () => {
// TODO: Check for internet connection // TODO: Check for internet connection
const internet = true; const internet = true;
if(internet){ if (internet) {
//byPass and load //byPass and load
let loggedIn = await API.isLoggedIn(); let loggedIn = await API.isLoggedIn();
if (!loggedIn) return navigation.reset({ if (!loggedIn) return navigation.reset({
@@ -74,11 +88,11 @@ let Feed = ({ navigation, route }) => {
return navigation.navigate('Profile', { profileid: route.params.profileid }); return navigation.navigate('Profile', { profileid: route.params.profileid });
} }
} }
if(!route.params?.reRender){ if (!route.params?.reRender) {
API.getMe().then((me) => { API.getMe().then((me) => {
if (subscribed){ if (subscribed) {
GlobalState.me = me; GlobalState.me = me;
posthog.identify(me.userid, posthog.identify(me.userid,
{ {
name: me.profile.firstName, name: me.profile.firstName,
profileid: me._id, profileid: me._id,
@@ -93,6 +107,7 @@ let Feed = ({ navigation, route }) => {
if (cacheFeed.length && subscribed) setPosts(cacheFeed); if (cacheFeed.length && subscribed) setPosts(cacheFeed);
console.log("Feed from server") console.log("Feed from server")
} }
await onFetchUpdateAsync();
flatListRef.current.scrollToOffset({ animated: true, offset: 0 }) flatListRef.current.scrollToOffset({ animated: true, offset: 0 })
let posts = await API.getPosts(); let posts = await API.getPosts();
if (subscribed) { if (subscribed) {
@@ -107,13 +122,13 @@ let Feed = ({ navigation, route }) => {
} }
}, [route.params]); }, [route.params]);
const renderPost = (({ item }) => { const renderPost = (({ item }) => {
if (item.nonOrganicType === 'PopularUsers' || item.nonOrganicType === 'PopularGroups'){ if (item.nonOrganicType === 'PopularUsers' || item.nonOrganicType === 'PopularGroups') {
if(item.nonOrganicType === 'PopularUsers'){ if (item.nonOrganicType === 'PopularUsers') {
return (<PostPopularUsers post={item}/>) return (<PostPopularUsers post={item} />)
} }
return (<></>); return (<></>);
} }
return (<Post post={item} />); return (<Post post={item} />);
}); });
@@ -122,7 +137,7 @@ let Feed = ({ navigation, route }) => {
<FlatList <FlatList
data={Posts} data={Posts}
renderItem={renderPost} renderItem={renderPost}
keyExtractor={item => item.lastUpdated || item._id || item.ceatedAt} //This may refresh the component keyExtractor={item => item.lastUpdated || item._id || item.ceatedAt} //This may refresh the component
//ListHeaderComponent={<NewPost newPostCB={(newPost) => setPosts([newPost, ...Posts])} />} //ListHeaderComponent={<NewPost newPostCB={(newPost) => setPosts([newPost, ...Posts])} />}
refreshing={Posts.length === 0} refreshing={Posts.length === 0}
onRefresh={() => { onRefresh={() => {