Commit a3c98a08 authored by Neosoulink's avatar Neosoulink
Browse files

feat: save prev host

parent 3a1fcb2c
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ import {
	ActivityIndicator,
	TouchableWithoutFeedback,
} from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';

// HELPERS
import { checkServer, isEmpty } from '../../helpers/utils';
@@ -56,6 +57,7 @@ const ApolloProvider: React.FC<Props> = (props) => {
		const FORMATTED_HOST = `https://${serverHostInp}`;
		const FORMATTED_URI = FORMATTED_HOST + '/graphql';

		AsyncStorage.setItem('serverHost', serverHostInp);
		setServerHostLoading(true);

		await checkServer(
@@ -85,6 +87,17 @@ const ApolloProvider: React.FC<Props> = (props) => {
		defaultOptions: { watchQuery: { fetchPolicy: 'cache-and-network' } },
	});

	// EFFECTS
	React.useEffect(() => {
		(async () => {
			const LOCAL_SERVER_HOST = await AsyncStorage.getItem('serverHost');

			if (typeof LOCAL_SERVER_HOST === 'string') {
				setServerHostInp(LOCAL_SERVER_HOST);
			}
		})();
	}, []);

	return (
		<Provider client={APOLLO_CLIENT}>
			<Modal