Browse Source

adding a verification to cachedData before dispatch

master
analuizaff 3 years ago
parent
commit
13334a9e69
  1. 9
      src/app/hooks/useSocketMarkers.js

9
src/app/hooks/useSocketMarkers.js

@ -116,8 +116,6 @@ function buildPolygonsObject(response, name) {
}
function buildMarkerObject(response, name) {
console.log("\n\n--------------------------------------------------------");
//console.log(response);
const r = JSON.parse(response);
const resposta = r.formsanswersgeom;
@ -127,7 +125,6 @@ function buildMarkerObject(response, name) {
if (r.array_to_json) {
situation = r.array_to_json.find((field) => field.fieldname == "situation");
}
// console.log(situation.fieldsanswersvalue);
return {
ID: r.formsanswersid,
@ -144,13 +141,10 @@ function buildMarkerObject(response, name) {
function verifyResponse(response, name) {
var markers = [];
var cache_marker = [];
if (response) {
const answer = JSON.parse(response);
if (answer.success == true) {
const formAnswer = answer.responseData.array_to_json;
answer.responseData.array_to_json.forEach((r) => {
if (r.formcode == "FLOODZONES_OFFICIAL") {
markers.push(buildPolygonsObject(JSON.stringify(r), name));
@ -256,7 +250,7 @@ export default function useSocketMarkers(fetchFromCache) {
if (fetchFromCache) {
formsKeys.forEach((key) => {
cache.get(key).then((cachedData) => {
if (cachedData) {
if (cachedData && cachedData?.success) {
dispatch({ increment: JSON.parse(cachedData) });
}
});
@ -266,7 +260,6 @@ export default function useSocketMarkers(fetchFromCache) {
global.formsSockets.forEach((socket) =>
getFormsAnswers(socket, dispatch, fetchFromCache)
);
//console.log(state.markers)
return state;
}
Loading…
Cancel
Save