This commit is contained in:
Maurice Parker 2020-07-08 20:13:08 -05:00
commit 5abf222c8a
3 changed files with 81 additions and 40 deletions

View File

@ -20,6 +20,30 @@ class SidebarModel: ObservableObject {
@Published var sidebarItems = [SidebarItem]() @Published var sidebarItems = [SidebarItem]()
#if os(macOS)
@Published var selectedSidebarItems = Set<FeedIdentifier>() {
didSet {
print(selectedSidebarItems)
}
}
#endif
private var items = Set<FeedIdentifier>()
@Published var selectedSidebarItem: FeedIdentifier? = .none {
willSet {
#if os(macOS)
if newValue != nil {
items.insert(newValue!)
} else {
selectedSidebarItems = items
items.removeAll()
}
#endif
}
}
init() { init() {
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidInitialize(_:)), name: .UnreadCountDidInitialize, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidInitialize(_:)), name: .UnreadCountDidInitialize, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(containerChildrenDidChange(_:)), name: .ChildrenDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(containerChildrenDidChange(_:)), name: .ChildrenDidChange, object: nil)
@ -62,7 +86,6 @@ class SidebarModel: ObservableObject {
sidebarItems = items sidebarItems = items
} }
} }
// MARK: Private // MARK: Private

View File

@ -16,8 +16,26 @@ struct SidebarView: View {
@StateObject private var expandedContainers = SidebarExpandedContainers() @StateObject private var expandedContainers = SidebarExpandedContainers()
@EnvironmentObject private var sidebarModel: SidebarModel @EnvironmentObject private var sidebarModel: SidebarModel
@ViewBuilder
var body: some View { var body: some View {
List() { #if os(macOS)
List(selection: $sidebarModel.selectedSidebarItems) {
containedList
}
#else
List {
containedList
}
#endif
// .onAppear {
// expandedContainers.data = expandedContainerData
// }
// .onReceive(expandedContainers.objectDidChange) {
// expandedContainerData = expandedContainers.data
// }
}
var containedList: some View {
ForEach(sidebarModel.sidebarItems) { sidebarItem in ForEach(sidebarModel.sidebarItems) { sidebarItem in
if let containerID = sidebarItem.containerID { if let containerID = sidebarItem.containerID {
DisclosureGroup(isExpanded: $expandedContainers[containerID]) { DisclosureGroup(isExpanded: $expandedContainers[containerID]) {
@ -27,7 +45,9 @@ struct SidebarView: View {
ForEach(sidebarItem.children) { sidebarItem in ForEach(sidebarItem.children) { sidebarItem in
ZStack { ZStack {
SidebarItemView(sidebarItem: sidebarItem) SidebarItemView(sidebarItem: sidebarItem)
NavigationLink(destination: (TimelineContainerView(feed: sidebarItem.feed))) { NavigationLink(destination: (TimelineContainerView(feed: sidebarItem.feed)),
tag: sidebarItem.feed!.feedID!,
selection: $sidebarModel.selectedSidebarItem) {
EmptyView() EmptyView()
}.buttonStyle(PlainButtonStyle()) }.buttonStyle(PlainButtonStyle())
} }
@ -35,7 +55,9 @@ struct SidebarView: View {
} label: { } label: {
ZStack { ZStack {
SidebarItemView(sidebarItem: sidebarItem) SidebarItemView(sidebarItem: sidebarItem)
NavigationLink(destination: (TimelineContainerView(feed: sidebarItem.feed))) { NavigationLink(destination: (TimelineContainerView(feed: sidebarItem.feed)),
tag: sidebarItem.feed!.feedID!,
selection: $sidebarModel.selectedSidebarItem) {
EmptyView() EmptyView()
}.buttonStyle(PlainButtonStyle()) }.buttonStyle(PlainButtonStyle())
} }
@ -43,7 +65,9 @@ struct SidebarView: View {
} else { } else {
ZStack { ZStack {
SidebarItemView(sidebarItem: sidebarItem) SidebarItemView(sidebarItem: sidebarItem)
NavigationLink(destination: (TimelineContainerView(feed: sidebarItem.feed))) { NavigationLink(destination: (TimelineContainerView(feed: sidebarItem.feed)),
tag: sidebarItem.feed!.feedID!,
selection: $sidebarModel.selectedSidebarItem) {
EmptyView() EmptyView()
}.buttonStyle(PlainButtonStyle()) }.buttonStyle(PlainButtonStyle())
} }
@ -55,11 +79,5 @@ struct SidebarView: View {
} }
} }
} }
// .onAppear {
// expandedContainers.data = expandedContainerData
// }
// .onReceive(expandedContainers.objectDidChange) {
// expandedContainerData = expandedContainers.data
// }
}
} }

View File

@ -4135,46 +4135,46 @@
TargetAttributes = { TargetAttributes = {
51314636235A7BBE00387FDC = { 51314636235A7BBE00387FDC = {
CreatedOnToolsVersion = 11.2; CreatedOnToolsVersion = 11.2;
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
LastSwiftMigration = 1120; LastSwiftMigration = 1120;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
}; };
513C5CE5232571C2003D4054 = { 513C5CE5232571C2003D4054 = {
CreatedOnToolsVersion = 11.0; CreatedOnToolsVersion = 11.0;
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
}; };
518B2ED12351B3DD00400001 = { 518B2ED12351B3DD00400001 = {
CreatedOnToolsVersion = 11.2; CreatedOnToolsVersion = 11.2;
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
TestTargetID = 840D617B2029031C009BC708; TestTargetID = 840D617B2029031C009BC708;
}; };
51C0513C24A77DF800194D5E = { 51C0513C24A77DF800194D5E = {
CreatedOnToolsVersion = 12.0; CreatedOnToolsVersion = 12.0;
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
}; };
51C0514324A77DF800194D5E = { 51C0514324A77DF800194D5E = {
CreatedOnToolsVersion = 12.0; CreatedOnToolsVersion = 12.0;
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
}; };
6581C73220CED60000F4AD34 = { 6581C73220CED60000F4AD34 = {
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
}; };
65ED3FA2235DEF6C0081F399 = { 65ED3FA2235DEF6C0081F399 = {
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
}; };
65ED4090235DEF770081F399 = { 65ED4090235DEF770081F399 = {
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
}; };
840D617B2029031C009BC708 = { 840D617B2029031C009BC708 = {
CreatedOnToolsVersion = 9.3; CreatedOnToolsVersion = 9.3;
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
SystemCapabilities = { SystemCapabilities = {
com.apple.BackgroundModes = { com.apple.BackgroundModes = {
@ -4184,7 +4184,7 @@
}; };
849C645F1ED37A5D003D8FC0 = { 849C645F1ED37A5D003D8FC0 = {
CreatedOnToolsVersion = 8.2.1; CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
SystemCapabilities = { SystemCapabilities = {
com.apple.HardenedRuntime = { com.apple.HardenedRuntime = {
@ -4194,7 +4194,7 @@
}; };
849C64701ED37A5D003D8FC0 = { 849C64701ED37A5D003D8FC0 = {
CreatedOnToolsVersion = 8.2.1; CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = SHJK2V3AJG; DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic; ProvisioningStyle = Automatic;
TestTargetID = 849C645F1ED37A5D003D8FC0; TestTargetID = 849C645F1ED37A5D003D8FC0;
}; };