Skip to content

Commit

Permalink
fix: implemented quickfly GET crashed dev app CU-94nauz[review]
Browse files Browse the repository at this point in the history
  • Loading branch information
mbetancurt committed Jul 13, 2020
1 parent 3ae97dc commit 6bc9211
Showing 1 changed file with 42 additions and 19 deletions.
61 changes: 42 additions & 19 deletions src/actions/quickfly.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import S from 'sanctuary';
import {Axios, print} from '../state/AdesState';
import {fM} from '../libs/SaferSanctuary';


const quickFlyLocations = [
{
name: 'DronfiesLabs',
cornerNW: [-56.27059936523438, -34.76615576940305],
cornerSE: [-55.948905944824226, -34.95237014224681]
cornerNW: {
type: 'Point',
coordinates: [-56.27059936523438, -34.76615576940305]
},
cornerSE: {
type: 'Point',
coordinates: [-55.948905944824226, -34.95237014224681]
}
}
];

Expand All @@ -19,8 +28,8 @@ function addQuickFly(store, data) {
}

const convertCoordinatesQF = (qf) => {
const cornerNWswap = [qf.cornerNW[1], qf.cornerNW[0]];
const cornerSEswap = [qf.cornerSE[1], qf.cornerSE[0]];
const cornerNWswap = [qf.cornerNW.coordinates[1], qf.cornerNW.coordinates[0]];
const cornerSEswap = [qf.cornerSE.coordinates[1], qf.cornerSE.coordinates[0]];
const newQf = {...qf};
newQf.cornerNW = cornerNWswap;
newQf.cornerSE = cornerSEswap;
Expand All @@ -30,29 +39,43 @@ const convertCoordinatesQF = (qf) => {

/* Actions */
export const fetch = (store) => {
addQuickFly(store, quickFlyLocations);
/*
//addQuickFly(store, quickFlyLocations);
Axios.get('quickfly', {headers: { auth: fM(store.state.auth.token) }})
.then(result => addQuickFly(store, result.data))
.then(result => {
if (Array.from(result.data).length > 0) {
addQuickFly(store, result.data);
} else {
addQuickFly(store, quickFlyLocations);
}
})
.catch(error => {
addQuickFly(store, quickFlyLocations);
print(store.state, true, 'QuickFlyState', error);
});*/
});
};
export const post = (store, data, callback, ) => {
const olds = S.values(store.state.quickFly.list);
data.cornerNW = [data.cornerNW.lng, data.cornerNW.lat];
data.cornerSE = [data.cornerSE.lng, data.cornerSE.lat];
olds.push(data);
addQuickFly(store, olds);
callback && callback();
/*Axios.add('quickfly', data, {headers: { auth: fM(store.state.auth.token) }})
export const post = (store, data, callback, errorCallback) => {
console.log('POSTQF', data);
data.cornerNW = {
type: 'Point',
coordinates: []
};
data.cornerSE = {
type: 'Point',
coordinates: []
};
console.log('cornernw', data.cornerNW);
data.cornerNW.coordinates = [store.state.map.cornerNW.lng, store.state.map.cornerNW.lat];
data.cornerSE.coordinates = [store.state.map.cornerSE.lng, store.state.map.cornerSE.lat];
//addQuickFly(store, olds);
//callback && callback();
Axios.post('quickfly', data, {headers: { auth: fM(store.state.auth.token) }})
.then(result => {
addQuickFly(result.data);
//addQuickFly(result.data);
store.actions.quickFly.fetch();
callback && callback();
})w
})
.catch(error => {
print(store.state, true, 'QuickFlyState', error);
errorCallback && error.response && errorCallback(error.response.data);
});*/
});
};

0 comments on commit 6bc9211

Please sign in to comment.