From 2f4f24dd6be016d207a70030330dc97200b35d8d Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Thu, 5 May 2022 20:32:50 -0700 Subject: [PATCH 1/3] add a sortedLabels computed property on LinkedItem --- .../Sources/App/Views/Labels/LabelsViewModel.swift | 2 +- apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift | 6 ++++++ apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift | 2 +- .../Sources/Views/FeedItem/HomeFeedCardView.swift | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsViewModel.swift b/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsViewModel.swift index 92aa9df2a..e0a7aa062 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsViewModel.swift @@ -22,7 +22,7 @@ import Views dataService.viewContext.performAndWait { self.labels = labelIDs.compactMap { dataService.viewContext.object(with: $0) as? LinkedItemLabel } } - let selLabels = initiallySelectedLabels ?? item?.labels.asArray(of: LinkedItemLabel.self) ?? [] + let selLabels = initiallySelectedLabels ?? item?.sortedLabels ?? [] for label in labels { if selLabels.contains(label) { selectedLabels.append(label) diff --git a/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift b/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift index 1e1fd0363..c6b8421a3 100644 --- a/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift +++ b/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift @@ -58,6 +58,12 @@ public extension LinkedItem { return URL(string: pageURLString ?? "") } + var sortedLabels: [LinkedItemLabel] { + labels.asArray(of: LinkedItemLabel.self).sorted { + ($0.name ?? "").lowercased() < ($1.name ?? "").lowercased() + } + } + var labelsJSONString: String { let labels = self.labels.asArray(of: LinkedItemLabel.self).map { label in [ diff --git a/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift b/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift index f9e5c49ba..bb2dc5c33 100644 --- a/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift +++ b/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift @@ -151,7 +151,7 @@ public struct GridCard: View { // Category Labels ScrollView(.horizontal, showsIndicators: false) { HStack { - ForEach(item.labels.asArray(of: LinkedItemLabel.self), id: \.self) { + ForEach(item.sortedLabels, id: \.self) { TextChip(feedItemLabel: $0) } Spacer() diff --git a/apple/OmnivoreKit/Sources/Views/FeedItem/HomeFeedCardView.swift b/apple/OmnivoreKit/Sources/Views/FeedItem/HomeFeedCardView.swift index 9bf95af7d..afb3f2916 100644 --- a/apple/OmnivoreKit/Sources/Views/FeedItem/HomeFeedCardView.swift +++ b/apple/OmnivoreKit/Sources/Views/FeedItem/HomeFeedCardView.swift @@ -67,7 +67,7 @@ public struct FeedCard: View { // Category Labels ScrollView(.horizontal, showsIndicators: false) { HStack { - ForEach(item.labels.asArray(of: LinkedItemLabel.self), id: \.self) { + ForEach(item.sortedLabels, id: \.self) { TextChip(feedItemLabel: $0) } Spacer() From fd1e80b01db70100235fadd3c86fa7515309ee6f Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Thu, 5 May 2022 20:46:17 -0700 Subject: [PATCH 2/3] use Capsule rather than cornerRadius to create text chip --- apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift | 1 - apple/OmnivoreKit/Sources/Views/TextChip.swift | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift b/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift index bb2dc5c33..bd1f03cd1 100644 --- a/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift +++ b/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift @@ -156,7 +156,6 @@ public struct GridCard: View { } Spacer() } - .frame(height: 30) .padding(.horizontal) .padding(.bottom, 8) } diff --git a/apple/OmnivoreKit/Sources/Views/TextChip.swift b/apple/OmnivoreKit/Sources/Views/TextChip.swift index f318d7902..76b8f30a4 100644 --- a/apple/OmnivoreKit/Sources/Views/TextChip.swift +++ b/apple/OmnivoreKit/Sources/Views/TextChip.swift @@ -26,8 +26,7 @@ public struct TextChip: View { .font(.appFootnote) .foregroundColor(color.isDark ? .white : .black) .lineLimit(1) - .background(color) - .cornerRadius(cornerRadius) + .background(Capsule().fill(color)) } } From d74342950e92c14337a27c2cf905251ae63a2f20 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Thu, 5 May 2022 20:54:52 -0700 Subject: [PATCH 3/3] remove unused corner radius property --- apple/OmnivoreKit/Sources/Views/TextChip.swift | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/apple/OmnivoreKit/Sources/Views/TextChip.swift b/apple/OmnivoreKit/Sources/Views/TextChip.swift index 76b8f30a4..4e0ada9c4 100644 --- a/apple/OmnivoreKit/Sources/Views/TextChip.swift +++ b/apple/OmnivoreKit/Sources/Views/TextChip.swift @@ -17,7 +17,6 @@ public struct TextChip: View { let text: String let color: Color - let cornerRadius = 20.0 public var body: some View { Text(text) @@ -85,7 +84,6 @@ public struct TextChipButton: View { let color: Color let onTap: () -> Void let actionType: ActionType - let cornerRadius = 20.0 let foregroundColor: Color public var body: some View { @@ -101,8 +99,7 @@ public struct TextChipButton: View { .font(.appFootnote) .foregroundColor(foregroundColor) .lineLimit(1) - .background(color) - .cornerRadius(cornerRadius) + .background(Capsule().fill(color)) Color.clear.contentShape(Rectangle()).frame(height: 15) }