{"size": 1372, "ext": "js", "max_stars_repo_path": "conceitos-dev/mobile/src/index.js", "max_stars_repo_name": "angeloevangelista/gostack", "max_stars_repo_stars_event_min_datetime": "2020-08-19T23:04:12.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-19T23:04:12.000Z", "max_issues_repo_path": "conceitos-dev/mobile/src/index.js", "max_issues_repo_name": "angeloevangelista/gostack", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "conceitos-dev/mobile/src/index.js", "max_forks_repo_name": "angeloevangelista/gostack", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.4918032787, "max_line_length": 70, "alphanum_fraction": 0.5758017493}
import React, { useEffect, useState } from 'react';
import {
  SafeAreaView,
  Text,
  StatusBar,
  Alert,
  FlatList,
  TouchableOpacity,
} from 'react-native';

import api from './services/api';

import styles from './styles';

const App = () => {
  const [projects, setProjects] = useState([]);

  useEffect(() => {
    api
      .get('projects')
      .then((response) => {
        setProjects(response.data);
      })
      .catch(() => Alert.alert('Falha ao carregar projetos'));
  }, []);

  async function handleAddProject() {
    const response = await api.post('projects', {
      title: `Projero número ${Date.now()}`,
      owner: 'Angelo Evangelista',
    });

    setProjects([...projects, response.data]);
  }

  return (
    <>
      <StatusBar barStyle="light-content" backgroundColor="#7159c1" />

      <SafeAreaView style={styles.container}>
        <FlatList
          data={projects}
          keyExtractor={(project) => project.id}
          renderItem={({ item: project }) => (
            <Text style={styles.project}>{project.title}</Text>
          )}
        />

        <TouchableOpacity
          onPress={handleAddProject}
          activeOpacity={0.65}
          style={styles.button}>
          <Text style={styles.buttonText}>Adicionar projeto</Text>
        </TouchableOpacity>
      </SafeAreaView>
    </>
  );
};

export default App;
