feat(ios): share extension ile Ratebubble iOS istemcisini ekle ve paylaşım akışını düzelt
This commit is contained in:
82
ios/Ratebubble/App/ContentView.swift
Normal file
82
ios/Ratebubble/App/ContentView.swift
Normal file
@@ -0,0 +1,82 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ContentView: View {
|
||||
@StateObject private var viewModel = MainViewModel()
|
||||
@Environment(\.scenePhase) private var scenePhase
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
Form {
|
||||
Section("Paylaşılan Link") {
|
||||
TextField("https://www.netflix.com/tr/title/...", text: $viewModel.sharedURL)
|
||||
.textInputAutocapitalization(.never)
|
||||
.autocorrectionDisabled(true)
|
||||
.keyboardType(.URL)
|
||||
|
||||
Button("Backend'den Getir") {
|
||||
Task { await viewModel.fetch() }
|
||||
}
|
||||
.disabled(viewModel.isLoading)
|
||||
}
|
||||
|
||||
if viewModel.isLoading {
|
||||
Section {
|
||||
HStack {
|
||||
ProgressView()
|
||||
Text("Veri alınıyor...")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let error = viewModel.errorMessage {
|
||||
Section("Hata") {
|
||||
Text(error)
|
||||
.foregroundStyle(.red)
|
||||
}
|
||||
}
|
||||
|
||||
if let result = viewModel.result {
|
||||
Section("Sonuç") {
|
||||
KeyValueRow(key: "Provider", value: result.provider)
|
||||
KeyValueRow(key: "Title", value: result.title)
|
||||
KeyValueRow(key: "Year", value: result.year.map(String.init) ?? "-")
|
||||
KeyValueRow(key: "Type", value: result.type)
|
||||
KeyValueRow(key: "Age Rating", value: result.ageRating ?? "-")
|
||||
KeyValueRow(key: "Current Season", value: result.currentSeason.map(String.init) ?? "-")
|
||||
KeyValueRow(key: "Genres", value: result.genres.joined(separator: ", "))
|
||||
KeyValueRow(key: "Cast", value: result.cast.joined(separator: ", "))
|
||||
KeyValueRow(key: "Plot", value: result.plot ?? "-")
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle("Ratebubble")
|
||||
}
|
||||
.onAppear {
|
||||
viewModel.consumeSharedURLIfAny()
|
||||
}
|
||||
.onOpenURL { _ in
|
||||
viewModel.consumeSharedURLIfAny()
|
||||
}
|
||||
.onChange(of: scenePhase) { phase in
|
||||
if phase == .active {
|
||||
viewModel.consumeSharedURLIfAny()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct KeyValueRow: View {
|
||||
let key: String
|
||||
let value: String
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(key)
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
Text(value.isEmpty ? "-" : value)
|
||||
.font(.body)
|
||||
}
|
||||
.padding(.vertical, 2)
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
10
ios/Ratebubble/App/RatebubbleApp.swift
Normal file
10
ios/Ratebubble/App/RatebubbleApp.swift
Normal file
@@ -0,0 +1,10 @@
|
||||
import SwiftUI
|
||||
|
||||
@main
|
||||
struct RatebubbleApp: App {
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
ContentView()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user