Loading packages/shop-mobile-expo/src/components/Providers/Apollo.tsx +94 −72 Original line number Diff line number Diff line Loading @@ -11,10 +11,11 @@ import { View, Modal, ActivityIndicator, TouchableWithoutFeedback, } from 'react-native'; // HELPERS import { isEmpty } from '../../helpers/utils'; import { checkServer, isEmpty } from '../../helpers/utils'; // ENVIRONMENT import ENV from '../../environments/environment'; Loading @@ -39,7 +40,11 @@ const ApolloProvider: React.FC<Props> = (props) => { ENV.PRODUCTION || __DEV__, ); const [serverHostInpMsg, setServerHostInpMsg] = React.useState<string>(''); const [serverHostLoading] = React.useState<boolean>(false); const [serverHostLoading, setServerHostLoading] = React.useState<boolean>(false); // REFS const serverHostInpRef = React.useRef<TextInput>(null); // FUNCTIONS const onConfirmHost = async () => { Loading @@ -48,15 +53,24 @@ const ApolloProvider: React.FC<Props> = (props) => { return setServerHostInpMsg("Can't be empty"); } const FORMATTED_URI = `http://${serverHostInp}/graphql`; // setServerHostLoading(true); const FORMATTED_HOST = `https://${serverHostInp}`; const FORMATTED_URI = FORMATTED_HOST + '/graphql'; // if (!(await serverReachable(serverHostInp))) { // return setServerHostInpMsg("Can't connect on this host"); // } setServerHostLoading(true); await checkServer( FORMATTED_URI, 5000, () => { setServerHost(FORMATTED_URI); setShowDialogUriConf(false); }, (errMsg) => { setServerHostInpMsg("Can't connect on this host: " + errMsg); }, ).finally(() => { setServerHostLoading(false); }); }; const onCancelHost = () => { Loading @@ -66,7 +80,7 @@ const ApolloProvider: React.FC<Props> = (props) => { // CONFIG const APOLLO_CLIENT = new ApolloClient({ uri: ENV.ENDPOINT.GQL, uri: serverHost || ENV.ENDPOINT.GQL, cache: new InMemoryCache(), defaultOptions: { watchQuery: { fetchPolicy: 'cache-and-network' } }, }); Loading @@ -78,6 +92,10 @@ const ApolloProvider: React.FC<Props> = (props) => { onDismiss={function (): void {}} style={{ ...GS.bgTransparent }} transparent> <TouchableWithoutFeedback onPress={() => { serverHostInpRef.current?.blur(); }}> <View style={{ ...GS.flex1, Loading @@ -102,6 +120,7 @@ const ApolloProvider: React.FC<Props> = (props) => { <View style={{ ...GS.w100, ...GS.my4 }}> <TextInput ref={serverHostInpRef} value={serverHostInp} placeholder='Ex: 10.0.2.2:8443' onChangeText={(text) => { Loading @@ -127,7 +146,9 @@ const ApolloProvider: React.FC<Props> = (props) => { style={{ ...GS.mr2, ...GS.flex1, ...(serverHostLoading ? GS.centered : {}), ...(serverHostLoading ? GS.centered : {}), }}> {serverHostLoading ? ( <ActivityIndicator Loading @@ -152,6 +173,7 @@ const ApolloProvider: React.FC<Props> = (props) => { </View> </View> </View> </TouchableWithoutFeedback> </Modal> {props.children} </Provider> Loading Loading
packages/shop-mobile-expo/src/components/Providers/Apollo.tsx +94 −72 Original line number Diff line number Diff line Loading @@ -11,10 +11,11 @@ import { View, Modal, ActivityIndicator, TouchableWithoutFeedback, } from 'react-native'; // HELPERS import { isEmpty } from '../../helpers/utils'; import { checkServer, isEmpty } from '../../helpers/utils'; // ENVIRONMENT import ENV from '../../environments/environment'; Loading @@ -39,7 +40,11 @@ const ApolloProvider: React.FC<Props> = (props) => { ENV.PRODUCTION || __DEV__, ); const [serverHostInpMsg, setServerHostInpMsg] = React.useState<string>(''); const [serverHostLoading] = React.useState<boolean>(false); const [serverHostLoading, setServerHostLoading] = React.useState<boolean>(false); // REFS const serverHostInpRef = React.useRef<TextInput>(null); // FUNCTIONS const onConfirmHost = async () => { Loading @@ -48,15 +53,24 @@ const ApolloProvider: React.FC<Props> = (props) => { return setServerHostInpMsg("Can't be empty"); } const FORMATTED_URI = `http://${serverHostInp}/graphql`; // setServerHostLoading(true); const FORMATTED_HOST = `https://${serverHostInp}`; const FORMATTED_URI = FORMATTED_HOST + '/graphql'; // if (!(await serverReachable(serverHostInp))) { // return setServerHostInpMsg("Can't connect on this host"); // } setServerHostLoading(true); await checkServer( FORMATTED_URI, 5000, () => { setServerHost(FORMATTED_URI); setShowDialogUriConf(false); }, (errMsg) => { setServerHostInpMsg("Can't connect on this host: " + errMsg); }, ).finally(() => { setServerHostLoading(false); }); }; const onCancelHost = () => { Loading @@ -66,7 +80,7 @@ const ApolloProvider: React.FC<Props> = (props) => { // CONFIG const APOLLO_CLIENT = new ApolloClient({ uri: ENV.ENDPOINT.GQL, uri: serverHost || ENV.ENDPOINT.GQL, cache: new InMemoryCache(), defaultOptions: { watchQuery: { fetchPolicy: 'cache-and-network' } }, }); Loading @@ -78,6 +92,10 @@ const ApolloProvider: React.FC<Props> = (props) => { onDismiss={function (): void {}} style={{ ...GS.bgTransparent }} transparent> <TouchableWithoutFeedback onPress={() => { serverHostInpRef.current?.blur(); }}> <View style={{ ...GS.flex1, Loading @@ -102,6 +120,7 @@ const ApolloProvider: React.FC<Props> = (props) => { <View style={{ ...GS.w100, ...GS.my4 }}> <TextInput ref={serverHostInpRef} value={serverHostInp} placeholder='Ex: 10.0.2.2:8443' onChangeText={(text) => { Loading @@ -127,7 +146,9 @@ const ApolloProvider: React.FC<Props> = (props) => { style={{ ...GS.mr2, ...GS.flex1, ...(serverHostLoading ? GS.centered : {}), ...(serverHostLoading ? GS.centered : {}), }}> {serverHostLoading ? ( <ActivityIndicator Loading @@ -152,6 +173,7 @@ const ApolloProvider: React.FC<Props> = (props) => { </View> </View> </View> </TouchableWithoutFeedback> </Modal> {props.children} </Provider> Loading