Browse Source

fixed pincode to be dinamic

Ricardo-gonzalez32 2 years ago
parent
commit
d50248836b

+ 1
- 24
MocionesIUPI/screens/HomeScreen.js View File

4
 import { globalStyles } from "../styles/global";
4
 import { globalStyles } from "../styles/global";
5
 
5
 
6
 export default App = ({ navigation }) => {
6
 export default App = ({ navigation }) => {
7
-  {/*
8
-  const [PIN, setPIN] = useState([]); // this is looking for 'PIN' and it's content
9
   
7
   
10
-    // this connects us to the API and fetches the json file with the mociones
11
-    const getMociones = async () => {
12
-       try {
13
-        const response = await fetch('http://10.0.0.65:5000/send?PIN=894761'); // connection to the website 
14
-        const json = await response.json();
15
-  
16
-        // setting the content of each category 
17
-        setPIN(json.PIN);
18
-  
19
-      } catch (error) {
20
-        console.error(error);
21
-      } 
22
-      
23
-    }
24
-    */}
25
-
26
     const pressHandler = () => {
8
     const pressHandler = () => {
27
         navigation.navigate('Pinpage');
9
         navigation.navigate('Pinpage');
28
     }
10
     }
29
-    
30
-    {/*
31
-    useEffect(() => {
32
-        getMociones();
33
-      }, []);
34
-    */}
11
+
35
 
12
 
36
     return (
13
     return (
37
         <View style = {globalStyles.container}>
14
         <View style = {globalStyles.container}>

+ 2
- 2
MocionesIUPI/screens/MocionScreen.js View File

1
 import React, { useEffect, useState } from 'react';
1
 import React, { useEffect, useState } from 'react';
2
 import { ActivityIndicator, Button, FlatList, Text, View } from 'react-native';
2
 import { ActivityIndicator, Button, FlatList, Text, View } from 'react-native';
3
 
3
 
4
-export default App = () => {
4
+export default App = ({ navigation }) => {
5
   const [mocion, setMocion] = useState(null);
5
   const [mocion, setMocion] = useState(null);
6
   const [description, setDescription] = useState(null);
6
   const [description, setDescription] = useState(null);
7
   const [pin, setPIN] = useState(null);
7
   const [pin, setPIN] = useState(null);
10
   // this connects us to the API and fetches the json file with the mociones
10
   // this connects us to the API and fetches the json file with the mociones
11
   const getMociones = async () => {
11
   const getMociones = async () => {
12
      try {
12
      try {
13
-      const response = await fetch('http://10.0.0.65:5000/send?PIN=894761');
13
+      const response = await fetch(`http://10.0.0.65:5000/send?PIN=${navigation.state.params.Pin}`); // connection to the website 
14
       const json = await response.json();
14
       const json = await response.json();
15
       setMocion(json.Mocion);
15
       setMocion(json.Mocion);
16
       setDescription(json.Description);
16
       setDescription(json.Description);

+ 13
- 22
MocionesIUPI/screens/PincodeScreen.js View File

9
 export default class App extends React.Component {
9
 export default class App extends React.Component {
10
 
10
 
11
   
11
   
12
-    // this connects us to the API and fetches the json file with the mociones
13
-    getMociones = async (code) => {
12
+    // this checks the pin the user inputs to see if there is a mocion with that pin
13
+    getPin = async (code) => {
14
        try {
14
        try {
15
         const response = await fetch(`http://10.0.0.65:5000/send?PIN=${code}`); // connection to the website 
15
         const response = await fetch(`http://10.0.0.65:5000/send?PIN=${code}`); // connection to the website 
16
         const json = await response.json();
16
         const json = await response.json();
17
         console.log(json);
17
         console.log(json);
18
 
18
 
19
         // checks if the mocion exists
19
         // checks if the mocion exists
20
-        if (json == "Error: No hay mocion con ese PIN."){
20
+        if (JSON.stringify(json) == '{"Error":"No hay mocion con ese PIN."}' ){
21
           alert("Error: No hay mocion con ese PIN.")
21
           alert("Error: No hay mocion con ese PIN.")
22
+          this.pinInput.current.shake()
23
+          .then(() => this.setState({ code: '' }));
24
+
22
         } else {
25
         } else {
23
           this.setState({ pincode: true});
26
           this.setState({ pincode: true});
24
         }
27
         }
30
       
33
       
31
     }
34
     }
32
     
35
     
33
-
34
     
36
     
35
-    pressHandler = () => {
37
+    pressHandler = (code) => {
36
     {/*Dentro del parentesis va el path al screen para redirigir*/}
38
     {/*Dentro del parentesis va el path al screen para redirigir*/}
37
-      this.props.navigation.navigate('Mocion')
39
+      this.props.navigation.navigate('Mocion', {Pin:code})
40
+      this.setState({ pincode: false});
41
+      this.setState({ code: '' })
38
     }
42
     }
39
 
43
 
40
     state = {
44
     state = {
41
       code: '',
45
       code: '',
42
       pincode: false,
46
       pincode: false,
43
     };
47
     };
44
-    pinInput = React.createRef();
45
-  
46
-    _checkCode = (code) => {
47
 
48
 
48
-      this.getMociones(code);
49
-
50
-    {/*
51
-      if (code != 894761) { //this is for recieving the parameters from another screen
52
-        this.pinInput.current.shake()
53
-          .then(() => this.setState({ code: '' }));
54
-      } else {
55
-        this.setState({ pincode: true});
56
-      }
57
-    */} 
58
-    }
49
+    pinInput = React.createRef();
59
   
50
   
60
     render() {
51
     render() {
61
       const { code } = this.state;
52
       const { code } = this.state;
70
               value={code}
61
               value={code}
71
               codeLength={6}
62
               codeLength={6}
72
               onTextChange={code => this.setState({ code })}
63
               onTextChange={code => this.setState({ code })}
73
-              onFulfill={this.getMociones}
64
+              onFulfill={this.getPin}
74
               onBackspace={() => console.log('No more back.')}
65
               onBackspace={() => console.log('No more back.')}
75
               />
66
               />
76
           </View>
67
           </View>
77
           
68
           
78
           <View style={globalStyles.container}>
69
           <View style={globalStyles.container}>
79
-            { pincode && <Button title='Ir a mocion' color = {'#e81b39'} onPress={this.pressHandler} />}
70
+            { pincode && this.pressHandler(code)} 
80
           </View>
71
           </View>
81
 
72
 
82
         </View>
73
         </View>