From fa35168bb45f2d49a358e5bdfe897f68a3d5b0d9 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Mon, 17 Oct 2022 16:54:37 +0800 Subject: [PATCH] Display subscription icons in the iOS subscription view --- .../App/Views/Profile/Subscriptions.swift | 25 +++++++++++++++++-- .../Models/DataModels/Subscription.swift | 5 +++- .../Queries/SubscriptionsQuery.swift | 3 ++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/Profile/Subscriptions.swift b/apple/OmnivoreKit/Sources/App/Views/Profile/Subscriptions.swift index 69d11b7a8..9fa414f79 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Profile/Subscriptions.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Profile/Subscriptions.swift @@ -123,7 +123,7 @@ struct SubscriptionCell: View { let subscription: Subscription var body: some View { - VStack { + HStack { VStack(alignment: .leading, spacing: 6) { Text(subscription.name) .font(.appCallout) @@ -140,7 +140,28 @@ struct SubscriptionCell: View { } .multilineTextAlignment(.leading) .padding(.vertical, 8) - .frame(minHeight: 50) + + Spacer() + + Group { + if let icon = subscription.icon, let imageURL = URL(string: icon) { + AsyncImage(url: imageURL) { phase in + if let image = phase.image { + image + .resizable() + .aspectRatio(contentMode: .fill) + .frame(width: 40, height: 40) + .cornerRadius(6) + } else if phase.error != nil { + EmptyView().frame(width: 40, height: 40, alignment: .top) + } else { + Color.appButtonBackground + .frame(width: 40, height: 40) + .cornerRadius(2) + } + } + } + }.frame(minHeight: 50) } } } diff --git a/apple/OmnivoreKit/Sources/Models/DataModels/Subscription.swift b/apple/OmnivoreKit/Sources/Models/DataModels/Subscription.swift index 10d6208a9..6179318df 100644 --- a/apple/OmnivoreKit/Sources/Models/DataModels/Subscription.swift +++ b/apple/OmnivoreKit/Sources/Models/DataModels/Subscription.swift @@ -11,6 +11,7 @@ public struct Subscription { public let unsubscribeMailTo: String? public let updatedAt: Date? public let url: String? + public let icon: String? public init( createdAt: Date?, @@ -22,7 +23,8 @@ public struct Subscription { unsubscribeHttpUrl: String?, unsubscribeMailTo: String?, updatedAt: Date?, - url: String? + url: String?, + icon: String? ) { self.createdAt = createdAt self.description = description @@ -34,6 +36,7 @@ public struct Subscription { self.unsubscribeMailTo = unsubscribeMailTo self.updatedAt = updatedAt self.url = url + self.icon = icon } } diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Queries/SubscriptionsQuery.swift b/apple/OmnivoreKit/Sources/Services/DataService/Queries/SubscriptionsQuery.swift index 2c2976126..a78045904 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Queries/SubscriptionsQuery.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Queries/SubscriptionsQuery.swift @@ -20,7 +20,8 @@ public extension DataService { unsubscribeHttpUrl: try $0.unsubscribeHttpUrl(), unsubscribeMailTo: try $0.unsubscribeMailTo(), updatedAt: try $0.updatedAt().value, - url: try $0.url() + url: try $0.url(), + icon: try $0.icon() ) }