2020-06-28 14:21:43 -05:00
|
|
|
//
|
|
|
|
// SidebarView.swift
|
|
|
|
// NetNewsWire
|
|
|
|
//
|
2020-06-29 13:14:03 -05:00
|
|
|
// Created by Maurice Parker on 6/29/20.
|
2020-06-28 14:21:43 -05:00
|
|
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
2020-06-30 20:23:22 -05:00
|
|
|
import Account
|
2020-06-28 14:21:43 -05:00
|
|
|
|
|
|
|
struct SidebarView: View {
|
2020-06-28 17:43:20 -05:00
|
|
|
|
2020-06-30 20:38:55 -05:00
|
|
|
// I had to comment out SceneStorage because it blows up if used on macOS
|
2020-07-08 21:39:39 +08:00
|
|
|
// @SceneStorage("expandedContainers") private var expandedContainerData = Data()
|
2020-06-30 20:23:22 -05:00
|
|
|
@StateObject private var expandedContainers = SidebarExpandedContainers()
|
2020-06-29 13:14:03 -05:00
|
|
|
@EnvironmentObject private var sidebarModel: SidebarModel
|
2020-07-11 12:47:13 -05:00
|
|
|
@State var navigate = false
|
|
|
|
|
2020-07-11 18:22:47 -05:00
|
|
|
@ViewBuilder var body: some View {
|
2020-07-08 21:39:39 +08:00
|
|
|
#if os(macOS)
|
2020-07-12 10:52:42 -05:00
|
|
|
VStack {
|
|
|
|
HStack {
|
|
|
|
Spacer()
|
|
|
|
Button (action: {
|
|
|
|
withAnimation {
|
|
|
|
sidebarModel.isReadFiltered.toggle()
|
|
|
|
}
|
|
|
|
}, label: {
|
|
|
|
if sidebarModel.isReadFiltered {
|
|
|
|
AppAssets.filterActiveImage
|
|
|
|
} else {
|
|
|
|
AppAssets.filterInactiveImage
|
|
|
|
}
|
|
|
|
})
|
2020-07-12 14:43:52 -05:00
|
|
|
.padding(.top, 8).padding(.trailing)
|
2020-07-12 10:52:42 -05:00
|
|
|
.buttonStyle(PlainButtonStyle())
|
2020-07-12 15:03:43 -05:00
|
|
|
.help(sidebarModel.isReadFiltered ? "Show Read Feeds" : "Filter Read Feeds")
|
2020-07-12 10:52:42 -05:00
|
|
|
}
|
|
|
|
ZStack {
|
|
|
|
NavigationLink(destination: TimelineContainerView(feeds: sidebarModel.selectedFeeds), isActive: $navigate) {
|
|
|
|
EmptyView()
|
|
|
|
}.hidden()
|
|
|
|
List(selection: $sidebarModel.selectedFeedIdentifiers) {
|
|
|
|
rows
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.onChange(of: sidebarModel.selectedFeedIdentifiers) { value in
|
|
|
|
navigate = !sidebarModel.selectedFeedIdentifiers.isEmpty
|
2020-07-11 12:47:13 -05:00
|
|
|
}
|
2020-07-08 21:39:39 +08:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
List {
|
2020-07-11 12:47:13 -05:00
|
|
|
rows
|
2020-07-08 21:39:39 +08:00
|
|
|
}
|
2020-07-12 17:45:38 -05:00
|
|
|
.navigationTitle(Text("Feeds"))
|
2020-07-08 21:39:39 +08:00
|
|
|
#endif
|
2020-07-11 12:47:13 -05:00
|
|
|
// .onAppear {
|
|
|
|
// expandedContainers.data = expandedContainerData
|
|
|
|
// }
|
|
|
|
// .onReceive(expandedContainers.objectDidChange) {
|
|
|
|
// expandedContainerData = expandedContainers.data
|
|
|
|
// }
|
2020-07-08 21:39:39 +08:00
|
|
|
}
|
|
|
|
|
2020-07-11 12:47:13 -05:00
|
|
|
var rows: some View {
|
2020-07-08 21:39:39 +08:00
|
|
|
ForEach(sidebarModel.sidebarItems) { sidebarItem in
|
|
|
|
if let containerID = sidebarItem.containerID {
|
|
|
|
DisclosureGroup(isExpanded: $expandedContainers[containerID]) {
|
|
|
|
ForEach(sidebarItem.children) { sidebarItem in
|
|
|
|
if let containerID = sidebarItem.containerID {
|
|
|
|
DisclosureGroup(isExpanded: $expandedContainers[containerID]) {
|
|
|
|
ForEach(sidebarItem.children) { sidebarItem in
|
2020-07-11 12:47:13 -05:00
|
|
|
buildSidebarItemNavigation(sidebarItem)
|
2020-06-30 20:23:22 -05:00
|
|
|
}
|
2020-07-08 21:39:39 +08:00
|
|
|
} label: {
|
2020-07-11 12:47:13 -05:00
|
|
|
buildSidebarItemNavigation(sidebarItem)
|
2020-06-30 20:23:22 -05:00
|
|
|
}
|
2020-07-08 21:39:39 +08:00
|
|
|
} else {
|
2020-07-11 12:47:13 -05:00
|
|
|
buildSidebarItemNavigation(sidebarItem)
|
2020-06-30 20:23:22 -05:00
|
|
|
}
|
|
|
|
}
|
2020-07-08 21:39:39 +08:00
|
|
|
} label: {
|
2020-07-13 12:00:59 -05:00
|
|
|
#if os(macOS)
|
2020-07-13 11:58:44 -05:00
|
|
|
SidebarItemView(sidebarItem: sidebarItem).padding(.leading, 4)
|
2020-07-13 12:00:59 -05:00
|
|
|
#else
|
|
|
|
SidebarItemView(sidebarItem: sidebarItem)
|
|
|
|
#endif
|
2020-06-30 20:23:22 -05:00
|
|
|
}
|
2020-06-28 17:43:20 -05:00
|
|
|
}
|
2020-06-29 06:16:48 -05:00
|
|
|
}
|
2020-06-28 17:43:20 -05:00
|
|
|
}
|
2020-07-08 21:39:39 +08:00
|
|
|
|
2020-07-11 12:47:13 -05:00
|
|
|
func buildSidebarItemNavigation(_ sidebarItem: SidebarItem) -> some View {
|
|
|
|
#if os(macOS)
|
|
|
|
return SidebarItemView(sidebarItem: sidebarItem).tag(sidebarItem.feed!.feedID!)
|
|
|
|
#else
|
|
|
|
return ZStack {
|
|
|
|
SidebarItemView(sidebarItem: sidebarItem)
|
|
|
|
NavigationLink(destination: TimelineContainerView(feeds: sidebarModel.selectedFeeds),
|
|
|
|
tag: sidebarItem.feed!.feedID!,
|
|
|
|
selection: $sidebarModel.selectedFeedIdentifier) {
|
|
|
|
EmptyView()
|
|
|
|
}.buttonStyle(PlainButtonStyle())
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-06-28 14:21:43 -05:00
|
|
|
}
|