Browse Source

testing API connection - fetching data

master
analuizaff 3 years ago
parent
commit
4191518af0
  1. 8
      src/app/api/client.js
  2. 9
      src/app/api/getforms.js
  3. 19
      src/app/screens/MapFeedScreen.js

8
src/app/api/client.js

@ -0,0 +1,8 @@
import { create } from 'apisauce'
const apiClient = create({
baseURL: 'https://waterproofing.geog.uni-heidelberg.de/api'
});
export default apiClient;

9
src/app/api/getforms.js

@ -0,0 +1,9 @@
import client from './client';
const endpoint = '/hot/capability'
const getForms = () => client.get(endpoint);
export default {
getForms,
}

19
src/app/screens/MapFeedScreen.js

@ -1,11 +1,28 @@
import React, { useEffect, useContext } from "react";
import React, { useEffect, useContext, useState } from "react";
import { StyleSheet, View } from "react-native";
import OpenStreetMap from "../components/map/OpenStreetMap";
import attachFocusToQuery from "../hooks/useFocus";
import { MapMarkerList } from "../components/MapMarkerList";
import formsApi from "../api/getforms";
export default function MapFeedScreen() {
const focusChanged = attachFocusToQuery();
const [error, setError] = useState(false);
useEffect(() => {
loadForms();
}, []);
const loadForms = async () => {
const response = await formsApi.getForms();
console.log(response);
if (!response.ok) {
console.log("resposta não ok!");
return setError(true);
}
setError(false);
}
return (
<View style={styles.container}>

Loading…
Cancel
Save