From c72ae2f7d73d65bb2189997d03a460eac308a23a Mon Sep 17 00:00:00 2001 From: scigward <162128369+scigward@users.noreply.github.com> Date: Sat, 16 Aug 2025 23:08:58 +0300 Subject: [PATCH] Update AnilistMatchView.swift --- .../Matching/AnilistMatchView.swift | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Sora/Views/MediaInfoView/Matching/AnilistMatchView.swift b/Sora/Views/MediaInfoView/Matching/AnilistMatchView.swift index 35e996a..392fce1 100644 --- a/Sora/Views/MediaInfoView/Matching/AnilistMatchView.swift +++ b/Sora/Views/MediaInfoView/Matching/AnilistMatchView.swift @@ -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() } -} +} \ No newline at end of file