Files
ratebubble/ios/Ratebubble/App/MainViewModel.swift

37 lines
951 B
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Foundation
@MainActor
final class MainViewModel: ObservableObject {
@Published var sharedURL: String = ""
@Published var isLoading: Bool = false
@Published var result: GetInfoResponse?
@Published var errorMessage: String?
func consumeSharedURLIfAny() {
guard let incoming = SharedPayloadStore.consumeIncomingURL(), !incoming.isEmpty else {
return
}
sharedURL = incoming
Task { await fetch() }
}
func fetch() async {
guard !sharedURL.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
errorMessage = "Paylaşılan URL boş olamaz."
return
}
isLoading = true
errorMessage = nil
result = nil
do {
result = try await APIClient.shared.getInfo(url: sharedURL)
} catch {
errorMessage = error.localizedDescription
}
isLoading = false
}
}