Skip to content

Commit

Permalink
aws datastore clear logout
Browse files Browse the repository at this point in the history
  • Loading branch information
hrutik7 committed Jul 29, 2023
1 parent ffa3374 commit 77be5f2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
16 changes: 10 additions & 6 deletions app/Components/Tags/Tags.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TextInput, View , Text ,StyleSheet, Touchable, TouchableOpacity} from '
import CustomTouchableOpacity from '../Button/Button';
import ResponsiveFontSize from 'react-native-responsive-fontsize';
// import { mutations } from '../../../src/graphql/mutations';
import mutations from '../../../src/graphql/mutations'
import * as mutations from '../../../src/graphql/mutations';
import { API } from "aws-amplify";
import { UserInfo } from '../../../src/models';
import { DataStore } from 'aws-amplify';
Expand All @@ -20,19 +20,22 @@ const Tags = ({navigation}) => {
const postUserData = async () => {
try {
const posts = await DataStore.query(UserInfo);
setUsername(posts[0].name)
console.log('Posts retrieved successfully!', JSON.stringify(posts, null, 2));
setUsername(posts[0].username)
console.log('Posts retrieved successfully!', posts);
} catch (error) {
console.log('Error retrieving posts', error);
}
try {
// console.log(inputarray,username,"====================")

const inputstring = JSON.stringify(inputarray)
console.log(inputstring,"string==============================")
const userData = await API.graphql({
query: mutations.createUsersData,
variables: {
input: {
id: "1",
name: username,
tags: inputarray
username: username,
tags: inputstring
}
}
});
Expand All @@ -41,6 +44,7 @@ const Tags = ({navigation}) => {
} catch (err) {
console.log("error creating user", err);
}
changeScreen('WaitingScreen');
};


Expand Down
14 changes: 14 additions & 0 deletions app/Screens/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ const Login = ({navigation}) => {
console.log(username,password)
try {
console.log('first');
// {"cause": {"locations": null,
// "message": "Cannot return null for non-nullable type:
// 'AWSTimestamp' within parent 'Restaurant' (/syncRestaurants/items[2]/_lastChangedAt)",
// "path": ["syncRestaurants", "items", 2, "_lastChangedAt"]}, "errorType": "BadRecord", "localModel": null,
// "message": "Cannot return null for non-nullable
// type: 'AWSTimestamp' within parent
// 'Restaurant' (/syncRestaurants/items[2]/_lastChangedAt)",
// "model": "Restaurant", "oper
// ation": "syncRest
// aurants", "process": "sync", "recoverySu
// ggestion": "Ensure app code is up to date, auth directiv
// es exist and are correct on each model, and that server-side data has not been invalidated by a schema change.
// If the problem persists
// , search for or create an issue: https://github.com/aws-amplify/amplify-js/issues", "remoteModel": null}
const post = await DataStore.save(
new UserInfo({
username: username
Expand Down
29 changes: 23 additions & 6 deletions app/Screens/WaitingMatch/WaitingMatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {View, StyleSheet, Image,Text, TouchableOpacity} from 'react-native';
import { SvgUri } from 'react-native-svg';
import CustomTouchableOpacity from '../../Components/Button/Button';
import * as queries from '../../../src/graphql/queries'
import { API } from 'aws-amplify';
import { API, DataStore } from 'aws-amplify';
const WaitingScreen = ({navigation}) => {
useEffect(()=>{
fetchApi()
Expand All @@ -14,6 +14,11 @@ const WaitingScreen = ({navigation}) => {
const allTodos = await API.graphql({ query: queries.listUsersData });
console.log(allTodos.data,"con")
}

const signOut = async () =>{
await DataStore.clear()
navigation.navigate("SignUp")
}
return (
<View style={styles.container}>
<View style={styles.header}>
Expand All @@ -33,15 +38,25 @@ const WaitingScreen = ({navigation}) => {
<CustomTouchableOpacity
style={{
backgroundColor: '#6528F7',
width: '80%',
width: '40%',
alignSelf: 'center',
// marginTop: 20,
}}
title="change preferences"
onPress={() => console.log('Login')}
title="update tags"
onPress={() => navigation.navigate("TagsScreen")}
/>


<CustomTouchableOpacity
style={{
backgroundColor: '#8d7d37',
width: '40%',
alignSelf: 'center',
// marginTop: 20,
color:"black"
}}
title="Logout"
onPress={() => signOut()}
/>
</View>
</View>
);
Expand All @@ -63,8 +78,10 @@ const styles = StyleSheet.create({
flex:1
},
btnContainer:{
flex:2,
flex:1,
flexDirection:"row",
width:"100%",
justifyContent:"space-around"
},
ImageContainer:{
flex:3
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint": "eslint .",
"start": "react-native start",
"test": "jest",
"format": "prettier --write 'src/*.js'",
"format": "prettier --write ''",
"gradclean": "cd android && gradlew clean && cd ..",
"amplify-modelgen": "node amplify\\scripts\\amplify-modelgen.js",
"amplify-push": "node amplify\\scripts\\amplify-push.js"
Expand Down

0 comments on commit 77be5f2

Please sign in to comment.