feat(ios): share extension ile Ratebubble iOS istemcisini ekle ve paylaşım akışını düzelt
This commit is contained in:
36
ios/Ratebubble/App/MainViewModel.swift
Normal file
36
ios/Ratebubble/App/MainViewModel.swift
Normal file
@@ -0,0 +1,36 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user