From e593f674297c9ac2c9c59b49217f23789c7d9e17 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Tue, 30 Jun 2020 11:03:33 -0500 Subject: [PATCH 1/3] Stub out Timeline code --- Multiplatform/Shared/SceneModel.swift | 10 +++ .../Sidebar/CompactSidebarContainerView.swift | 2 +- .../Sidebar/RegularSidebarContainerView.swift | 2 +- .../Timeline/TimelineContainerView.swift | 34 +++++++++ .../Shared/Timeline/TimelineItem.swift | 17 +++++ .../Shared/Timeline/TimelineModel.swift | 38 ++++++++++ .../Shared/Timeline/TimelineView.swift | 21 ++++++ NetNewsWire.xcodeproj/project.pbxproj | 72 +++++++++++++------ 8 files changed, 174 insertions(+), 22 deletions(-) create mode 100644 Multiplatform/Shared/Timeline/TimelineContainerView.swift create mode 100644 Multiplatform/Shared/Timeline/TimelineItem.swift create mode 100644 Multiplatform/Shared/Timeline/TimelineModel.swift create mode 100644 Multiplatform/Shared/Timeline/TimelineView.swift diff --git a/Multiplatform/Shared/SceneModel.swift b/Multiplatform/Shared/SceneModel.swift index 1aeec3a43..033b56148 100644 --- a/Multiplatform/Shared/SceneModel.swift +++ b/Multiplatform/Shared/SceneModel.swift @@ -12,6 +12,7 @@ import Account final class SceneModel: ObservableObject { var sidebarModel: SidebarModel? + var timelineModel: TimelineModel? } @@ -29,3 +30,12 @@ extension SceneModel: SidebarModelDelegate { } } + +// MARK: TimelineModelDelegate + +extension SceneModel: TimelineModelDelegate { + + func timelineRequestedWebFeedSelection(_: TimelineModel, webFeed: WebFeed) { + } + +} diff --git a/Multiplatform/Shared/Sidebar/CompactSidebarContainerView.swift b/Multiplatform/Shared/Sidebar/CompactSidebarContainerView.swift index be76f6a48..23d986b46 100644 --- a/Multiplatform/Shared/Sidebar/CompactSidebarContainerView.swift +++ b/Multiplatform/Shared/Sidebar/CompactSidebarContainerView.swift @@ -1,5 +1,5 @@ // -// CompactNavigationView.swift +// CompactSidebarContainerView.swift // Multiplatform iOS // // Created by Stuart Breckenridge on 29/6/20. diff --git a/Multiplatform/Shared/Sidebar/RegularSidebarContainerView.swift b/Multiplatform/Shared/Sidebar/RegularSidebarContainerView.swift index af95dff28..f2440a746 100644 --- a/Multiplatform/Shared/Sidebar/RegularSidebarContainerView.swift +++ b/Multiplatform/Shared/Sidebar/RegularSidebarContainerView.swift @@ -1,5 +1,5 @@ // -// SidebarView.swift +// RegularSidebarContainerView.swift // NetNewsWire // // Created by Maurice Parker on 6/28/20. diff --git a/Multiplatform/Shared/Timeline/TimelineContainerView.swift b/Multiplatform/Shared/Timeline/TimelineContainerView.swift new file mode 100644 index 000000000..09e75ad7a --- /dev/null +++ b/Multiplatform/Shared/Timeline/TimelineContainerView.swift @@ -0,0 +1,34 @@ +// +// TimelineContainerView.swift +// NetNewsWire +// +// Created by Maurice Parker on 6/30/20. +// Copyright © 2020 Ranchero Software. All rights reserved. +// + +import SwiftUI + +struct TimelineContainerView: View { + + @EnvironmentObject private var sceneModel: SceneModel + @StateObject private var timelineModel = TimelineModel() + + @ViewBuilder var body: some View { + TimelineView() + .environmentObject(timelineModel) + .listStyle(SidebarListStyle()) + .onAppear { + sceneModel.timelineModel = timelineModel + timelineModel.delegate = sceneModel + timelineModel.rebuildTimelineItems() + } + } + +} + +struct TimelineContainerView_Previews: PreviewProvider { + static var previews: some View { + TimelineContainerView() + .environmentObject(SceneModel()) + } +} diff --git a/Multiplatform/Shared/Timeline/TimelineItem.swift b/Multiplatform/Shared/Timeline/TimelineItem.swift new file mode 100644 index 000000000..eb82c20de --- /dev/null +++ b/Multiplatform/Shared/Timeline/TimelineItem.swift @@ -0,0 +1,17 @@ +// +// TimelineItem.swift +// NetNewsWire +// +// Created by Maurice Parker on 6/30/20. +// Copyright © 2020 Ranchero Software. All rights reserved. +// + +import SwiftUI +import Articles + +struct TimelineItem: Identifiable { + + var id: String + + +} diff --git a/Multiplatform/Shared/Timeline/TimelineModel.swift b/Multiplatform/Shared/Timeline/TimelineModel.swift new file mode 100644 index 000000000..0f98ebb4b --- /dev/null +++ b/Multiplatform/Shared/Timeline/TimelineModel.swift @@ -0,0 +1,38 @@ +// +// TimelineModel.swift +// NetNewsWire +// +// Created by Maurice Parker on 6/30/20. +// Copyright © 2020 Ranchero Software. All rights reserved. +// + +import Foundation +import RSCore +import Account + +protocol TimelineModelDelegate: class { + func timelineRequestedWebFeedSelection(_: TimelineModel, webFeed: WebFeed) +} + +class TimelineModel: ObservableObject { + + weak var delegate: TimelineModelDelegate? + + @Published var timelineItems = [TimelineItem]() + + init() { + } + + // MARK: API + + func rebuildTimelineItems() { + + } + +} + +// MARK: Private +private extension TimelineModel { + + +} diff --git a/Multiplatform/Shared/Timeline/TimelineView.swift b/Multiplatform/Shared/Timeline/TimelineView.swift new file mode 100644 index 000000000..486d4f6c5 --- /dev/null +++ b/Multiplatform/Shared/Timeline/TimelineView.swift @@ -0,0 +1,21 @@ +// +// TimelineView.swift +// NetNewsWire +// +// Created by Maurice Parker on 6/30/20. +// Copyright © 2020 Ranchero Software. All rights reserved. +// + +import SwiftUI + +struct TimelineView: View { + var body: some View { + Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + } +} + +struct TimelineView_Previews: PreviewProvider { + static var previews: some View { + TimelineView() + } +} diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index 8d476b95b..2852381f1 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -220,6 +220,14 @@ 51919FB424AAB97900541E64 /* FeedImageLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51919FB224AAB97900541E64 /* FeedImageLoader.swift */; }; 51919FB624AABCA100541E64 /* IconImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51919FB524AABCA100541E64 /* IconImageView.swift */; }; 51919FB724AABCA100541E64 /* IconImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51919FB524AABCA100541E64 /* IconImageView.swift */; }; + 51919FEE24AB85E400541E64 /* TimelineContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51919FED24AB85E400541E64 /* TimelineContainerView.swift */; }; + 51919FEF24AB85E400541E64 /* TimelineContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51919FED24AB85E400541E64 /* TimelineContainerView.swift */; }; + 51919FF124AB864A00541E64 /* TimelineModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51919FF024AB864A00541E64 /* TimelineModel.swift */; }; + 51919FF224AB864A00541E64 /* TimelineModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51919FF024AB864A00541E64 /* TimelineModel.swift */; }; + 51919FF424AB869C00541E64 /* TimelineItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51919FF324AB869C00541E64 /* TimelineItem.swift */; }; + 51919FF524AB869C00541E64 /* TimelineItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51919FF324AB869C00541E64 /* TimelineItem.swift */; }; + 51919FF724AB8B7700541E64 /* TimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51919FF624AB8B7700541E64 /* TimelineView.swift */; }; + 51919FF824AB8B7700541E64 /* TimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51919FF624AB8B7700541E64 /* TimelineView.swift */; }; 51934CCB230F599B006127BE /* InteractiveNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51934CC1230F5963006127BE /* InteractiveNavigationController.swift */; }; 51934CCE2310792F006127BE /* ActivityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51934CCD2310792F006127BE /* ActivityManager.swift */; }; 51938DF2231AFC660055A1A0 /* SearchTimelineFeedDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51938DF1231AFC660055A1A0 /* SearchTimelineFeedDelegate.swift */; }; @@ -1817,6 +1825,10 @@ 51919FAE24AA8EFA00541E64 /* SidebarItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarItemView.swift; sourceTree = ""; }; 51919FB224AAB97900541E64 /* FeedImageLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedImageLoader.swift; sourceTree = ""; }; 51919FB524AABCA100541E64 /* IconImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconImageView.swift; sourceTree = ""; }; + 51919FED24AB85E400541E64 /* TimelineContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineContainerView.swift; sourceTree = ""; }; + 51919FF024AB864A00541E64 /* TimelineModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineModel.swift; sourceTree = ""; }; + 51919FF324AB869C00541E64 /* TimelineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineItem.swift; sourceTree = ""; }; + 51919FF624AB8B7700541E64 /* TimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineView.swift; sourceTree = ""; }; 51934CC1230F5963006127BE /* InteractiveNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InteractiveNavigationController.swift; sourceTree = ""; }; 51934CCD2310792F006127BE /* ActivityManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityManager.swift; sourceTree = ""; }; 51938DF1231AFC660055A1A0 /* SearchTimelineFeedDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchTimelineFeedDelegate.swift; sourceTree = ""; }; @@ -2602,6 +2614,17 @@ path = Images; sourceTree = ""; }; + 51919FCB24AB855000541E64 /* Timeline */ = { + isa = PBXGroup; + children = ( + 51919FED24AB85E400541E64 /* TimelineContainerView.swift */, + 51919FF324AB869C00541E64 /* TimelineItem.swift */, + 51919FF024AB864A00541E64 /* TimelineModel.swift */, + 51919FF624AB8B7700541E64 /* TimelineView.swift */, + ); + path = Timeline; + sourceTree = ""; + }; 51934CCC231078DC006127BE /* Activity */ = { isa = PBXGroup; children = ( @@ -2635,13 +2658,13 @@ 51C0519324A77E6600194D5E /* iOS */ = { isa = PBXGroup; children = ( - 51C0513F24A77DF800194D5E /* Info.plist */, - 51C051CE24A7A72100194D5E /* iOS.entitlements */, 51C051CF24A7A72100194D5E /* iOS-dev.entitlements */, + 51C051CE24A7A72100194D5E /* iOS.entitlements */, + 51C0513F24A77DF800194D5E /* Info.plist */, 51E4993B24A8709900B667CB /* AppDelegate.swift */, - 172199EB24AB228E00A31D04 /* Settings */, 172199EC24AB2E0100A31D04 /* SafariView.swift */, 172199EE24AB372D00A31D04 /* VisualEffectBlur.swift */, + 172199EB24AB228E00A31D04 /* Settings */, ); path = iOS; sourceTree = ""; @@ -2649,12 +2672,12 @@ 51C0519424A77E6D00194D5E /* macOS */ = { isa = PBXGroup; children = ( - 1729528F24AA1A4F00D65E66 /* Preferences */, - 51C0514624A77DF800194D5E /* Info.plist */, - 51C0514724A77DF800194D5E /* macOS.entitlements */, 51C051CD24A7A6DB00194D5E /* macOS-dev.entitlements */, + 51C0514724A77DF800194D5E /* macOS.entitlements */, + 51C0514624A77DF800194D5E /* Info.plist */, 51E4993924A8708800B667CB /* AppDelegate.swift */, 1729529A24AA1FD200D65E66 /* MacSearchField.swift */, + 1729528F24AA1A4F00D65E66 /* Preferences */, ); path = macOS; sourceTree = ""; @@ -2662,15 +2685,16 @@ 51C0519524A77E8B00194D5E /* Shared */ = { isa = PBXGroup; children = ( - 51C0513624A77DF700194D5E /* MainApp.swift */, - 51E499D724A912C200B667CB /* SceneModel.swift */, - 51E49A0224A91FF600B667CB /* SceneNavigationView.swift */, 51E4992524A80AAB00B667CB /* AppAssets.swift */, 51E4992824A866F000B667CB /* AppDefaults.swift */, 51E4995824A873F900B667CB /* ErrorHandler.swift */, + 51C0513624A77DF700194D5E /* MainApp.swift */, + 51E499D724A912C200B667CB /* SceneModel.swift */, + 51E49A0224A91FF600B667CB /* SceneNavigationView.swift */, 51C0513824A77DF800194D5E /* Assets.xcassets */, 51919FB124AAB95300541E64 /* Images */, 51E499FB24A9135A00B667CB /* Sidebar */, + 51919FCB24AB855000541E64 /* Timeline */, ); path = Shared; sourceTree = ""; @@ -3861,46 +3885,46 @@ TargetAttributes = { 51314636235A7BBE00387FDC = { CreatedOnToolsVersion = 11.2; - DevelopmentTeam = FQLBNX3GP7; + DevelopmentTeam = SHJK2V3AJG; LastSwiftMigration = 1120; ProvisioningStyle = Automatic; }; 513C5CE5232571C2003D4054 = { CreatedOnToolsVersion = 11.0; - DevelopmentTeam = FQLBNX3GP7; + DevelopmentTeam = SHJK2V3AJG; ProvisioningStyle = Automatic; }; 518B2ED12351B3DD00400001 = { CreatedOnToolsVersion = 11.2; - DevelopmentTeam = FQLBNX3GP7; + DevelopmentTeam = SHJK2V3AJG; ProvisioningStyle = Automatic; TestTargetID = 840D617B2029031C009BC708; }; 51C0513C24A77DF800194D5E = { CreatedOnToolsVersion = 12.0; - DevelopmentTeam = FQLBNX3GP7; + DevelopmentTeam = SHJK2V3AJG; ProvisioningStyle = Automatic; }; 51C0514324A77DF800194D5E = { CreatedOnToolsVersion = 12.0; - DevelopmentTeam = FQLBNX3GP7; + DevelopmentTeam = SHJK2V3AJG; ProvisioningStyle = Automatic; }; 6581C73220CED60000F4AD34 = { - DevelopmentTeam = FQLBNX3GP7; + DevelopmentTeam = SHJK2V3AJG; ProvisioningStyle = Automatic; }; 65ED3FA2235DEF6C0081F399 = { - DevelopmentTeam = FQLBNX3GP7; + DevelopmentTeam = SHJK2V3AJG; ProvisioningStyle = Automatic; }; 65ED4090235DEF770081F399 = { - DevelopmentTeam = FQLBNX3GP7; + DevelopmentTeam = SHJK2V3AJG; ProvisioningStyle = Automatic; }; 840D617B2029031C009BC708 = { CreatedOnToolsVersion = 9.3; - DevelopmentTeam = FQLBNX3GP7; + DevelopmentTeam = SHJK2V3AJG; ProvisioningStyle = Automatic; SystemCapabilities = { com.apple.BackgroundModes = { @@ -3910,7 +3934,7 @@ }; 849C645F1ED37A5D003D8FC0 = { CreatedOnToolsVersion = 8.2.1; - DevelopmentTeam = FQLBNX3GP7; + DevelopmentTeam = SHJK2V3AJG; ProvisioningStyle = Automatic; SystemCapabilities = { com.apple.HardenedRuntime = { @@ -3920,7 +3944,7 @@ }; 849C64701ED37A5D003D8FC0 = { CreatedOnToolsVersion = 8.2.1; - DevelopmentTeam = FQLBNX3GP7; + DevelopmentTeam = SHJK2V3AJG; ProvisioningStyle = Automatic; TestTargetID = 849C645F1ED37A5D003D8FC0; }; @@ -4691,11 +4715,13 @@ 51E4994424A8713C00B667CB /* RefreshInterval.swift in Sources */, 51E498F824A8085D00B667CB /* UnreadFeed.swift in Sources */, 51E4996A24A8762D00B667CB /* ExtractedArticle.swift in Sources */, + 51919FF124AB864A00541E64 /* TimelineModel.swift in Sources */, 51E498F124A8085D00B667CB /* StarredFeedDelegate.swift in Sources */, 51E498FF24A808BB00B667CB /* SingleFaviconDownloader.swift in Sources */, 51E4997224A8784300B667CB /* DefaultFeedsImporter.swift in Sources */, 51919FAF24AA8EFA00541E64 /* SidebarItemView.swift in Sources */, 51E4990D24A808C500B667CB /* RSHTMLMetadata+Extension.swift in Sources */, + 51919FF424AB869C00541E64 /* TimelineItem.swift in Sources */, 51E49A0024A91FC100B667CB /* RegularSidebarContainerView.swift in Sources */, 51E4995C24A875F300B667CB /* ArticleRenderer.swift in Sources */, 51E4992324A8095700B667CB /* URL-Extensions.swift in Sources */, @@ -4755,8 +4781,10 @@ 51E498F724A8085D00B667CB /* SearchTimelineFeedDelegate.swift in Sources */, 51E4993524A867E800B667CB /* AppNotifications.swift in Sources */, 51C0515E24A77DF800194D5E /* MainApp.swift in Sources */, + 51919FF724AB8B7700541E64 /* TimelineView.swift in Sources */, 51E4993D24A870F800B667CB /* UserNotificationManager.swift in Sources */, 51E4991524A808FF00B667CB /* ArticleStringFormatter.swift in Sources */, + 51919FEE24AB85E400541E64 /* TimelineContainerView.swift in Sources */, 51E4995724A8734D00B667CB /* ExtensionPoint.swift in Sources */, 51E4991124A808DE00B667CB /* SmallIconProvider.swift in Sources */, ); @@ -4777,9 +4805,11 @@ 51E4996F24A8764C00B667CB /* ActivityType.swift in Sources */, 51E4994E24A8734C00B667CB /* SendToMarsEditCommand.swift in Sources */, 51919FB024AA8EFA00541E64 /* SidebarItemView.swift in Sources */, + 51919FEF24AB85E400541E64 /* TimelineContainerView.swift in Sources */, 51E4996624A8760B00B667CB /* ArticleStyle.swift in Sources */, 51E4996C24A8762D00B667CB /* ExtractedArticle.swift in Sources */, 51E4990824A808C300B667CB /* RSHTMLMetadata+Extension.swift in Sources */, + 51919FF824AB8B7700541E64 /* TimelineView.swift in Sources */, 51E4992B24A8676300B667CB /* ArticleArray.swift in Sources */, 51E4994D24A8734C00B667CB /* ExtensionPointIdentifer.swift in Sources */, 51E4992224A8095600B667CB /* URL-Extensions.swift in Sources */, @@ -4791,6 +4821,7 @@ 51E498CA24A8085D00B667CB /* SmartFeedDelegate.swift in Sources */, 51E4990524A808C300B667CB /* FeaturedImageDownloader.swift in Sources */, 51E4991624A8090300B667CB /* ArticleUtilities.swift in Sources */, + 51919FF224AB864A00541E64 /* TimelineModel.swift in Sources */, 51E4991A24A8090F00B667CB /* IconImage.swift in Sources */, 51E4992724A80AAB00B667CB /* AppAssets.swift in Sources */, 51E49A0124A91FC100B667CB /* RegularSidebarContainerView.swift in Sources */, @@ -4829,6 +4860,7 @@ 51E498CF24A8085D00B667CB /* SmartFeed.swift in Sources */, 51E4990724A808C300B667CB /* AuthorAvatarDownloader.swift in Sources */, 51E4997424A8784400B667CB /* DefaultFeedsImporter.swift in Sources */, + 51919FF524AB869C00541E64 /* TimelineItem.swift in Sources */, 51E4992024A8095000B667CB /* RSImage-Extensions.swift in Sources */, 51E499FE24A9137600B667CB /* SidebarModel.swift in Sources */, 51E498FE24A808BA00B667CB /* FaviconDownloader.swift in Sources */, From 53a26f89fe578430239e6ec95116f3e251964109 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Tue, 30 Jun 2020 20:23:22 -0500 Subject: [PATCH 2/3] Implement scene specific storage for Sidebar expanded state --- .../Sidebar/SidebarExpandedContainers.swift | 48 +++++++++++++++++++ .../Shared/Sidebar/SidebarItem.swift | 13 +++-- .../Shared/Sidebar/SidebarView.swift | 36 ++++++++++++-- NetNewsWire.xcodeproj/project.pbxproj | 10 +++- 4 files changed, 94 insertions(+), 13 deletions(-) create mode 100644 Multiplatform/Shared/Sidebar/SidebarExpandedContainers.swift diff --git a/Multiplatform/Shared/Sidebar/SidebarExpandedContainers.swift b/Multiplatform/Shared/Sidebar/SidebarExpandedContainers.swift new file mode 100644 index 000000000..190135cde --- /dev/null +++ b/Multiplatform/Shared/Sidebar/SidebarExpandedContainers.swift @@ -0,0 +1,48 @@ +// +// SidebarExpandedContainers.swift +// NetNewsWire +// +// Created by Maurice Parker on 6/30/20. +// Copyright © 2020 Ranchero Software. All rights reserved. +// + +import SwiftUI +import Combine +import Account + +final class SidebarExpandedContainers: ObservableObject { + + @Published var expandedTable = Set() + var objectDidChange = PassthroughSubject() + + var data: Data { + get { + let encoder = PropertyListEncoder() + encoder.outputFormat = .binary + return (try? encoder.encode(expandedTable)) ?? Data() + } + set { + let decoder = PropertyListDecoder() + expandedTable = (try? decoder.decode(Set.self, from: newValue)) ?? Set() + } + } + + subscript(_ containerID: ContainerIdentifier) -> Bool { + get { + if expandedTable.contains(containerID) { + return true + } else { + return false + } + } + set(newValue) { + if newValue { + expandedTable.insert(containerID) + } else { + expandedTable.remove(containerID) + } + objectDidChange.send() + } + } + +} diff --git a/Multiplatform/Shared/Sidebar/SidebarItem.swift b/Multiplatform/Shared/Sidebar/SidebarItem.swift index 796008552..fbeea8841 100644 --- a/Multiplatform/Shared/Sidebar/SidebarItem.swift +++ b/Multiplatform/Shared/Sidebar/SidebarItem.swift @@ -24,7 +24,7 @@ struct SidebarItem: Identifiable { var id: SidebarItemIdentifier var represented: Any - var children: [SidebarItem]? + var children: [SidebarItem] = [SidebarItem]() var unreadCount: Int @@ -37,6 +37,10 @@ struct SidebarItem: Identifiable { represented as? Feed } + var containerID: ContainerIdentifier? { + return (represented as? ContainerIdentifiable)?.containerID + } + var representedType: RepresentedType { switch type(of: represented) { case is SmartFeed.Type: @@ -55,14 +59,12 @@ struct SidebarItem: Identifiable { init(_ smartFeedsController: SmartFeedsController) { self.id = .smartFeedController self.represented = smartFeedsController - self.children = [SidebarItem]() self.unreadCount = 0 } init(_ account: Account) { self.id = .account(account.accountID) self.represented = account - self.children = [SidebarItem]() self.unreadCount = account.unreadCount } @@ -70,13 +72,10 @@ struct SidebarItem: Identifiable { self.id = .feed(feed.feedID!) self.represented = feed self.unreadCount = unreadCount - if let container = feed as? Container, container.hasAtLeastOneWebFeed() { - self.children = [SidebarItem]() - } } mutating func addChild(_ sidebarItem: SidebarItem) { - children?.append(sidebarItem) + children.append(sidebarItem) } } diff --git a/Multiplatform/Shared/Sidebar/SidebarView.swift b/Multiplatform/Shared/Sidebar/SidebarView.swift index 71a5bd083..5497a18d5 100644 --- a/Multiplatform/Shared/Sidebar/SidebarView.swift +++ b/Multiplatform/Shared/Sidebar/SidebarView.swift @@ -7,17 +7,45 @@ // import SwiftUI +import Account struct SidebarView: View { + @SceneStorage("expandedContainers") private var expandedContainerData = Data() + @StateObject private var expandedContainers = SidebarExpandedContainers() @EnvironmentObject private var sidebarModel: SidebarModel +// @State private var selected = Set() + var body: some View { - List { - OutlineGroup(sidebarModel.sidebarItems, children: \.children) { sidebarItem in - SidebarItemView(sidebarItem: sidebarItem) + List() { + 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 + SidebarItemView(sidebarItem: sidebarItem) + } + } label: { + SidebarItemView(sidebarItem: sidebarItem) + } + } else { + SidebarItemView(sidebarItem: sidebarItem) + } + } + } label: { + SidebarItemView(sidebarItem: sidebarItem) + } + } } } + .onAppear { + expandedContainers.data = expandedContainerData + } + .onReceive(expandedContainers.objectDidChange) { + expandedContainerData = expandedContainers.data + } } - } diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index 2852381f1..b71450964 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -108,6 +108,8 @@ 51333D1724685D2E00EB5C91 /* AddRedditFeedWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51333D1524685D2E00EB5C91 /* AddRedditFeedWindowController.swift */; }; 51333D3B2468615D00EB5C91 /* AddRedditFeedSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = 51333D392468615D00EB5C91 /* AddRedditFeedSheet.xib */; }; 51333D3C2468615D00EB5C91 /* AddRedditFeedSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = 51333D392468615D00EB5C91 /* AddRedditFeedSheet.xib */; }; + 51392D1B24AC19A000BE0D35 /* SidebarExpandedContainers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51392D1A24AC19A000BE0D35 /* SidebarExpandedContainers.swift */; }; + 51392D1C24AC19A000BE0D35 /* SidebarExpandedContainers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51392D1A24AC19A000BE0D35 /* SidebarExpandedContainers.swift */; }; 513C5CE9232571C2003D4054 /* ShareViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 513C5CE8232571C2003D4054 /* ShareViewController.swift */; }; 513C5CEC232571C2003D4054 /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 513C5CEA232571C2003D4054 /* MainInterface.storyboard */; }; 513C5CF0232571C2003D4054 /* NetNewsWire iOS Share Extension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 513C5CE6232571C2003D4054 /* NetNewsWire iOS Share Extension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; @@ -1752,6 +1754,7 @@ 513228F2233037620033D4ED /* Reachability.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reachability.swift; sourceTree = ""; }; 51333D1524685D2E00EB5C91 /* AddRedditFeedWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddRedditFeedWindowController.swift; sourceTree = ""; }; 51333D3A2468615D00EB5C91 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Mac/Base.lproj/AddRedditFeedSheet.xib; sourceTree = SOURCE_ROOT; }; + 51392D1A24AC19A000BE0D35 /* SidebarExpandedContainers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarExpandedContainers.swift; sourceTree = ""; }; 513C5CE6232571C2003D4054 /* NetNewsWire iOS Share Extension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "NetNewsWire iOS Share Extension.appex"; sourceTree = BUILT_PRODUCTS_DIR; }; 513C5CE8232571C2003D4054 /* ShareViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareViewController.swift; sourceTree = ""; }; 513C5CEB232571C2003D4054 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/MainInterface.storyboard; sourceTree = ""; }; @@ -2872,12 +2875,13 @@ children = ( 172952AF24AA287100D65E66 /* CompactSidebarContainerView.swift */, 51E499FF24A91FC100B667CB /* RegularSidebarContainerView.swift */, - 172199F024AB716900A31D04 /* SidebarToolbar.swift */, + 51392D1A24AC19A000BE0D35 /* SidebarExpandedContainers.swift */, 51408B7D24A9EC6F0073CF4E /* SidebarItem.swift */, + 51919FAE24AA8EFA00541E64 /* SidebarItemView.swift */, 51E499FC24A9137600B667CB /* SidebarModel.swift */, + 172199F024AB716900A31D04 /* SidebarToolbar.swift */, 51919FA524AA64B000541E64 /* SidebarView.swift */, 51919FAB24AA8CCA00541E64 /* UnreadCountView.swift */, - 51919FAE24AA8EFA00541E64 /* SidebarItemView.swift */, ); path = Sidebar; sourceTree = ""; @@ -4711,6 +4715,7 @@ buildActionMask = 2147483647; files = ( 51E4995924A873F900B667CB /* ErrorHandler.swift in Sources */, + 51392D1B24AC19A000BE0D35 /* SidebarExpandedContainers.swift in Sources */, 51E4992F24A8676400B667CB /* ArticleArray.swift in Sources */, 51E4994424A8713C00B667CB /* RefreshInterval.swift in Sources */, 51E498F824A8085D00B667CB /* UnreadFeed.swift in Sources */, @@ -4870,6 +4875,7 @@ 51E4991824A8090A00B667CB /* CacheCleaner.swift in Sources */, 51E498CD24A8085D00B667CB /* SearchTimelineFeedDelegate.swift in Sources */, 51E4996124A875F400B667CB /* ArticleRenderer.swift in Sources */, + 51392D1C24AC19A000BE0D35 /* SidebarExpandedContainers.swift in Sources */, 51C0515F24A77DF800194D5E /* MainApp.swift in Sources */, 1729529524AA1CAA00D65E66 /* GeneralPreferencesView.swift in Sources */, 1729529424AA1CAA00D65E66 /* AdvancedPreferencesView.swift in Sources */, From 6ddf0f29fbea4c64e6b447988f44a0cf6b9087a1 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Tue, 30 Jun 2020 20:38:55 -0500 Subject: [PATCH 3/3] Comment out SceneStorage since it crashes on launch on macOS --- Multiplatform/Shared/Sidebar/SidebarView.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Multiplatform/Shared/Sidebar/SidebarView.swift b/Multiplatform/Shared/Sidebar/SidebarView.swift index 5497a18d5..5f85e8242 100644 --- a/Multiplatform/Shared/Sidebar/SidebarView.swift +++ b/Multiplatform/Shared/Sidebar/SidebarView.swift @@ -11,7 +11,8 @@ import Account struct SidebarView: View { - @SceneStorage("expandedContainers") private var expandedContainerData = Data() + // I had to comment out SceneStorage because it blows up if used on macOS +// @SceneStorage("expandedContainers") private var expandedContainerData = Data() @StateObject private var expandedContainers = SidebarExpandedContainers() @EnvironmentObject private var sidebarModel: SidebarModel @@ -41,11 +42,11 @@ struct SidebarView: View { } } } - .onAppear { - expandedContainers.data = expandedContainerData - } - .onReceive(expandedContainers.objectDidChange) { - expandedContainerData = expandedContainers.data - } +// .onAppear { +// expandedContainers.data = expandedContainerData +// } +// .onReceive(expandedContainers.objectDidChange) { +// expandedContainerData = expandedContainers.data +// } } }