<commit_before>import { useNavigation } from '@react-navigation/native';
import { Button, Icon } from '@ui-kitten/components';
import * as Linking from 'expo-linking';
import * as Location from 'expo-location';
import propTypes from 'prop-types';
import React from 'react';
import { Alert, AppState, Platform, StyleSheet, useWindowDimensions, View } from 'react-native';
import MapView, { PROVIDER_GOOGLE, UrlTile } from 'react-native-maps';
import useAuth from '../auth/context';
import config from '../config';
import RootView from '../RootView';
import { wrapAsyncWithDelay } from '../utilities';

const MapButton = ({ iconName, onPress, style }) => {
  const iconSize = 30;
  const ButtonIcon = (props) => <Icon {...props} name={iconName} height={iconSize} width={iconSize} />;

  return <Button accessoryLeft={ButtonIcon} style={[styles.mapButton, style]} size="tiny" onPress={onPress} />;
};
MapButton.propTypes = {
  iconName: propTypes.string.isRequired,
  onPress: propTypes.func.isRequired,
  style: propTypes.object,
};

const locationToRegion = function (location) {
  return {
    latitude: location.coords.latitude,
    longitude: location.coords.longitude,
    latitudeDelta: 0.1,
    longitudeDelta: 0.05,
  };
};

export default function MainScreen() {
  const navigation = useNavigation();
  const [initialLocation, setInitialLocation] = React.useState(null);
  const appState = React.useRef(AppState.currentState);
  const [showSpinner, setShowSpinner] = React.useState(false);
  const mapView = React.useRef(null);
  const { authInfo } = useAuth();

  const getLocation = async () => {
    let location;
    try {
      location = await Location.getCurrentPositionAsync({
        accuracy: Location.Accuracy.Low,
      });
    } catch (error) {
      console.log(`getCurrentPositionAsync: ${error}`);

      location = await Location.getLastKnownPositionAsync({
        accuracy: Location.Accuracy.Low,
      });
    }

    return location;
  };

  React.useEffect(() => {
    const initLocation = async () => {
      const result = await Location.requestForegroundPermissionsAsync();
      if (result.status !== 'granted') {
        Alert.alert('Error', 'Location permission are required to submit reports.', [
          { text: 'OK', onPress: () => Linking.openSettings() },
        ]);

        return;
      }

      const location = await getLocation();

      setInitialLocation(location);
    };

    const handleAppStateChange = async (nextAppState) => {
      if (appState.current.match(/inactive|background/) && nextAppState === 'active' && !initialLocation) {
        await wrapAsyncWithDelay(
          initLocation,
          () => setShowSpinner(true),
          () => setShowSpinner(false),
          config.SPINNER_DELAY
        );
      }

      appState.current = nextAppState;
    };

    AppState.addEventListener('change', handleAppStateChange);

    wrapAsyncWithDelay(
      initLocation,
      () => setShowSpinner(true),
      () => setShowSpinner(false),
      config.SPINNER_DELAY
    );

    return () => AppState.removeEventListener('change', handleAppStateChange);
  }, []);

  const zoomToCurrentLocation = async () => {
    const location = await getLocation();

    mapView.current.animateToRegion(locationToRegion(location));
  };
  const showAddReport = () => {
    console.log('showAddReport');
  };
  const showAddRoute = () => {
    console.log('showAddRoute');<commit_msg>fix(front): pan, don't zoom on location button<commit_after>import { useNavigation } from '@react-navigation/native';
import { Button, Icon } from '@ui-kitten/components';
import * as Linking from 'expo-linking';
import * as Location from 'expo-location';
import propTypes from 'prop-types';
import React from 'react';
import { Alert, AppState, Platform, StyleSheet, useWindowDimensions, View } from 'react-native';
import MapView, { PROVIDER_GOOGLE, UrlTile } from 'react-native-maps';
import useAuth from '../auth/context';
import config from '../config';
import RootView from '../RootView';
import { wrapAsyncWithDelay } from '../utilities';

const MapButton = ({ iconName, onPress, style }) => {
  const iconSize = 30;
  const ButtonIcon = (props) => <Icon {...props} name={iconName} height={iconSize} width={iconSize} />;

  return <Button accessoryLeft={ButtonIcon} style={[styles.mapButton, style]} size="tiny" onPress={onPress} />;
};
MapButton.propTypes = {
  iconName: propTypes.string.isRequired,
  onPress: propTypes.func.isRequired,
  style: propTypes.object,
};

const locationToRegion = function (location) {
  return {
    latitude: location.coords.latitude,
    longitude: location.coords.longitude,
    latitudeDelta: 0.1,
    longitudeDelta: 0.05,
  };
};

export default function MainScreen() {
  const navigation = useNavigation();
  const [initialLocation, setInitialLocation] = React.useState(null);
  const appState = React.useRef(AppState.currentState);
  const [showSpinner, setShowSpinner] = React.useState(false);
  const mapView = React.useRef(null);
  const { authInfo } = useAuth();

  const getLocation = async () => {
    let location;
    try {
      location = await Location.getCurrentPositionAsync({
        accuracy: Location.Accuracy.Low,
      });
    } catch (error) {
      console.log(`getCurrentPositionAsync: ${error}`);

      location = await Location.getLastKnownPositionAsync({
        accuracy: Location.Accuracy.Low,
      });
    }

    return location;
  };

  React.useEffect(() => {
    const initLocation = async () => {
      const result = await Location.requestForegroundPermissionsAsync();
      if (result.status !== 'granted') {
        Alert.alert('Error', 'Location permission are required to submit reports.', [
          { text: 'OK', onPress: () => Linking.openSettings() },
        ]);

        return;
      }

      const location = await getLocation();

      setInitialLocation(location);
    };

    const handleAppStateChange = async (nextAppState) => {
      if (appState.current.match(/inactive|background/) && nextAppState === 'active' && !initialLocation) {
        await wrapAsyncWithDelay(
          initLocation,
          () => setShowSpinner(true),
          () => setShowSpinner(false),
          config.SPINNER_DELAY
        );
      }

      appState.current = nextAppState;
    };

    AppState.addEventListener('change', handleAppStateChange);

    wrapAsyncWithDelay(
      initLocation,
      () => setShowSpinner(true),
      () => setShowSpinner(false),
      config.SPINNER_DELAY
    );

    return () => AppState.removeEventListener('change', handleAppStateChange);
  }, []);

  const zoomToCurrentLocation = async () => {
    const location = await getLocation();

    mapView.current.animateCamera({
      center: {
        latitude: location.coords.latitude,
        longitude: location.coords.longitude,
      },
    });
  };
  const showAddReport = () => {
    console.log('showAddReport');
  };
  const showAddRoute = () => {
    console.log('showAddRoute');
{'fraction_non_alphanumeric': 0.13778795249678066, 'fraction_numerical': 0.002003147803691515, 'mean_word_length': 3.483643361128929, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4480236', 'n_tokens_mistral': 2037, 'n_tokens_neox': 1993, 'n_words': 444}