quick fix
This commit is contained in:
parent
aae53a17d8
commit
ef7116d0bf
1 changed files with 34 additions and 30 deletions
|
|
@ -1,7 +1,37 @@
|
|||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
// MARK: - AnyCodable
|
||||
// Wraps heterogeneous values in the fix_data dictionary (String, Int, or [String]).
|
||||
// Must be defined before CompanionAPIService extension references it.
|
||||
|
||||
struct AnyCodable: Codable {
|
||||
let value: Any
|
||||
|
||||
init(_ value: Any) { self.value = value }
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.singleValueContainer()
|
||||
if let v = try? container.decode([String].self) { value = v; return }
|
||||
if let v = try? container.decode([String: String].self) { value = v; return }
|
||||
if let v = try? container.decode(String.self) { value = v; return }
|
||||
if let v = try? container.decode(Int.self) { value = v; return }
|
||||
value = ""
|
||||
}
|
||||
|
||||
func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.singleValueContainer()
|
||||
switch value {
|
||||
case let v as [String]: try container.encode(v)
|
||||
case let v as [String: String]: try container.encode(v)
|
||||
case let v as String: try container.encode(v)
|
||||
case let v as Int: try container.encode(v)
|
||||
default: try container.encode("")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Conflict Models
|
||||
// Kept in a separate file so both CompanionAPIService and LibraryConflictsView can reference these types.
|
||||
|
||||
struct LibraryConflict: Codable, Identifiable {
|
||||
let type: String
|
||||
|
|
@ -13,7 +43,10 @@ struct LibraryConflict: Codable, Identifiable {
|
|||
let fix_data: [String: AnyCodable]?
|
||||
|
||||
var id: String { "\(type)|\(title)" }
|
||||
}
|
||||
|
||||
// SwiftUI display helpers — in an extension so the base struct has no SwiftUI dependency
|
||||
extension LibraryConflict {
|
||||
var severityColor: Color {
|
||||
severity == "error" ? Color(red: 1, green: 0.176, blue: 0.333) : .yellow
|
||||
}
|
||||
|
|
@ -42,35 +75,6 @@ struct ConflictsResponse: Codable {
|
|||
let issues: [LibraryConflict]
|
||||
}
|
||||
|
||||
// MARK: - AnyCodable
|
||||
// Wraps heterogeneous values in the fix_data dictionary (String, Int, or [String]).
|
||||
|
||||
struct AnyCodable: Codable {
|
||||
let value: Any
|
||||
|
||||
init(_ value: Any) { self.value = value }
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.singleValueContainer()
|
||||
if let v = try? container.decode([String].self) { value = v; return }
|
||||
if let v = try? container.decode([String: String].self) { value = v; return }
|
||||
if let v = try? container.decode(String.self) { value = v; return }
|
||||
if let v = try? container.decode(Int.self) { value = v; return }
|
||||
value = ""
|
||||
}
|
||||
|
||||
func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.singleValueContainer()
|
||||
switch value {
|
||||
case let v as [String]: try container.encode(v)
|
||||
case let v as [String: String]: try container.encode(v)
|
||||
case let v as String: try container.encode(v)
|
||||
case let v as Int: try container.encode(v)
|
||||
default: try container.encode("")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Conflict Manager
|
||||
|
||||
@MainActor
|
||||
|
|
|
|||
Loading…
Reference in a new issue