NetNewsWire/Multiplatform/Shared/Sidebar/SidebarItemView.swift

114 lines
2.3 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-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 {
Button(action: {}) {
HStack {
Text("Mark All As Read in \(sidebarItem.nameForDisplay)")
Spacer()
Image("markAllAsRead")
.resizable()
.aspectRatio(contentMode: .fit)
2020-06-30 04:31:50 +02:00
}
}
}
if sidebarItem.representedType == .feed {
Button(action: {}) {
HStack {
Text("Mark All as Read")
Spacer()
Image("markAllAsRead")
.resizable()
.aspectRatio(contentMode: .fit)
2020-06-30 04:31:50 +02:00
}
}
Divider()
Button(action: {
}) {
HStack {
Text("Open Home Page")
Spacer()
Image(systemName: "safari")
2020-06-30 04:31:50 +02:00
}
}
Divider()
Button(action: {}) {
HStack {
Text("Copy Feed URL")
Spacer()
Image(systemName: "doc.on.doc")
2020-06-30 04:31:50 +02:00
}
}
Button(action: {}) {
HStack {
Text("Copy Home Page URL")
Spacer()
Image(systemName: "doc.on.doc")
2020-06-30 04:31:50 +02:00
}
}
Divider()
Button(action: {}) {
HStack {
Text("Rename")
Spacer()
Image(systemName: "textformat")
2020-06-30 04:31:50 +02:00
}
}
Button(action: {}) {
HStack {
Text("Delete").foregroundColor(.red)
Spacer()
Image(systemName: "trash").foregroundColor(.red)
2020-06-30 04:31:50 +02:00
}
}
}
if sidebarItem.representedType == .pseudoFeed {
Button(action: {}) {
HStack {
Text("Mark All as Read")
Spacer()
Image("markAllAsRead")
.resizable()
.aspectRatio(contentMode: .fit)
2020-06-30 04:31:50 +02:00
}
}
}
}
2020-06-29 23:58:10 +02:00
}