Login and logout

This commit is contained in:
aeroreyna
2022-03-12 22:44:47 -08:00
parent 1abf26ce60
commit 082abd8fbe
7 changed files with 67 additions and 23 deletions

View File

@@ -5,12 +5,35 @@ import API from './../API.js';
import Post from './../components/Post.js';
import NewPost from "./../components/NewPost.js";
import AsyncStorage from '@react-native-async-storage/async-storage';
const storeFeed = async (value) => {
try {
const jsonValue = JSON.stringify(value)
await AsyncStorage.setItem('feed', jsonValue)
} catch (e) {
}
}
const getFeed = async () => {
try {
const value = await AsyncStorage.getItem('feed')
if (value !== null) {
return JSON.parse(value);
}
} catch (e) {
return []
}
}
let Feed = ({ navigation, route }) => {
let [Me, setMeProfile] = useState({});
let [Posts, setPosts] = useState([]);
useEffect(async () => {
let loggedIn = await API.isLoggedIn();
if(!loggedIn) return navigation.navigate('Login');
let cacheFeed = await getFeed() || [];
setPosts(cacheFeed);
let r = await API.getMe();
setMeProfile(r);
if (route.params && route.params.profileid) {
@@ -18,9 +41,8 @@ let Feed = ({ navigation, route }) => {
} else {
let posts = await API.getPosts();
setPosts(posts);
navigation.setOptions({ title: "Feed" });
storeFeed(posts);
}
//console.log(posts)
}, [route.params]);
const renderPost = (({ item }) => {
if (item.nonOrganicType === 'PopularUsers' || item.nonOrganicType === 'PopularGroups')