mirror of
https://github.com/cranci1/Sora.git
synced 2026-04-06 01:29:50 +00:00
Update AnilistMatchView.swift
This commit is contained in:
parent
17861cfcb8
commit
c72ae2f7d7
1 changed files with 20 additions and 4 deletions
|
|
@ -9,7 +9,7 @@ import SwiftUI
|
|||
|
||||
struct AnilistMatchPopupView: View {
|
||||
let seriesTitle: String
|
||||
let onSelect: (Int, String) -> Void
|
||||
let onSelect: (Int, Int?, String) -> Void // Updated to include MAL ID
|
||||
|
||||
@State private var results: [[String: Any]] = []
|
||||
@State private var isLoading = true
|
||||
|
|
@ -53,8 +53,13 @@ struct AnilistMatchPopupView: View {
|
|||
let result = results[index]
|
||||
Button(action: {
|
||||
if let id = result["id"] as? Int {
|
||||
let malID = result["mal_id"] as? Int?
|
||||
let title = result["title"] as? String ?? seriesTitle
|
||||
onSelect(id, title)
|
||||
|
||||
// Log the IDs
|
||||
Logger.shared.log("Selected AniList ID: \(id), MAL ID: \(malID?.description ?? "nil")", type: "Debug")
|
||||
|
||||
onSelect(id, malID, title)
|
||||
dismiss()
|
||||
}
|
||||
}) {
|
||||
|
|
@ -86,6 +91,11 @@ struct AnilistMatchPopupView: View {
|
|||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
if let malID = result["mal_id"] as? Int {
|
||||
Text("MAL ID: \(malID)")
|
||||
.font(.caption2)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
|
@ -153,7 +163,7 @@ struct AnilistMatchPopupView: View {
|
|||
Button("Cancel", role: .cancel) { }
|
||||
Button("Save") {
|
||||
if let idInt = Int(manualIDText.trimmingCharacters(in: .whitespaces)) {
|
||||
onSelect(idInt, seriesTitle)
|
||||
onSelect(idInt, nil, seriesTitle)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
|
@ -170,6 +180,7 @@ struct AnilistMatchPopupView: View {
|
|||
Page(page: 1, perPage: 6) {
|
||||
media(search: "\(seriesTitle)", type: ANIME) {
|
||||
id
|
||||
idMal
|
||||
title {
|
||||
romaji
|
||||
english
|
||||
|
|
@ -202,8 +213,13 @@ struct AnilistMatchPopupView: View {
|
|||
results = mediaList.map { media in
|
||||
let titleInfo = media["title"] as? [String: Any]
|
||||
let cover = (media["coverImage"] as? [String: Any])?["large"] as? String
|
||||
let malID = media["idMal"] as? Int?
|
||||
|
||||
Logger.shared.log("Found AniList ID: \(media["id"] ?? "nil"), MAL ID: \(malID?.description ?? "nil")", type: "Debug")
|
||||
|
||||
return [
|
||||
"id": media["id"] ?? 0,
|
||||
"mal_id": malID as Any,
|
||||
"title": titleInfo?["romaji"] ?? "Unknown",
|
||||
"title_english": titleInfo?["english"] as Any,
|
||||
"cover": cover as Any
|
||||
|
|
@ -212,4 +228,4 @@ struct AnilistMatchPopupView: View {
|
|||
}
|
||||
}.resume()
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue