From 0ef9fd47fb42c48b9578c6e60b582402940b7e04 Mon Sep 17 00:00:00 2001 From: cranci1 <100066266+cranci1@users.noreply.github.com> Date: Fri, 14 Feb 2025 14:44:27 +0100 Subject: [PATCH] tf is this error :sob: --- .../DetailsView/AniList-DetailsView.swift | 48 +++++++++++++++---- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/Sora/Tracking Services/AniList/HomePage/DetailsView/AniList-DetailsView.swift b/Sora/Tracking Services/AniList/HomePage/DetailsView/AniList-DetailsView.swift index 3b4d8d1..16736a8 100644 --- a/Sora/Tracking Services/AniList/HomePage/DetailsView/AniList-DetailsView.swift +++ b/Sora/Tracking Services/AniList/HomePage/DetailsView/AniList-DetailsView.swift @@ -36,7 +36,7 @@ struct AniListDetailsView: View { ProgressView() .padding() } else if let media = mediaInfo { - HStack(alignment: .bottom, spacing: 16) { + HStack(alignment: .top, spacing: 16) { if let coverDict = media["coverImage"] as? [String: Any], let posterURLString = coverDict["extraLarge"] as? String, let posterURL = URL(string: posterURLString) { @@ -55,9 +55,28 @@ struct AniListDetailsView: View { VStack(alignment: .leading) { if let titleDict = media["title"] as? [String: Any], - let userPreferred = titleDict["userPreferred"] as? String { + let userPreferred = titleDict["english"] as? String { Text(userPreferred) - .font(.headline) + .font(.system(size: 17)) + .fontWeight(.bold) + .onLongPressGesture { + UIPasteboard.general.string = userPreferred + DropManager.shared.showDrop(title: "Copied to Clipboard", subtitle: "", duration: 1.0, icon: UIImage(systemName: "doc.on.clipboard.fill")) + } + } + + if let titleDict = media["title"] as? [String: Any], + let userPreferred = titleDict["romaji"] as? String { + Text(userPreferred) + .font(.system(size: 13)) + .foregroundColor(.secondary) + } + + if let titleDict = media["title"] as? [String: Any], + let userPreferred = titleDict["native"] as? String { + Text(userPreferred) + .font(.system(size: 13)) + .foregroundColor(.secondary) } } @@ -166,12 +185,25 @@ struct AniListDetailsView: View { let maxValue: Int = scoreDistribution.compactMap { $0["amount"] as? Int }.max() ?? 1 - HStack(alignment: .center) { - if let averageScore = media["averageScore"] as? Double { - Text("Average Score: \(String(format: "%.1f", averageScore))") - .font(.headline) - .frame(width: 120, alignment: .leading) + let totalScore = scoreDistribution.reduce(0) { partialResult, dataPoint in + if let score = dataPoint["score"] as? Int, let amount = dataPoint["amount"] as? Int { + return partialResult + score * amount } + return partialResult + } + + let totalCount = scoreDistribution.reduce(0) { partialResult, dataPoint in + if let amount = dataPoint["amount"] as? Int { + return partialResult + amount + } + return partialResult + } + let computedAverage = totalCount > 0 ? Double(totalScore) / Double(totalCount) : 0.0 + + HStack(alignment: .center) { + Text("Average Score: \(String(format: "%.1f", computedAverage))") + .font(.headline) + .frame(width: 120, alignment: .leading) VStack(alignment: .center) { Text("Score Distribution") .font(.headline)