Improve SidebarView
This commit is contained in:
@@ -18,7 +18,7 @@ public struct MainView: View {
|
|||||||
|
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
NavigationSplitView {
|
NavigationSplitView {
|
||||||
SidebarView()
|
SidebarView(selection: $viewModel.selection)
|
||||||
.navigationSplitViewColumnWidth(150)
|
.navigationSplitViewColumnWidth(150)
|
||||||
} detail: {
|
} detail: {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
@@ -60,7 +60,6 @@ public struct MainView: View {
|
|||||||
.onReceive(environments.openSettings) {
|
.onReceive(environments.openSettings) {
|
||||||
viewModel.openSettings()
|
viewModel.openSettings()
|
||||||
}
|
}
|
||||||
.environment(\.selection, $viewModel.selection)
|
|
||||||
.environment(\.importProfile, $viewModel.importProfile)
|
.environment(\.importProfile, $viewModel.importProfile)
|
||||||
.environment(\.importRemoteProfile, $viewModel.importRemoteProfile)
|
.environment(\.importRemoteProfile, $viewModel.importRemoteProfile)
|
||||||
.environment(\.profileEditor, profileEditor)
|
.environment(\.profileEditor, profileEditor)
|
||||||
|
|||||||
@@ -3,97 +3,56 @@ import Library
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
public struct SidebarView: View {
|
public struct SidebarView: View {
|
||||||
@Environment(\.selection) private var selection
|
@Binding var selection: NavigationPage
|
||||||
@EnvironmentObject private var environments: ExtensionEnvironments
|
@EnvironmentObject private var environments: ExtensionEnvironments
|
||||||
|
|
||||||
public init() {}
|
public init(selection: Binding<NavigationPage>) {
|
||||||
|
_selection = selection
|
||||||
|
}
|
||||||
|
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
VStack {
|
if ApplicationLibrary.inPreview {
|
||||||
if ApplicationLibrary.inPreview {
|
sidebarContent(isConnected: true, profile: nil)
|
||||||
SidebarViewPreview()
|
} else if environments.extensionProfileLoading {
|
||||||
} else if environments.extensionProfileLoading {
|
ProgressView()
|
||||||
ProgressView()
|
} else if let profile = environments.extensionProfile {
|
||||||
} else if let profile = environments.extensionProfile {
|
sidebarContent(isConnected: profile.status.isConnectedStrict, profile: profile)
|
||||||
SidebarView0().environmentObject(profile)
|
.onChangeCompat(of: profile.status) {
|
||||||
|
if !selection.visible(profile) {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
selection = .dashboard
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sidebarContent(isConnected: false, profile: nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func sidebarContent(isConnected: Bool, profile: ExtensionProfile?) -> some View {
|
||||||
|
List(selection: $selection) {
|
||||||
|
if isConnected {
|
||||||
|
Section(NavigationPage.dashboard.title) {
|
||||||
|
Label("Overview", systemImage: "text.and.command.macwindow")
|
||||||
|
.tint(.textColor)
|
||||||
|
.tag(NavigationPage.dashboard)
|
||||||
|
NavigationPage.groups.label.tag(NavigationPage.groups)
|
||||||
|
if Variant.isBeta {
|
||||||
|
NavigationPage.connections.label.tag(NavigationPage.connections)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Divider()
|
||||||
|
ForEach(NavigationPage.macosDefaultPages, id: \.self) { it in
|
||||||
|
it.label
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
SidebarView1()
|
ForEach(NavigationPage.allCases.filter { $0.visible(profile) }, id: \.self) { it in
|
||||||
}
|
it.label
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SidebarView0: View {
|
|
||||||
@Environment(\.selection) private var selection
|
|
||||||
@EnvironmentObject private var extensionProfile: ExtensionProfile
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
VStack {
|
|
||||||
viewBuilder {
|
|
||||||
if extensionProfile.status.isConnectedStrict {
|
|
||||||
List(selection: selection) {
|
|
||||||
Section(NavigationPage.dashboard.title) {
|
|
||||||
Label("Overview", systemImage: "text.and.command.macwindow")
|
|
||||||
.tint(.textColor)
|
|
||||||
.tag(NavigationPage.dashboard)
|
|
||||||
NavigationPage.groups.label.tag(NavigationPage.groups)
|
|
||||||
if Variant.isBeta {
|
|
||||||
NavigationPage.connections.label.tag(NavigationPage.connections)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Divider()
|
|
||||||
ForEach(NavigationPage.macosDefaultPages, id: \.self) { it in
|
|
||||||
it.label
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
List(NavigationPage.allCases.filter { it in
|
|
||||||
it.visible(extensionProfile)
|
|
||||||
}, selection: selection) { it in
|
|
||||||
it.label
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.listStyle(.sidebar)
|
|
||||||
.scrollDisabled(true)
|
|
||||||
}
|
|
||||||
.onChangeCompat(of: extensionProfile.status) {
|
|
||||||
if !selection.wrappedValue.visible(extensionProfile) {
|
|
||||||
selection.wrappedValue = NavigationPage.dashboard
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
.listStyle(.sidebar)
|
||||||
|
.scrollDisabled(true)
|
||||||
struct SidebarView1: View {
|
|
||||||
@Environment(\.selection) private var selection
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
List(NavigationPage.allCases.filter { it in
|
|
||||||
it.visible(nil)
|
|
||||||
}, selection: selection) { it in
|
|
||||||
it.label
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SidebarViewPreview: View {
|
|
||||||
@Environment(\.selection) private var selection
|
|
||||||
var body: some View {
|
|
||||||
VStack {
|
|
||||||
List(selection: selection) {
|
|
||||||
Section(NavigationPage.dashboard.title) {
|
|
||||||
Label("Overview", systemImage: "text.and.command.macwindow")
|
|
||||||
.tint(.textColor)
|
|
||||||
.tag(NavigationPage.dashboard)
|
|
||||||
NavigationPage.groups.label.tag(NavigationPage.groups)
|
|
||||||
}
|
|
||||||
Divider()
|
|
||||||
ForEach(NavigationPage.macosDefaultPages, id: \.self) { it in
|
|
||||||
it.label
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.listStyle(.sidebar)
|
|
||||||
.scrollDisabled(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user