소스 검색

fixed pincode to be dinamic

Ricardo-gonzalez32 2 년 전
부모
커밋
d50248836b
3개의 변경된 파일16개의 추가작업 그리고 48개의 파일을 삭제
  1. 1
    24
      MocionesIUPI/screens/HomeScreen.js
  2. 2
    2
      MocionesIUPI/screens/MocionScreen.js
  3. 13
    22
      MocionesIUPI/screens/PincodeScreen.js

+ 1
- 24
MocionesIUPI/screens/HomeScreen.js 파일 보기

@@ -4,34 +4,11 @@ import { StyleSheet, View, Text, Button } from 'react-native';
4 4
 import { globalStyles } from "../styles/global";
5 5
 
6 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 8
     const pressHandler = () => {
27 9
         navigation.navigate('Pinpage');
28 10
     }
29
-    
30
-    {/*
31
-    useEffect(() => {
32
-        getMociones();
33
-      }, []);
34
-    */}
11
+
35 12
 
36 13
     return (
37 14
         <View style = {globalStyles.container}>

+ 2
- 2
MocionesIUPI/screens/MocionScreen.js 파일 보기

@@ -1,7 +1,7 @@
1 1
 import React, { useEffect, useState } from 'react';
2 2
 import { ActivityIndicator, Button, FlatList, Text, View } from 'react-native';
3 3
 
4
-export default App = () => {
4
+export default App = ({ navigation }) => {
5 5
   const [mocion, setMocion] = useState(null);
6 6
   const [description, setDescription] = useState(null);
7 7
   const [pin, setPIN] = useState(null);
@@ -10,7 +10,7 @@ export default App = () => {
10 10
   // this connects us to the API and fetches the json file with the mociones
11 11
   const getMociones = async () => {
12 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 14
       const json = await response.json();
15 15
       setMocion(json.Mocion);
16 16
       setDescription(json.Description);

+ 13
- 22
MocionesIUPI/screens/PincodeScreen.js 파일 보기

@@ -9,16 +9,19 @@ import { useEffect, useState } from "react";
9 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 14
        try {
15 15
         const response = await fetch(`http://10.0.0.65:5000/send?PIN=${code}`); // connection to the website 
16 16
         const json = await response.json();
17 17
         console.log(json);
18 18
 
19 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 21
           alert("Error: No hay mocion con ese PIN.")
22
+          this.pinInput.current.shake()
23
+          .then(() => this.setState({ code: '' }));
24
+
22 25
         } else {
23 26
           this.setState({ pincode: true});
24 27
         }
@@ -30,32 +33,20 @@ export default class App extends React.Component {
30 33
       
31 34
     }
32 35
     
33
-
34 36
     
35
-    pressHandler = () => {
37
+    pressHandler = (code) => {
36 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 44
     state = {
41 45
       code: '',
42 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 51
     render() {
61 52
       const { code } = this.state;
@@ -70,13 +61,13 @@ export default class App extends React.Component {
70 61
               value={code}
71 62
               codeLength={6}
72 63
               onTextChange={code => this.setState({ code })}
73
-              onFulfill={this.getMociones}
64
+              onFulfill={this.getPin}
74 65
               onBackspace={() => console.log('No more back.')}
75 66
               />
76 67
           </View>
77 68
           
78 69
           <View style={globalStyles.container}>
79
-            { pincode && <Button title='Ir a mocion' color = {'#e81b39'} onPress={this.pressHandler} />}
70
+            { pincode && this.pressHandler(code)} 
80 71
           </View>
81 72
 
82 73
         </View>