Add localstorage management

This commit is contained in:
dario-cfpt
2019-12-15 12:40:10 +01:00
parent 0ac148d899
commit 5fa7f19eb1
13 changed files with 119 additions and 817 deletions

50
mobile/www/js/index.js Normal file
View File

@ -0,0 +1,50 @@
const baseUrl = "http://localhost:3000/";
let feData = JSON.parse(localStorage.getItem("feData"));
function updateData(data) {
if (Object.keys(data).length > 0) {
localStorage.setItem("feData", JSON.stringify(data));
feData = data;
}
}
if (feData != null) {
fetch(baseUrl + "update", {
method: "POST",
body: JSON.stringify({version: feData.version}) ,
headers: {
'Content-Type': 'application/json'
},
})
.then(res => {
if (res.ok) {
return res.json();
} else {
console.log(res);
}
})
.then(data => {
updateData(data);
})
.catch(err => {
console.log(err);
});
} else {
fetch(baseUrl + "all")
.then(res => {
if (res.ok) {
return res.json();
} else {
console.log(res);
}
})
.then(data => {
updateData(data);
})
.catch(err => {
console.log(err);
});
}