deeplinks for profiles and posts

This commit is contained in:
Adolfo Reyna
2023-03-10 23:08:03 -06:00
parent 7be9b89c5a
commit 424fc016d2
2 changed files with 192 additions and 196 deletions

View File

@@ -3,6 +3,7 @@ import { StyleSheet, SafeAreaView, FlatList } from 'react-native';
import API from './../API.js';
import Post from './../components/Post.js';
import GlobalState from '../contexts/GlobalState.js';
import * as Linking from 'expo-linking';
import AsyncStorage from '@react-native-async-storage/async-storage';
@@ -26,10 +27,34 @@ const getFeed = async () => {
}
}
let prevLink = '';
const handleURL = (url, navigation) => {
const { hostname, path, queryParams } = Linking.parse(url);
if(path.includes("feed/post/")){
const postid = path.substring(10);
return navigation.navigate('SinglePost', { postid });
}
if(path.includes("feed/")){
const profileid = path.substring(5);
return navigation.navigate('Profile', { profileid });
}
if (path === 'alert') {
alert(queryParams.str);
} else {
alert(path + " ::: " + queryParams);
}
}
let Feed = ({ navigation, route }) => {
let [Posts, setPosts] = useState([]);
const flatListRef = React.useRef()
console.log("Render Feed");
const url = Linking.useURL();
useEffect(() => {
if (prevLink === url || !url) return;
prevLink = url;
handleURL(url, navigation);
}, [url]);
useEffect(() => {
let subscribed = true;
const getData = async () => {
@@ -43,7 +68,7 @@ let Feed = ({ navigation, route }) => {
routes: [{ name: 'Login' }],
});
if (route.params && route.params.profileid) {
return navigation.navigate('Profile', { profileid: route.params.profileid })
return navigation.navigate('Profile', { profileid: route.params.profileid });
}
}
if(!route.params?.reRender){