NetNewsWire/Multiplatform/Shared/Sidebar/SidebarItemView.swift

65 lines
1.6 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-07-21 10:05:31 +02:00
@EnvironmentObject private var sidebarModel: SidebarModel
@State private var showInspector: Bool = false
2020-06-29 23:58:10 +02:00
var sidebarItem: SidebarItem
var body: some View {
HStack {
#if os(macOS)
HStack {
if let image = feedIconImageLoader.image {
IconImageView(iconImage: image)
.frame(width: 20, height: 20, alignment: .center)
}
Text(verbatim: sidebarItem.nameForDisplay)
Spacer()
if sidebarItem.unreadCount > 0 {
UnreadCountView(count: sidebarItem.unreadCount)
}
}
#else
HStack(alignment: .top) {
if let image = feedIconImageLoader.image {
IconImageView(iconImage: image)
.frame(width: 20, height: 20)
}
Text(verbatim: sidebarItem.nameForDisplay)
2020-06-30 03:09:11 +02:00
}
2020-06-29 23:58:10 +02:00
Spacer()
if sidebarItem.unreadCount > 0 {
UnreadCountView(count: sidebarItem.unreadCount)
}
2020-07-06 02:09:23 +02:00
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
}
}.contextMenu {
SidebarContextMenu(showInspector: $showInspector, sidebarItem: sidebarItem)
2020-07-21 10:05:31 +02:00
.environmentObject(sidebarModel)
}
.sheet(isPresented: $showInspector, onDismiss: { showInspector = false}) {
InspectorView(sidebarItem: sidebarItem)
}
}
2020-06-29 23:58:10 +02:00
}