SidebarItem updates

Several computed properties added to `SidebarItem` which `SidebarItemView` makes use of.
This commit is contained in:
Stuart Breckenridge 2020-06-30 12:37:29 +08:00
parent c3e93980d1
commit f222dbd0fa
2 changed files with 101 additions and 72 deletions

View File

@ -16,6 +16,10 @@ public enum SidebarItemIdentifier: Hashable, Equatable {
case feed(FeedIdentifier)
}
public enum RepresentedType {
case feed, pseudoFeed, account, unknown
}
struct SidebarItem: Identifiable {
var id: SidebarItemIdentifier
@ -29,6 +33,25 @@ struct SidebarItem: Identifiable {
return displayNameProvider.nameForDisplay
}
var feed: Feed? {
represented as? Feed
}
var representedType: RepresentedType {
switch type(of: represented) {
case is SmartFeed.Type:
return .pseudoFeed
case is UnreadFeed.Type:
return .pseudoFeed
case is WebFeed.Type:
return .feed
case is Account.Type:
return .account
default:
return .unknown
}
}
init(_ smartFeedsController: SmartFeedsController) {
self.id = .smartFeedController
self.represented = smartFeedsController

View File

@ -26,21 +26,27 @@ struct SidebarItemView: View {
}
}
.onAppear {
if let feed = sidebarItem.represented as? Feed {
if let feed = sidebarItem.feed {
feedImageLoader.loadImage(for: feed)
}
}.contextMenu(menuItems: {
if let _ = sidebarItem.represented as? PseudoFeed {
menuItems
})
}
@ViewBuilder var menuItems: some View {
if sidebarItem.representedType == .account {
Button(action: {}) {
HStack {
Text("Mark All as Read")
Text("Mark All As Read in \(sidebarItem.nameForDisplay)")
Spacer()
Image("markAllAsRead")
.resizable()
.aspectRatio(contentMode: .fit)
}
}
} else if let _ = sidebarItem.represented as? Feed {
}
if sidebarItem.representedType == .feed {
Button(action: {}) {
HStack {
Text("Mark All as Read")
@ -90,10 +96,11 @@ struct SidebarItemView: View {
Image(systemName: "trash").foregroundColor(.red)
}
}
} else {
}
if sidebarItem.representedType == .pseudoFeed {
Button(action: {}) {
HStack {
Text("Mark All As Read in \(sidebarItem.nameForDisplay)")
Text("Mark All as Read")
Spacer()
Image("markAllAsRead")
.resizable()
@ -101,6 +108,5 @@ struct SidebarItemView: View {
}
}
}
})
}
}