2021-07-11 20:52:49 +00:00
|
|
|
import SwiftUI
|
|
|
|
#if os(iOS)
|
|
|
|
import Introspect
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct AppSidebarNavigation: View {
|
2021-09-25 08:18:22 +00:00
|
|
|
@EnvironmentObject<InvidiousAPI> private var api
|
|
|
|
@EnvironmentObject<NavigationModel> private var navigation
|
2021-07-11 20:52:49 +00:00
|
|
|
|
|
|
|
@State private var didApplyPrimaryViewWorkAround = false
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
#if os(iOS)
|
|
|
|
content.introspectViewController { viewController in
|
|
|
|
// workaround for an empty supplementary view on launch
|
|
|
|
// the supplementary view is determined by the default selection inside the
|
|
|
|
// primary view, but the primary view is not loaded so its selection is not read
|
2021-09-25 08:18:22 +00:00
|
|
|
// We work around that by showing the primary view
|
2021-07-11 20:52:49 +00:00
|
|
|
if !didApplyPrimaryViewWorkAround, let splitVC = viewController.children.first as? UISplitViewController {
|
|
|
|
UIView.performWithoutAnimation {
|
|
|
|
splitVC.show(.primary)
|
|
|
|
}
|
|
|
|
didApplyPrimaryViewWorkAround = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
content
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-09-25 08:18:22 +00:00
|
|
|
let sidebarMinWidth: Double = 280
|
|
|
|
|
2021-07-11 20:52:49 +00:00
|
|
|
var content: some View {
|
|
|
|
NavigationView {
|
2021-09-28 23:01:49 +00:00
|
|
|
Sidebar()
|
2021-09-25 08:18:22 +00:00
|
|
|
.toolbar { toolbarContent }
|
|
|
|
.frame(minWidth: sidebarMinWidth)
|
2021-08-31 21:17:50 +00:00
|
|
|
|
2021-07-11 20:52:49 +00:00
|
|
|
Text("Select section")
|
|
|
|
}
|
2021-09-19 12:42:47 +00:00
|
|
|
.environment(\.navigationStyle, .sidebar)
|
2021-07-11 20:52:49 +00:00
|
|
|
}
|
|
|
|
|
2021-09-25 08:18:22 +00:00
|
|
|
var toolbarContent: some ToolbarContent {
|
|
|
|
Group {
|
|
|
|
#if os(iOS)
|
|
|
|
ToolbarItemGroup(placement: .navigationBarTrailing) {
|
|
|
|
Button(action: { navigation.presentingSettings = true }) {
|
|
|
|
Image(systemName: "gearshape.2")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ToolbarItem(placement: accountsMenuToolbarItemPlacement) {
|
|
|
|
AccountsMenuView()
|
|
|
|
.help(
|
|
|
|
"Switch Instances and Accounts\n" +
|
|
|
|
"Current Instance: \n" +
|
|
|
|
"\(api.account?.url ?? "Not Set")\n" +
|
|
|
|
"Current User: \(api.account?.description ?? "Not set")"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var accountsMenuToolbarItemPlacement: ToolbarItemPlacement {
|
|
|
|
#if os(iOS)
|
|
|
|
return .bottomBar
|
|
|
|
#else
|
|
|
|
return .automatic
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-08-29 21:36:18 +00:00
|
|
|
static func symbolSystemImage(_ name: String) -> String {
|
|
|
|
let firstLetter = name.first?.lowercased()
|
|
|
|
let regex = #"^[a-z0-9]$"#
|
|
|
|
|
|
|
|
let symbolName = firstLetter?.range(of: regex, options: .regularExpression) != nil ? firstLetter! : "questionmark"
|
|
|
|
|
2021-09-25 08:18:22 +00:00
|
|
|
return "\(symbolName).circle"
|
2021-07-11 20:52:49 +00:00
|
|
|
}
|
|
|
|
}
|