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')

View File

@@ -3,35 +3,26 @@ import React, { useEffect, useState } from 'react';
import { StyleSheet, Text, View, TextInput, SafeAreaView } from 'react-native';
import API from './../API.js';
import LoginForm from './../components/Login.js';
import { Provider as PaperProvider } from 'react-native-paper';
import AwesomeIcon from 'react-native-vector-icons/FontAwesome';
export default function App({navigation, route}) {
useEffect(async () => {
let r = await API.isLoggedIn();
if(r) navigation.navigate('Feed')
if(r){
await API.logout();
navigation.navigate('Login')
}
}, []);
return (
<PaperProvider settings={{
icon: props => <AwesomeIcon {...props} />,
}}>
<SafeAreaView style={styles.container}>
<Text>EMI Social LOGO</Text>
<LoginForm />
<StatusBar style="auto" />
</SafeAreaView>
</PaperProvider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
marginTop: 25,
paddingTop: 10,
backgroundColor: "#edf2f7"
},
});

View File

@@ -58,7 +58,6 @@ export default Profile;
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
backgroundColor: "#edf2f7",
},
});