From 7c0eac53cc6a5a76dfa334519e80424aa81bc1fa Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Tue, 3 May 2022 13:59:06 -0700 Subject: [PATCH] show labels on list cards --- .../Components/FeedCardNavigationLink.swift | 2 +- .../Views/FeedItem/HomeFeedCardView.swift | 95 +++++++++++-------- 2 files changed, 55 insertions(+), 42 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift index 3dc9f8e0e..3776647b7 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift @@ -6,7 +6,7 @@ import Views struct FeedCardNavigationLink: View { @EnvironmentObject var dataService: DataService - let item: LinkedItem + @ObservedObject var item: LinkedItem @ObservedObject var viewModel: HomeFeedViewModel diff --git a/apple/OmnivoreKit/Sources/Views/FeedItem/HomeFeedCardView.swift b/apple/OmnivoreKit/Sources/Views/FeedItem/HomeFeedCardView.swift index 7576b0ab0..a38bebf6e 100644 --- a/apple/OmnivoreKit/Sources/Views/FeedItem/HomeFeedCardView.swift +++ b/apple/OmnivoreKit/Sources/Views/FeedItem/HomeFeedCardView.swift @@ -3,60 +3,73 @@ import SwiftUI import Utils public struct FeedCard: View { - let item: LinkedItem + @ObservedObject var item: LinkedItem public init(item: LinkedItem) { self.item = item } public var body: some View { - HStack(alignment: .top, spacing: 6) { - VStack(alignment: .leading, spacing: 6) { - Text(item.unwrappedTitle) - .font(.appSubheadline) - .foregroundColor(.appGrayTextContrast) - .lineLimit(2) - .frame(maxWidth: .infinity, alignment: .leading) + VStack { + HStack(alignment: .top, spacing: 6) { + VStack(alignment: .leading, spacing: 6) { + Text(item.unwrappedTitle) + .font(.appSubheadline) + .foregroundColor(.appGrayTextContrast) + .lineLimit(2) + .frame(maxWidth: .infinity, alignment: .leading) - if let author = item.author { - Text("By \(author)") - .font(.appCaption) - .foregroundColor(.appGrayText) - .lineLimit(1) + if let author = item.author { + Text("By \(author)") + .font(.appCaption) + .foregroundColor(.appGrayText) + .lineLimit(1) + } + + if let publisherURL = item.publisherHostname { + Text(publisherURL) + .font(.appCaption) + .foregroundColor(.appGrayText) + .underline() + .lineLimit(1) + } } + .frame(maxWidth: .infinity) + .multilineTextAlignment(.leading) + .padding(0) - if let publisherURL = item.publisherHostname { - Text(publisherURL) - .font(.appCaption) - .foregroundColor(.appGrayText) - .underline() - .lineLimit(1) - } - } - .frame(maxWidth: .infinity) - .multilineTextAlignment(.leading) - .padding(0) - - Group { - if let imageURL = item.imageURL { - AsyncLoadingImage(url: imageURL) { imageStatus in - if case let AsyncImageStatus.loaded(image) = imageStatus { - image - .resizable() - .aspectRatio(1, contentMode: .fill) - .frame(width: 80, height: 80) - .cornerRadius(6) - } else if case AsyncImageStatus.loading = imageStatus { - Color.appButtonBackground - .frame(width: 80, height: 80) - .cornerRadius(6) - } else { - EmptyView() + Group { + if let imageURL = item.imageURL { + AsyncLoadingImage(url: imageURL) { imageStatus in + if case let AsyncImageStatus.loaded(image) = imageStatus { + image + .resizable() + .aspectRatio(1, contentMode: .fill) + .frame(width: 80, height: 80) + .cornerRadius(6) + } else if case AsyncImageStatus.loading = imageStatus { + Color.appButtonBackground + .frame(width: 80, height: 80) + .cornerRadius(6) + } else { + EmptyView() + } } } } } + + // Category Labels + ScrollView(.horizontal, showsIndicators: false) { + HStack { + ForEach(item.labels.asArray(of: LinkedItemLabel.self), id: \.self) { + TextChip(feedItemLabel: $0) + } + Spacer() + } + } + .padding(.bottom, 5) } - .frame(maxWidth: .infinity, minHeight: 100, idealHeight: 100, maxHeight: 100) + .padding(.top, 5) } }