File size: 2,543 Bytes
96e5fd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import * as AppleAuthentication from "expo-apple-authentication";
import { StyleSheet, View, Text } from "react-native";
import { useState, useEffect } from "react";
import * as Network from "expo-network";

import Vision from "./Vision";

export default function App() {
  const [credentials, setCredentials] = useState(null);
  const [connected, setConnected] = useState(true);
  const checkConnection = async () => {
    const { isConnected } = await Network.getNetworkStateAsync();
    if (!isConnected) {
      console.log("not connected");
    }
    setConnected(isConnected);
  };

  setInterval(checkConnection, 1000);

  return (
    <View style={{ flex: 1 }}>
      {credentials && connected ? (
        <Vision
          user={credentials.user || true}
          setCredentials={setCredentials}
        />
      ) : (
        <View style={styles.buttonContainer}>
          <Text
            style={{
              fontSize: 40,
              marginBottom: 20,
            }}
          >
            Pinecone Vision
          </Text>
          <AppleAuthentication.AppleAuthenticationButton
            buttonType={
              AppleAuthentication.AppleAuthenticationButtonType.SIGN_IN
            }
            buttonStyle={
              AppleAuthentication.AppleAuthenticationButtonStyle.BLACK
            }
            cornerRadius={5}
            style={styles.button}
            onPress={async () => {
              try {
                const creds = await AppleAuthentication.signInAsync({
                  requestedScopes: [
                    AppleAuthentication.AppleAuthenticationScope.FULL_NAME,
                    AppleAuthentication.AppleAuthenticationScope.EMAIL,
                  ],
                });
                // signed in
                setCredentials(creds);
              } catch (e) {
                if (e.code === "ERR_CANCELED") {
                  // handle that the user canceled the sign-in flow
                } else {
                  // handle other errors
                }
              }
            }}
          />
        </View>
      )}

      {!connected && (
        <View style={styles.buttonContainer}>
          <Text style={{ fontSize: 40, marginBottom: 20 }}>
            Cannot connect to server
          </Text>
        </View>
      )}
    </View>
  );
}

const styles = StyleSheet.create({
  //Justify content center
  buttonContainer: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
  },
  button: {
    width: 200,
    height: 44,
  },
});