Fix
This commit is contained in:
parent
62160354bf
commit
3dc31548bf
|
@ -69,21 +69,27 @@
|
||||||
throw new Error('Network response was not ok.');
|
throw new Error('Network response was not ok.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const lastModifiedServer = new Date(response.headers.get('Last-Modified'));
|
||||||
|
const lastModifiedLocal = new Date(localStorage.getItem('lastModified'));
|
||||||
|
|
||||||
|
if (lastModifiedServer > lastModifiedLocal || !lastModifiedLocal) {
|
||||||
const newData = await response.json();
|
const newData = await response.json();
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
|
|
||||||
Object.entries(newData).forEach(([key, value]) => {
|
Object.entries(newData).forEach(([key, value]) => {
|
||||||
localStorage.setItem(key, value);
|
localStorage.setItem(key, value);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
localStorage.setItem('lastModified', lastModifiedServer.toISOString());
|
||||||
console.log('Fetched savedata');
|
console.log('Fetched savedata');
|
||||||
window.reload();
|
} else {
|
||||||
|
console.log('Local data is up-to-date or server data older.');
|
||||||
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching localStorage:', error);
|
console.error('Error fetching localStorage:', error);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function syncLocalStorage(){
|
async function syncLocalStorage(){
|
||||||
console.log("Syncing...")
|
console.log("Syncing...")
|
||||||
uploadLocalStorage();
|
uploadLocalStorage();
|
||||||
|
|
Loading…
Reference in New Issue