mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 10:42:57 +00:00
update
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user