From 77be5f2e562683cf7ee6168caf36f06c829c04b8 Mon Sep 17 00:00:00 2001 From: hrutik7 <62372737+hrutik7@users.noreply.github.com> Date: Sat, 29 Jul 2023 16:22:06 +0530 Subject: [PATCH] aws datastore clear logout --- app/Components/Tags/Tags.jsx | 16 ++++++++----- app/Screens/Login/Login.js | 14 ++++++++++++ app/Screens/WaitingMatch/WaitingMatch.js | 29 +++++++++++++++++++----- package.json | 2 +- 4 files changed, 48 insertions(+), 13 deletions(-) diff --git a/app/Components/Tags/Tags.jsx b/app/Components/Tags/Tags.jsx index 722311d..cbe5af3 100644 --- a/app/Components/Tags/Tags.jsx +++ b/app/Components/Tags/Tags.jsx @@ -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'; @@ -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 } } }); @@ -41,6 +44,7 @@ const Tags = ({navigation}) => { } catch (err) { console.log("error creating user", err); } + changeScreen('WaitingScreen'); }; diff --git a/app/Screens/Login/Login.js b/app/Screens/Login/Login.js index 4df18bc..2fe83e0 100644 --- a/app/Screens/Login/Login.js +++ b/app/Screens/Login/Login.js @@ -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 diff --git a/app/Screens/WaitingMatch/WaitingMatch.js b/app/Screens/WaitingMatch/WaitingMatch.js index f3c514f..b2e0bb8 100644 --- a/app/Screens/WaitingMatch/WaitingMatch.js +++ b/app/Screens/WaitingMatch/WaitingMatch.js @@ -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() @@ -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 ( @@ -33,15 +38,25 @@ const WaitingScreen = ({navigation}) => { console.log('Login')} + title="update tags" + onPress={() => navigation.navigate("TagsScreen")} /> - + signOut()} + /> ); @@ -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 diff --git a/package.json b/package.json index 42e8a1d..0812e48 100644 --- a/package.json +++ b/package.json @@ -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"