diff --git a/App.js b/App.js index dd93a93..d9f8827 100644 --- a/App.js +++ b/App.js @@ -30,6 +30,7 @@ import Slideshow from './Views/Slideshow.js'; import SongPlayer from './Views/SongPlayer.js'; import { Platform } from 'react-native'; import { PostHogProvider } from 'posthog-react-native' +import * as Updates from 'expo-updates'; const Tab = createBottomTabNavigator(); diff --git a/Views/Feed.js b/Views/Feed.js index f050cf5..0a85ae2 100644 --- a/Views/Feed.js +++ b/Views/Feed.js @@ -6,7 +6,7 @@ import PostPopularUsers from '../components/PostPopularUsers.js'; import GlobalState from '../contexts/GlobalState.js'; import * as Linking from 'expo-linking'; import { posthog } from './../PostHog.js'; - +import * as Updates from 'expo-updates'; import AsyncStorage from '@react-native-async-storage/async-storage'; @@ -32,12 +32,12 @@ const getFeed = async () => { let prevLink = ''; const handleURL = (url, navigation) => { const { hostname, path, queryParams } = Linking.parse(url); - if(!path) return; - if(path.includes("feed/post/")){ + if (!path) return; + if (path.includes("feed/post/")) { const postid = path.substring(10); return navigation.navigate('SinglePost', { postid }); } - if(path.includes("feed/")){ + if (path.includes("feed/")) { const profileid = path.substring(5); 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 [Posts, setPosts] = useState([]); const flatListRef = React.useRef() @@ -63,7 +77,7 @@ let Feed = ({ navigation, route }) => { const getData = async () => { // TODO: Check for internet connection const internet = true; - if(internet){ + if (internet) { //byPass and load let loggedIn = await API.isLoggedIn(); if (!loggedIn) return navigation.reset({ @@ -74,11 +88,11 @@ let Feed = ({ navigation, route }) => { return navigation.navigate('Profile', { profileid: route.params.profileid }); } } - if(!route.params?.reRender){ + if (!route.params?.reRender) { API.getMe().then((me) => { - if (subscribed){ + if (subscribed) { GlobalState.me = me; - posthog.identify(me.userid, + posthog.identify(me.userid, { name: me.profile.firstName, profileid: me._id, @@ -93,6 +107,7 @@ let Feed = ({ navigation, route }) => { if (cacheFeed.length && subscribed) setPosts(cacheFeed); console.log("Feed from server") } + await onFetchUpdateAsync(); flatListRef.current.scrollToOffset({ animated: true, offset: 0 }) let posts = await API.getPosts(); if (subscribed) { @@ -107,13 +122,13 @@ let Feed = ({ navigation, route }) => { } }, [route.params]); const renderPost = (({ item }) => { - if (item.nonOrganicType === 'PopularUsers' || item.nonOrganicType === 'PopularGroups'){ - if(item.nonOrganicType === 'PopularUsers'){ - return () + if (item.nonOrganicType === 'PopularUsers' || item.nonOrganicType === 'PopularGroups') { + if (item.nonOrganicType === 'PopularUsers') { + return () } return (<>); } - return (); + return (); }); @@ -122,7 +137,7 @@ let Feed = ({ navigation, route }) => { 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={ setPosts([newPost, ...Posts])} />} refreshing={Posts.length === 0} onRefresh={() => {