Moves selection to SidebarModel

This commit is contained in:
Stuart Breckenridge
2020-07-09 07:15:47 +08:00
parent 91bc4a0c30
commit 4c11667ff7
4 changed files with 26 additions and 50 deletions

View File

@@ -20,6 +20,28 @@ class SidebarModel: ObservableObject {
@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() {

View File

@@ -1,38 +0,0 @@
//
// SidebarSelectionModel.swift
// NetNewsWire
//
// Created by Stuart Breckenridge on 8/7/20.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import Foundation
import RSCore
import Account
class SidebarSelectionModel: ObservableObject {
#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
}
}
}

View File

@@ -16,12 +16,10 @@ struct SidebarView: View {
@StateObject private var expandedContainers = SidebarExpandedContainers()
@EnvironmentObject private var sidebarModel: SidebarModel
@StateObject private var sidebarSelectionModel = SidebarSelectionModel()
@ViewBuilder
var body: some View {
#if os(macOS)
List(selection: $sidebarSelectionModel.selectedSidebarItems) {
List(selection: $sidebarModel.selectedSidebarItems) {
containedList
}
#else
@@ -49,7 +47,7 @@ struct SidebarView: View {
SidebarItemView(sidebarItem: sidebarItem)
NavigationLink(destination: (TimelineContainerView(feed: sidebarItem.feed)),
tag: sidebarItem.feed!.feedID!,
selection: $sidebarSelectionModel.selectedSidebarItem) {
selection: $sidebarModel.selectedSidebarItem) {
EmptyView()
}.buttonStyle(PlainButtonStyle())
}
@@ -59,7 +57,7 @@ struct SidebarView: View {
SidebarItemView(sidebarItem: sidebarItem)
NavigationLink(destination: (TimelineContainerView(feed: sidebarItem.feed)),
tag: sidebarItem.feed!.feedID!,
selection: $sidebarSelectionModel.selectedSidebarItem) {
selection: $sidebarModel.selectedSidebarItem) {
EmptyView()
}.buttonStyle(PlainButtonStyle())
}
@@ -69,7 +67,7 @@ struct SidebarView: View {
SidebarItemView(sidebarItem: sidebarItem)
NavigationLink(destination: (TimelineContainerView(feed: sidebarItem.feed)),
tag: sidebarItem.feed!.feedID!,
selection: $sidebarSelectionModel.selectedSidebarItem) {
selection: $sidebarModel.selectedSidebarItem) {
EmptyView()
}.buttonStyle(PlainButtonStyle())
}