Skip to content

Commit 0ef9fd4

Browse files
committed
tf is this error 😭
1 parent 7dec411 commit 0ef9fd4

1 file changed

Lines changed: 40 additions & 8 deletions

File tree

Sora/Tracking Services/AniList/HomePage/DetailsView/AniList-DetailsView.swift

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct AniListDetailsView: View {
3636
ProgressView()
3737
.padding()
3838
} else if let media = mediaInfo {
39-
HStack(alignment: .bottom, spacing: 16) {
39+
HStack(alignment: .top, spacing: 16) {
4040
if let coverDict = media["coverImage"] as? [String: Any],
4141
let posterURLString = coverDict["extraLarge"] as? String,
4242
let posterURL = URL(string: posterURLString) {
@@ -55,9 +55,28 @@ struct AniListDetailsView: View {
5555

5656
VStack(alignment: .leading) {
5757
if let titleDict = media["title"] as? [String: Any],
58-
let userPreferred = titleDict["userPreferred"] as? String {
58+
let userPreferred = titleDict["english"] as? String {
5959
Text(userPreferred)
60-
.font(.headline)
60+
.font(.system(size: 17))
61+
.fontWeight(.bold)
62+
.onLongPressGesture {
63+
UIPasteboard.general.string = userPreferred
64+
DropManager.shared.showDrop(title: "Copied to Clipboard", subtitle: "", duration: 1.0, icon: UIImage(systemName: "doc.on.clipboard.fill"))
65+
}
66+
}
67+
68+
if let titleDict = media["title"] as? [String: Any],
69+
let userPreferred = titleDict["romaji"] as? String {
70+
Text(userPreferred)
71+
.font(.system(size: 13))
72+
.foregroundColor(.secondary)
73+
}
74+
75+
if let titleDict = media["title"] as? [String: Any],
76+
let userPreferred = titleDict["native"] as? String {
77+
Text(userPreferred)
78+
.font(.system(size: 13))
79+
.foregroundColor(.secondary)
6180
}
6281
}
6382

@@ -166,12 +185,25 @@ struct AniListDetailsView: View {
166185

167186
let maxValue: Int = scoreDistribution.compactMap { $0["amount"] as? Int }.max() ?? 1
168187

169-
HStack(alignment: .center) {
170-
if let averageScore = media["averageScore"] as? Double {
171-
Text("Average Score: \(String(format: "%.1f", averageScore))")
172-
.font(.headline)
173-
.frame(width: 120, alignment: .leading)
188+
let totalScore = scoreDistribution.reduce(0) { partialResult, dataPoint in
189+
if let score = dataPoint["score"] as? Int, let amount = dataPoint["amount"] as? Int {
190+
return partialResult + score * amount
191+
}
192+
return partialResult
193+
}
194+
195+
let totalCount = scoreDistribution.reduce(0) { partialResult, dataPoint in
196+
if let amount = dataPoint["amount"] as? Int {
197+
return partialResult + amount
174198
}
199+
return partialResult
200+
}
201+
let computedAverage = totalCount > 0 ? Double(totalScore) / Double(totalCount) : 0.0
202+
203+
HStack(alignment: .center) {
204+
Text("Average Score: \(String(format: "%.1f", computedAverage))")
205+
.font(.headline)
206+
.frame(width: 120, alignment: .leading)
175207
VStack(alignment: .center) {
176208
Text("Score Distribution")
177209
.font(.headline)

0 commit comments

Comments
 (0)