This commit is contained in:
Tomas Dvorak
2026-03-13 14:34:19 +01:00
parent 84a8acf944
commit 30d70a6aeb
126 changed files with 27297 additions and 29069 deletions
+12 -1
View File
@@ -47,7 +47,6 @@ class OfflineSyncService {
constructor() {
this.initializeNetworkListener();
this.loadSyncQueue();
this.startPeriodicSync();
}
private initializeNetworkListener() {
@@ -61,6 +60,9 @@ class OfflineSyncService {
const stored = await AsyncStorage.getItem(SYNC_QUEUE_KEY);
if (stored) {
this.syncQueue = JSON.parse(stored);
if (this.syncQueue.length > 0) {
this.startPeriodicSync();
}
}
} catch (error) {
console.error('Failed to load sync queue:', error);
@@ -76,6 +78,10 @@ class OfflineSyncService {
}
private startPeriodicSync() {
if (this.syncInterval) {
return;
}
// Try to sync every 30 seconds when online
this.syncInterval = setInterval(() => {
if (this.isOnline && this.syncQueue.length > 0) {
@@ -99,6 +105,7 @@ class OfflineSyncService {
};
this.syncQueue.push(syncItem);
this.startPeriodicSync();
this.saveSyncQueue();
// Try to sync immediately if online
@@ -135,6 +142,10 @@ class OfflineSyncService {
this.syncQueue = remainingItems;
this.saveSyncQueue();
if (this.syncQueue.length === 0) {
this.stopPeriodicSync();
}
}
private async processSyncItem(item: SyncItem, api: any) {