import Foundation /// One screen's loading lifecycle. `empty` is a first-class state, not a /// failure — exit 3 lands here, and so does a list with nothing in it. nonisolated enum LoadState: Sendable { case loading case loaded(Value) case empty(String) case failed(String) var value: Value? { if case .loaded(let value) = self { return value } return nil } } extension LoadState { /// Map any thrown error onto the state a screen should show. static func from(_ error: any Error) -> LoadState { guard let error = error as? GitbayError else { return .failed(GitbayError.transport(error).userFacingMessage) } return error.isEmptyState ? .empty(error.userFacingMessage) : .failed(error.userFacingMessage) } }