Merge pull request #2349 from omnivore-app/fix/ios-pinned-items

Remember feature filter, dont display features during search
This commit is contained in:
Jackson Harper
2023-06-13 21:30:19 +08:00
committed by GitHub
6 changed files with 29 additions and 31 deletions

File diff suppressed because one or more lines are too long

View File

@ -398,7 +398,7 @@ struct AnimatingCellHeight: AnimatableModifier {
})
}, label: {
HStack(alignment: .center) {
Text(viewModel.featureFilter.title.uppercased())
Text((FeaturedItemFilter(rawValue: viewModel.featureFilter) ?? .continueReading).title.uppercased())
.font(Font.system(size: 14, weight: .regular))
Image(systemName: "chevron.down")
}.frame(maxWidth: .infinity, alignment: .leading)
@ -410,17 +410,13 @@ struct AnimatingCellHeight: AnimatableModifier {
ScrollView(.horizontal, showsIndicators: false) {
if viewModel.featureItems.count > 0 {
LazyHStack(alignment: .top, spacing: 20) {
LazyHStack(alignment: .top, spacing: 10) {
ForEach(viewModel.featureItems) { item in
LibraryFeatureCardNavigationLink(item: item, viewModel: viewModel)
.background(
RoundedRectangle(cornerRadius: 12) // << tune as needed
.fill(Color(UIColor.systemBackground)) // << fill with system color
)
}
}
} else {
Text(viewModel.featureFilter.emptyMessage)
Text((FeaturedItemFilter(rawValue: viewModel.featureFilter) ?? .continueReading).emptyMessage)
.font(Font.system(size: 14, weight: .regular))
.foregroundColor(Color(hex: "#898989"))
.frame(maxWidth: geo.size.width)
@ -432,7 +428,6 @@ struct AnimatingCellHeight: AnimatableModifier {
Text((LinkedItemFilter(rawValue: viewModel.appliedFilter)?.displayName ?? "Inbox").uppercased())
.font(Font.system(size: 14, weight: .regular))
.padding(.bottom, 5)
}
}
@ -455,8 +450,7 @@ struct AnimatingCellHeight: AnimatableModifier {
filtersHeader
.listRowInsets(.init(top: 0, leading: 10, bottom: 10, trailing: 10))
// Only show the feature card section if we have items loaded
if !viewModel.hideFeatureSection, viewModel.items.count > 0 {
if !viewModel.hideFeatureSection, viewModel.items.count > 0, viewModel.searchTerm.isEmpty, viewModel.selectedLabels.isEmpty, viewModel.negatedLabels.isEmpty {
featureCard
.listRowInsets(.init(top: 0, leading: 10, bottom: 10, trailing: 10))
.modifier(AnimatingCellHeight(height: viewModel.featureItems.count > 0 ? 260 : 130))

View File

@ -32,8 +32,6 @@ import Views
@Published var showLabelsSheet = false
@Published var showCommunityModal = false
@Published var featureFilter = FeaturedItemFilter.continueReading
@Published var featureItems = [LinkedItem]()
var cursor: String?
@ -47,20 +45,25 @@ import Views
@AppStorage(UserDefaultKey.hideFeatureSection.rawValue) var hideFeatureSection = false
@AppStorage(UserDefaultKey.lastSelectedLinkedItemFilter.rawValue) var appliedFilter = LinkedItemFilter.inbox.rawValue
@AppStorage(UserDefaultKey.lastSelectedFeaturedItemFilter.rawValue) var featureFilter = FeaturedItemFilter.continueReading.rawValue
func setItems(_ items: [LinkedItem]) {
self.items = items
updateFeatureFilter(featureFilter)
updateFeatureFilter(FeaturedItemFilter(rawValue: featureFilter))
}
func updateFeatureFilter(_ filter: FeaturedItemFilter) {
// now try to update the continue reading items:
featureItems = (items.filter { item in
filter.predicate.evaluate(with: item)
} as NSArray)
.sortedArray(using: [filter.sortDescriptor])
.compactMap { $0 as? LinkedItem }
featureFilter = filter
func updateFeatureFilter(_ filter: FeaturedItemFilter?) {
if let filter = filter {
// now try to update the continue reading items:
featureItems = (items.filter { item in
filter.predicate.evaluate(with: item)
} as NSArray)
.sortedArray(using: [filter.sortDescriptor])
.compactMap { $0 as? LinkedItem }
featureFilter = filter.rawValue
} else {
featureItems = []
}
}
func handleReaderItemNotification(objectID: NSManagedObjectID, dataService: DataService) {

View File

@ -12,6 +12,7 @@ public enum UserDefaultKey: String {
case firebasePushToken
case homeFeedlayoutPreference
case lastSelectedLinkedItemFilter
case lastSelectedFeaturedItemFilter
case lastUsedAppVersion
case lastUsedAppBuildNumber
case lastItemSyncTime

View File

@ -76,19 +76,19 @@ public struct LibraryFeatureCard: View {
switch phase {
case .empty:
Color.systemBackground
.frame(width: 150, height: 90)
.cornerRadius(8)
.frame(width: 146, height: 90)
.cornerRadius(5)
case let .success(image):
image.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 150, height: 90)
.cornerRadius(8)
.frame(width: 146, height: 90)
.cornerRadius(5)
case .failure:
Image(systemName: "photo")
.frame(width: 150, height: 90)
.frame(width: 146, height: 90)
.foregroundColor(Color(hex: "#6A6968"))
.background(Color(hex: "#EBEBEB"))
.cornerRadius(8)
.cornerRadius(5)
@unknown default:
// Since the AsyncImagePhase enum isn't frozen,
// we need to add this currently unused fallback
@ -99,10 +99,10 @@ public struct LibraryFeatureCard: View {
}
} else {
Image(systemName: "photo")
.frame(width: 150, height: 90)
.frame(width: 146, height: 90)
.foregroundColor(Color(hex: "#6A6968"))
.background(Color(hex: "#EBEBEB"))
.cornerRadius(8)
.cornerRadius(5)
}
}
}

File diff suppressed because one or more lines are too long