NetNewsWire/Multiplatform/Shared/Sidebar/SidebarItemView.swift

140 lines
2.7 KiB
Swift
Raw Normal View History

2020-06-29 23:58:10 +02:00
//
// SidebarItemView.swift
// NetNewsWire
//
// Created by Maurice Parker on 6/29/20.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import SwiftUI
2020-06-30 03:09:11 +02:00
import Account
2020-06-29 23:58:10 +02:00
struct SidebarItemView: View {
2020-07-01 23:37:20 +02:00
@StateObject var feedIconImageLoader = FeedIconImageLoader()
2020-06-29 23:58:10 +02:00
var sidebarItem: SidebarItem
var body: some View {
HStack {
2020-07-01 23:37:20 +02:00
if let image = feedIconImageLoader.image {
2020-06-30 03:09:11 +02:00
IconImageView(iconImage: image)
2020-07-02 00:21:58 +02:00
.frame(width: 20, height: 20, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
2020-06-30 03:09:11 +02:00
}
2020-06-29 23:58:10 +02:00
Text(verbatim: sidebarItem.nameForDisplay)
Spacer()
if sidebarItem.unreadCount > 0 {
UnreadCountView(count: sidebarItem.unreadCount)
}
2020-07-06 02:09:23 +02:00
#if os(iOS)
if sidebarItem.representedType == .webFeed || sidebarItem.representedType == .pseudoFeed {
Spacer()
.frame(width: 16)
}
#endif
2020-06-29 23:58:10 +02:00
}
2020-06-30 03:09:11 +02:00
.onAppear {
if let feed = sidebarItem.feed {
2020-07-01 23:37:20 +02:00
feedIconImageLoader.loadImage(for: feed)
2020-06-30 03:09:11 +02:00
}
2020-06-30 04:31:50 +02:00
}.contextMenu(menuItems: {
menuItems
})
}
@ViewBuilder var menuItems: some View {
if sidebarItem.representedType == .account {
2020-07-04 21:13:12 +02:00
Button(action: {}) {
Text("Get Info")
#if os(iOS)
2020-07-04 21:13:12 +02:00
AppAssets.getInfoImage
#endif
2020-07-04 21:13:12 +02:00
}
Button(action: {}) {
2020-07-04 19:16:21 +02:00
Text("Mark All As Read")
#if os(iOS)
2020-07-04 19:16:21 +02:00
AppAssets.markAllAsReadImage
#endif
}
}
2020-07-04 19:16:21 +02:00
if sidebarItem.representedType == .pseudoFeed {
Button(action: {}) {
2020-07-04 19:16:21 +02:00
Text("Mark All As Read")
#if os(iOS)
2020-07-04 19:16:21 +02:00
AppAssets.markAllAsReadImage
#endif
2020-07-04 19:16:21 +02:00
}
}
if sidebarItem.representedType == .webFeed {
2020-07-04 21:13:12 +02:00
Button(action: {}) {
Text("Get Info")
#if os(iOS)
2020-07-04 21:13:12 +02:00
AppAssets.getInfoImage
#endif
2020-07-04 21:13:12 +02:00
}
2020-07-04 19:16:21 +02:00
Button(action: {}) {
Text("Mark All As Read")
#if os(iOS)
2020-07-04 19:16:21 +02:00
AppAssets.markAllAsReadImage
#endif
}
Divider()
2020-07-04 21:13:12 +02:00
Button(action: {}) {
2020-07-04 19:16:21 +02:00
Text("Open Home Page")
#if os(iOS)
2020-07-04 19:16:21 +02:00
AppAssets.openInBrowserImage
#endif
}
Divider()
Button(action: {}) {
2020-07-04 19:16:21 +02:00
Text("Copy Feed URL")
#if os(iOS)
2020-07-04 19:16:21 +02:00
AppAssets.copyImage
#endif
}
Button(action: {}) {
2020-07-04 19:16:21 +02:00
Text("Copy Home Page URL")
#if os(iOS)
2020-07-04 19:16:21 +02:00
AppAssets.copyImage
#endif
}
Divider()
Button(action: {}) {
2020-07-04 19:16:21 +02:00
Text("Rename")
#if os(iOS)
2020-07-04 19:16:21 +02:00
AppAssets.renameImage
#endif
}
Button(action: {}) {
2020-07-04 19:16:21 +02:00
Text("Delete")
#if os(iOS)
2020-07-04 19:16:21 +02:00
AppAssets.deleteImage
#endif
}
}
2020-07-04 19:16:21 +02:00
if sidebarItem.representedType == .folder {
Button(action: {}) {
Text("Mark All As Read")
#if os(iOS)
2020-07-04 19:16:21 +02:00
AppAssets.markAllAsReadImage
#endif
2020-07-04 19:16:21 +02:00
}
Divider()
Button(action: {}) {
Text("Rename")
#if os(iOS)
2020-07-04 19:16:21 +02:00
AppAssets.renameImage
#endif
2020-07-04 19:16:21 +02:00
}
Button(action: {}) {
2020-07-04 19:16:21 +02:00
Text("Delete")
#if os(iOS)
2020-07-04 19:16:21 +02:00
AppAssets.deleteImage
#endif
2020-06-30 04:31:50 +02:00
}
}
}
2020-06-29 23:58:10 +02:00
}