Browse Source

caching fields answers

master
analuizaff 3 years ago
parent
commit
967f5fbbe1
  1. 21
      src/app/api/client.js
  2. 2
      src/app/components/AssembleModalObject.js
  3. 3
      src/app/components/MapModal.js

21
src/app/api/client.js

@ -1,8 +1,21 @@
import { create } from 'apisauce'
import { create } from "apisauce";
import { useCallback } from "react";
import cache from "../utility/cache";
const apiClient = create({ const apiClient = create({
baseURL: 'https://wpd.brazilsouth.cloudapp.azure.com/api'
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/api",
}); });
export default apiClient;
const get = apiClient.get;
apiClient.get = async (url, params, axiosConfig) => {
const response = await get(url, params, axiosConfig);
if (response.ok) {
cache.store(url, response.data)
return response;
}
const data = JSON.parse( await cache.get(url));
return data ? {ok:true, data} : undefined;
};
export default apiClient;

2
src/app/components/AssembleModalObject.js

@ -145,7 +145,7 @@ async function getPluviometerStatio_informations(id) {
} }
const AssembleModalObject = async (response, name, userId, formId) => { const AssembleModalObject = async (response, name, userId, formId) => {
var situation = null; var situation = null;
var user = null; var user = null;
var institution = null; var institution = null;

3
src/app/components/MapModal.js

@ -324,6 +324,7 @@ function MapModal({ showModal, setShowModal, markers }) {
id, id,
user user
); );
// console.log(result)
if (result.data && showModal && currentMarker == undefined) { if (result.data && showModal && currentMarker == undefined) {
AssembleModalObject( AssembleModalObject(
JSON.stringify(result.data.responseData), JSON.stringify(result.data.responseData),
@ -337,7 +338,7 @@ function MapModal({ showModal, setShowModal, markers }) {
} }
} }
}; };
if (markers && showModal != null && markers.has(showModal)) { if (markers && showModal != null && markers.has(showModal)) {
//currentMarker = markers.get(showModal); //currentMarker = markers.get(showModal);
getAnswers( getAnswers(

Loading…
Cancel
Save