ReadKeep/readeck/Domain/Model/OfflineBookmarkSyncState.swift
Ilyas Hallak ffb41347af refactor: Implement state machine architecture for offline sync
- Replace multiple boolean properties with single OfflineBookmarkSyncState enum
- Add Use Case pattern for OfflineSyncManager with dependency injection
- Simplify LocalBookmarksSyncView using state-driven UI with external bindings
- Convert OfflineBookmarksViewModel to use @Observable instead of ObservableObject
- Move credentials from Core Data to Keychain for better persistence
- Implement comprehensive database migration for App Group containers
- Add structured logging throughout sync operations and API calls

Architecture improvements follow MVVM principles with clean separation of concerns.
2025-08-18 22:58:42 +02:00

62 lines
1.2 KiB
Swift

import Foundation
enum OfflineBookmarkSyncState: Equatable {
case idle
case pending(count: Int)
case syncing(count: Int, status: String?)
case success(syncedCount: Int)
case error(String)
var localBookmarkCount: Int {
switch self {
case .idle:
return 0
case .pending(let count):
return count
case .syncing(let count, _):
return count
case .success:
return 0
case .error:
return 0
}
}
var isSyncing: Bool {
switch self {
case .syncing:
return true
default:
return false
}
}
var syncStatus: String? {
switch self {
case .syncing(_, let status):
return status
case .error(let message):
return message
default:
return nil
}
}
var showSuccessMessage: Bool {
switch self {
case .success:
return true
default:
return false
}
}
var syncedBookmarkCount: Int {
switch self {
case .success(let count):
return count
default:
return 0
}
}
}