1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 06:40:32 +05:30
yattee/Shared/Settings/SettingsView.swift

126 lines
3.7 KiB
Swift
Raw Normal View History

2021-09-25 13:48:22 +05:30
import Defaults
import Foundation
import SwiftUI
struct SettingsView: View {
#if os(macOS)
private enum Tabs: Hashable {
2021-11-05 04:55:51 +05:30
case instances, browsing, playback, services
}
#endif
2021-09-25 13:48:22 +05:30
#if os(iOS)
2021-11-28 20:07:55 +05:30
@Environment(\.presentationMode) private var presentationMode
#endif
2021-09-25 13:48:22 +05:30
2021-11-13 02:16:15 +05:30
@EnvironmentObject<AccountsModel> private var accounts
2021-11-28 20:07:55 +05:30
@State private var presentingInstanceForm = false
@State private var savedFormInstanceID: Instance.ID?
@Default(.instances) private var instances
2021-09-25 13:48:22 +05:30
var body: some View {
#if os(macOS)
TabView {
Form {
2021-10-23 17:21:02 +05:30
InstancesSettings()
2021-11-13 02:16:15 +05:30
.environmentObject(accounts)
2021-09-25 13:48:22 +05:30
}
.tabItem {
Label("Instances", systemImage: "server.rack")
}
.tag(Tabs.instances)
2021-11-05 04:55:51 +05:30
Form {
BrowsingSettings()
}
.tabItem {
Label("Browsing", systemImage: "list.and.film")
}
.tag(Tabs.browsing)
2021-10-23 17:42:53 +05:30
Form {
2021-11-04 04:30:17 +05:30
PlaybackSettings()
2021-10-23 17:42:53 +05:30
}
.tabItem {
2021-11-04 04:30:17 +05:30
Label("Playback", systemImage: "play.rectangle.on.rectangle.fill")
2021-10-23 17:42:53 +05:30
}
2021-11-04 04:30:17 +05:30
.tag(Tabs.playback)
2021-10-23 17:42:53 +05:30
2021-09-25 13:48:22 +05:30
Form {
2021-11-04 04:30:17 +05:30
ServicesSettings()
2021-09-25 13:48:22 +05:30
}
.tabItem {
2021-11-04 04:30:17 +05:30
Label("Services", systemImage: "puzzlepiece.extension")
2021-09-25 13:48:22 +05:30
}
2021-11-04 04:30:17 +05:30
.tag(Tabs.services)
2021-09-25 13:48:22 +05:30
}
.padding(20)
.frame(width: 400, height: 380)
2021-09-25 13:48:22 +05:30
#else
NavigationView {
List {
#if os(tvOS)
AccountSelectionView()
2021-11-07 22:22:42 +05:30
Section(header: SettingsHeader(text: "Favorites")) {
NavigationLink("Edit favorites...") {
EditFavorites()
}
}
#endif
2021-11-28 20:07:55 +05:30
Section(header: Text("Instances")) {
ForEach(instances) { instance in
AccountsNavigationLink(instance: instance)
}
addInstanceButton
}
2021-11-05 04:55:51 +05:30
BrowsingSettings()
2021-10-23 17:21:02 +05:30
PlaybackSettings()
2021-11-04 04:30:17 +05:30
ServicesSettings()
2021-09-25 13:48:22 +05:30
}
.navigationTitle("Settings")
2021-09-27 03:33:33 +05:30
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
#if !os(tvOS)
Button("Done") {
2021-11-28 20:07:55 +05:30
presentationMode.wrappedValue.dismiss()
}
2021-09-27 03:33:33 +05:30
.keyboardShortcut(.cancelAction)
#endif
2021-09-25 13:48:22 +05:30
}
2021-09-27 03:33:33 +05:30
}
.frame(maxWidth: 1000)
2021-09-27 03:33:33 +05:30
#if os(iOS)
.listStyle(.insetGrouped)
#endif
2021-09-25 13:48:22 +05:30
}
2021-11-28 20:07:55 +05:30
.sheet(isPresented: $presentingInstanceForm) {
InstanceForm(savedInstanceID: $savedFormInstanceID)
}
#if os(tvOS)
2021-11-28 20:07:55 +05:30
.background(Color.black)
#endif
2021-09-25 13:48:22 +05:30
#endif
}
2021-11-28 20:07:55 +05:30
private var addInstanceButton: some View {
Button("Add Instance...") {
presentingInstanceForm = true
}
}
2021-09-25 13:48:22 +05:30
}
struct SettingsView_Previews: PreviewProvider {
static var previews: some View {
SettingsView()
2021-09-29 17:15:00 +05:30
.injectFixtureEnvironmentObjects()
2021-09-25 13:48:22 +05:30
#if os(macOS)
.frame(width: 600, height: 300)
#endif
}
}