Initial commit - construprogress app
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import './bootstrap';
|
||||
|
||||
import localforage from 'localforage';
|
||||
|
||||
// Sync pending actions when online
|
||||
window.addEventListener('online', () => {
|
||||
fetch('/offline/sync', { method: 'POST', headers: { 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content } })
|
||||
.then(res => res.json())
|
||||
.then(data => console.log('Synced:', data));
|
||||
});
|
||||
|
||||
// Function to store offline progress update
|
||||
window.offlineProgressUpdate = function(phaseId, progress, comment, location) {
|
||||
const payload = { phase_id: phaseId, progress, comment, location };
|
||||
if (navigator.onLine) {
|
||||
fetch('/offline/pending', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content },
|
||||
body: JSON.stringify({ action: 'progress_update', payload })
|
||||
}).then(() => alert('Actualizado online'));
|
||||
} else {
|
||||
localforage.getItem('pendingOffline').then(pending => {
|
||||
const list = pending || [];
|
||||
list.push(payload);
|
||||
localforage.setItem('pendingOffline', list);
|
||||
alert('Guardado localmente, se sincronizará al recuperar internet');
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user