Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { useQuery, useSubscription } from '@apollo/react-hooks';
- import React from 'react';
- import { useTranslation } from 'react-i18next';
- import { ActivityIndicator, StyleSheet, View } from 'react-native';
- import { NavigationParams, NavigationScreenProp, NavigationState } from 'react-navigation';
- import { ScreenProps } from '../../../../App';
- import CustomIcon from '../../../assets/icons/CustomIcon';
- import { CustomButton } from '../../../components/button/CustomButton';
- import Header from '../../../components/text/Header';
- import SubHeader from '../../../components/text/SubHeader';
- import Constant from '../../../constants/Constant';
- import { SUBSCRIBE_GATEWAY, USER } from '../../../queries/queries';
- import {
- retrieveGatewayPings,
- retrieveGatewayPingsVariables,
- } from '../../../screens/Setup/__generated__/retrieveGatewayPings';
- import { user } from '../../HomeScreen/__generated__/user';
- interface Props {
- navigation: NavigationScreenProp<NavigationState, NavigationParams>;
- screenProps: ScreenProps;
- }
- function createToastAndSetFound(navigation: NavigationScreenProp<NavigationState, NavigationParams>, setFound: any) {
- setFound(true);
- setTimeout(() => {
- navigation.navigate('PairingSensors');
- }, 200);
- }
- const SearchingYourHub = ({ navigation, screenProps }: Props) => {
- const { t, i18n } = useTranslation(['onboarding']);
- const { data: userData, error, fetchMore } = useQuery<user>(USER, { fetchPolicy: 'cache-first' });
- if (!(userData && userData.user)) return null;
- const user = userData.user;
- const [found, setFound] = useState(false);
- const { data } = useSubscription<retrieveGatewayPings, retrieveGatewayPingsVariables>(SUBSCRIBE_GATEWAY, {
- variables: { gatewayId: user.gateway.id },
- onSubscriptionData: ({ client }) => {
- fetchMore({
- updateQuery: () => {
- userData && screenProps.updateState({ user: userData.user });
- if (
- (data && data.retrieveGatewayPings) ||
- (userData && userData.user && userData.user.gateway.status === 'ACTIVE')
- ) {
- createToastAndSetFound(navigation, setFound);
- }
- },
- });
- },
- });
- return (
- <View style={styles.container}>
- <View style={[styles.circle, found ? styles.solid : styles.dashed]}>
- <CustomIcon name="hub" size={18} style={styles.image} />
- </View>
- <Header>Test</Header>
- <SubHeader>Test</SubHeader>
- {(!found && <ActivityIndicator size="large" color="#0000ff" />) || (
- <View style={styles.buttonContainer}>
- <CustomButton
- title={t('next', { ns: 'fields', defaultValue: 'Next', lng: i18n.language })}
- onPress={}
- style={styles.buttonStyle}
- textStyle={styles.buttonTextStyle}
- />
- </View>
- )}
- </View>
- );
- };
- export default SearchingYourHub;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement