123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- const serverUrl = "http://192.168.8.101:5000"
- //const serverUrl = "http://localhost:5000"
- export const fetchPathKeys = () => {
- return fetch(serverUrl + "/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(serverUrl + "/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(serverUrl + "/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(serverUrl + "/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)
- })
- }
|