update app version when refreshing feed
This commit is contained in:
1
App.js
1
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();
|
||||
|
||||
@@ -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,9 +88,9 @@ 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,
|
||||
{
|
||||
@@ -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,9 +122,9 @@ let Feed = ({ navigation, route }) => {
|
||||
}
|
||||
}, [route.params]);
|
||||
const renderPost = (({ item }) => {
|
||||
if (item.nonOrganicType === 'PopularUsers' || item.nonOrganicType === 'PopularGroups'){
|
||||
if(item.nonOrganicType === 'PopularUsers'){
|
||||
return (<PostPopularUsers post={item}/>)
|
||||
if (item.nonOrganicType === 'PopularUsers' || item.nonOrganicType === 'PopularGroups') {
|
||||
if (item.nonOrganicType === 'PopularUsers') {
|
||||
return (<PostPopularUsers post={item} />)
|
||||
}
|
||||
return (<></>);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user