From c4644ce0e716b2d81cc76677dc1e917863286cc1 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Fri, 3 May 2024 09:21:02 +0800 Subject: [PATCH] Clean up metadata in list cards --- .../Views/FeedItem/LibraryItemCard.swift | 95 ++++++++++++------- 1 file changed, 63 insertions(+), 32 deletions(-) diff --git a/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift b/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift index d301f13d6..d05d3af68 100644 --- a/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift +++ b/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift @@ -55,7 +55,7 @@ func savedDateString(_ savedAt: Date?) -> String { dateFormatter.dateFormat = "MMM dd" } dateFormatter.locale = locale - return dateFormatter.string(from: savedAt) + " • " + return dateFormatter.string(from: savedAt) } return "" } @@ -160,12 +160,19 @@ public struct LibraryItemCard: View { var estimatedReadingTime: String { if item.wordsCount > 0 { let readLen = max(1, item.wordsCount / readingSpeed) - return "\(readLen) MIN READ • " + return "\(readLen) MIN READ" } return "" } var readingProgress: String { + if item.readingProgress < 2 { + return "" + } + var readingProgress = item.readingProgress + if readingProgress > 95 { + readingProgress = 100 + } // If there is no wordsCount don't show progress because it will make no sense if item.wordsCount > 0 { return "\(String(format: "%d", Int(item.readingProgress)))%" @@ -181,18 +188,15 @@ public struct LibraryItemCard: View { item.wordsCount > 0 || item.highlights?.first { ($0 as? Highlight)?.annotation != nil } != nil } - var highlightsText: String { + var highlightsStr: String { if let highlights = item.highlights, highlights.count > 0 { let fmted = LocalText.pluralizedText(key: "number_of_highlights", count: highlights.count) - if item.wordsCount > 0 || item.isPDF { - return " • \(fmted)" - } return fmted } return "" } - var notesText: String { + var notesStr: String { let notes = item.highlights?.filter { item in if let highlight = item as? Highlight { return !(highlight.annotation ?? "").isEmpty @@ -202,9 +206,6 @@ public struct LibraryItemCard: View { if let notes = notes, notes.count > 0 { let fmted = LocalText.pluralizedText(key: "number_of_notes", count: notes.count) - if hasMultipleInfoItems { - return " • \(fmted)" - } return fmted } return "" @@ -228,35 +229,65 @@ public struct LibraryItemCard: View { } } + var savedAtText: Text? { + if !savedAtStr.isEmpty { + return Text(savedAtStr) + .font(.footnote) + .foregroundColor(Color.themeLibraryItemSubtle) + } + return nil + } + + var estimatedReadingTimeText: Text? { + if !estimatedReadingTime.isEmpty { + return Text("\(estimatedReadingTime)") + .font(.footnote) + .foregroundColor(Color.themeLibraryItemSubtle) + + } + return nil + } + + var readingProgressText: Text? { + if !readingProgress.isEmpty { + return Text("\(readingProgress)") + .font(.footnote) + .foregroundColor(isPartiallyRead ? Color.appGreenSuccess : Color.themeLibraryItemSubtle) + } + return nil + } + + var highlightsText: Text? { + if !highlightsStr.isEmpty { + return Text("\(highlightsStr)") + .font(.footnote) + .foregroundColor(Color.themeLibraryItemSubtle) + } + return nil + } + + var notesText: Text? { + if !notesStr.isEmpty { + return Text("\(notesStr)") + .font(.footnote) + .foregroundColor(Color.themeLibraryItemSubtle) + } + return nil + } + var readInfo: some View { HStack(alignment: .center, spacing: 5.0) { ForEach(flairLabels, id: \.self) { $0.icon } - Text(savedAtStr) - .font(.footnote) - .foregroundColor(Color.themeLibraryItemSubtle) + let texts = [savedAtText, estimatedReadingTimeText, readingProgressText, highlightsText, notesText] + .compactMap { $0 } - + - Text("\(estimatedReadingTime)") - .font(.footnote) - .foregroundColor(Color.themeLibraryItemSubtle) - - + - Text("\(readingProgress)") - .font(.footnote) - .foregroundColor(isPartiallyRead ? Color.appGreenSuccess : Color.themeLibraryItemSubtle) - - + - Text("\(highlightsText)") - .font(.footnote) - .foregroundColor(Color.themeLibraryItemSubtle) - - + - Text("\(notesText)") - .font(.footnote) - .foregroundColor(Color.themeLibraryItemSubtle) + texts.dropLast().reduce(Text("")) { result, text in + result + text + Text(" • ").font(.footnote).foregroundColor(Color.themeLibraryItemSubtle) + } + texts.last! + // .reduce(Text(""), +) } .frame(maxWidth: .infinity, alignment: .leading) }