diff --git a/Multiplatform/Shared/Sidebar/SidebarItem.swift b/Multiplatform/Shared/Sidebar/SidebarItem.swift index 14a1abdb1..796008552 100644 --- a/Multiplatform/Shared/Sidebar/SidebarItem.swift +++ b/Multiplatform/Shared/Sidebar/SidebarItem.swift @@ -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 diff --git a/Multiplatform/Shared/Sidebar/SidebarItemView.swift b/Multiplatform/Shared/Sidebar/SidebarItemView.swift index 9f977f1fb..a50b63414 100644 --- a/Multiplatform/Shared/Sidebar/SidebarItemView.swift +++ b/Multiplatform/Shared/Sidebar/SidebarItemView.swift @@ -26,81 +26,87 @@ 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 { - Button(action: {}) { - HStack { - Text("Mark All as Read") - Spacer() - Image("markAllAsRead") - .resizable() - .aspectRatio(contentMode: .fit) - } - } - } else if let _ = sidebarItem.represented as? Feed { - Button(action: {}) { - HStack { - Text("Mark All as Read") - Spacer() - Image("markAllAsRead") - .resizable() - .aspectRatio(contentMode: .fit) - } - } - Divider() - Button(action: { - - }) { - HStack { - Text("Open Home Page") - Spacer() - Image(systemName: "safari") - } - } - Divider() - Button(action: {}) { - HStack { - Text("Copy Feed URL") - Spacer() - Image(systemName: "doc.on.doc") - } - } - Button(action: {}) { - HStack { - Text("Copy Home Page URL") - Spacer() - Image(systemName: "doc.on.doc") - } - } - Divider() - Button(action: {}) { - HStack { - Text("Rename") - Spacer() - Image(systemName: "textformat") - } - } - Button(action: {}) { - HStack { - Text("Delete").foregroundColor(.red) - Spacer() - Image(systemName: "trash").foregroundColor(.red) - } - } - } else { - Button(action: {}) { - HStack { - Text("Mark All As Read in \(sidebarItem.nameForDisplay)") - Spacer() - Image("markAllAsRead") - .resizable() - .aspectRatio(contentMode: .fit) - } - } - } + menuItems }) } + + @ViewBuilder var menuItems: some View { + if sidebarItem.representedType == .account { + Button(action: {}) { + HStack { + Text("Mark All As Read in \(sidebarItem.nameForDisplay)") + Spacer() + Image("markAllAsRead") + .resizable() + .aspectRatio(contentMode: .fit) + } + } + } + if sidebarItem.representedType == .feed { + Button(action: {}) { + HStack { + Text("Mark All as Read") + Spacer() + Image("markAllAsRead") + .resizable() + .aspectRatio(contentMode: .fit) + } + } + Divider() + Button(action: { + + }) { + HStack { + Text("Open Home Page") + Spacer() + Image(systemName: "safari") + } + } + Divider() + Button(action: {}) { + HStack { + Text("Copy Feed URL") + Spacer() + Image(systemName: "doc.on.doc") + } + } + Button(action: {}) { + HStack { + Text("Copy Home Page URL") + Spacer() + Image(systemName: "doc.on.doc") + } + } + Divider() + Button(action: {}) { + HStack { + Text("Rename") + Spacer() + Image(systemName: "textformat") + } + } + Button(action: {}) { + HStack { + Text("Delete").foregroundColor(.red) + Spacer() + Image(systemName: "trash").foregroundColor(.red) + } + } + } + if sidebarItem.representedType == .pseudoFeed { + Button(action: {}) { + HStack { + Text("Mark All as Read") + Spacer() + Image("markAllAsRead") + .resizable() + .aspectRatio(contentMode: .fit) + } + } + } + } }