Merge pull request #560 from omnivore-app/fix/card-label-display-issues

This commit is contained in:
Satindar Dhillon 2022-05-06 07:51:27 -07:00 committed by GitHub
commit b3d699e679
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 10 deletions

View file

@ -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)

View file

@ -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
[

View file

@ -151,12 +151,11 @@ 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()
}
.frame(height: 30)
.padding(.horizontal)
.padding(.bottom, 8)
}

View file

@ -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()

View file

@ -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)
@ -26,8 +25,7 @@ public struct TextChip: View {
.font(.appFootnote)
.foregroundColor(color.isDark ? .white : .black)
.lineLimit(1)
.background(color)
.cornerRadius(cornerRadius)
.background(Capsule().fill(color))
}
}
@ -86,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 {
@ -102,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)
}