export const fetchPathKeys = () => { return fetch("http://localhost:5000/get-path") .then(res => { if(res.status >= 400) { throw new Error("Server responds with error!"); } return res.json(); }).then(data => { return Object.keys(data) }, err => { console.log(err) }); } export const fetchPaths = () => { return fetch("http://localhost:5000/get-path") .then(res => { if(res.status >= 400) { throw new Error("Server responds with error!"); } return res.json(); }).then(data => { return data }, err => { console.log(err) }) } export function savePathToDb(){ let path = this.props.path if ("switchLatLng" in this.props){ path = path.map(pos => [pos[1], pos[0]]) } let json = JSON.stringify({ path: { name: this.state.savePathKey, coords: path } }) let reqOptions = { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: json } return fetch("http://localhost:5000/set-path", reqOptions) .then(res => { if(res.status >= 400) { throw new Error("Server responds with error!"); } return res.text(); }, err => { console.log(err) }) } export function saveTimeToDb(data){ let json = JSON.stringify(data) let reqOptions = { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: json } return fetch("http://localhost:5000/set-time", reqOptions) .then(res => { if(res.status >= 400) { console.log(res.text) throw new Error("Server responds with error!"); } return res.text(); }, err => { console.log(err) }) }