mirror of
https://github.com/metabolist/metatext.git
synced 2025-01-03 02:28:41 +00:00
Refactoring
This commit is contained in:
parent
2df47efdc9
commit
08bf8f1b8b
12 changed files with 124 additions and 114 deletions
|
@ -130,12 +130,12 @@ extension MainNavigationViewModel {
|
||||||
static let development = MainNavigationViewModel(environment: .development)
|
static let development = MainNavigationViewModel(environment: .development)
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SettingsViewModel {
|
extension SecondaryNavigationViewModel {
|
||||||
static let development = MainNavigationViewModel.development.settingsViewModel()
|
static let development = MainNavigationViewModel.development.settingsViewModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
extension IdentitiesViewModel {
|
extension IdentitiesViewModel {
|
||||||
static let development = SettingsViewModel.development.identitiesViewModel()
|
static let development = SecondaryNavigationViewModel.development.identitiesViewModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
// swiftlint:enable force_try
|
// swiftlint:enable force_try
|
||||||
|
|
|
@ -15,10 +15,10 @@
|
||||||
D047FAAF24C3E21200AF17C5 /* MetatextApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D047FA8524C3E21000AF17C5 /* MetatextApp.swift */; };
|
D047FAAF24C3E21200AF17C5 /* MetatextApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D047FA8524C3E21000AF17C5 /* MetatextApp.swift */; };
|
||||||
D047FAB224C3E21200AF17C5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D047FA8724C3E21200AF17C5 /* Assets.xcassets */; };
|
D047FAB224C3E21200AF17C5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D047FA8724C3E21200AF17C5 /* Assets.xcassets */; };
|
||||||
D047FAB324C3E21200AF17C5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D047FA8724C3E21200AF17C5 /* Assets.xcassets */; };
|
D047FAB324C3E21200AF17C5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D047FA8724C3E21200AF17C5 /* Assets.xcassets */; };
|
||||||
D04FD73324D48F37007D572D /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04FD73224D48F37007D572D /* SettingsView.swift */; };
|
D04FD73324D48F37007D572D /* SecondaryNavigationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04FD73224D48F37007D572D /* SecondaryNavigationView.swift */; };
|
||||||
D04FD73424D48F37007D572D /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04FD73224D48F37007D572D /* SettingsView.swift */; };
|
D04FD73424D48F37007D572D /* SecondaryNavigationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04FD73224D48F37007D572D /* SecondaryNavigationView.swift */; };
|
||||||
D04FD73624D49506007D572D /* SettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04FD73524D49506007D572D /* SettingsViewModel.swift */; };
|
D04FD73624D49506007D572D /* SecondaryNavigationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04FD73524D49506007D572D /* SecondaryNavigationViewModel.swift */; };
|
||||||
D04FD73724D49506007D572D /* SettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04FD73524D49506007D572D /* SettingsViewModel.swift */; };
|
D04FD73724D49506007D572D /* SecondaryNavigationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04FD73524D49506007D572D /* SecondaryNavigationViewModel.swift */; };
|
||||||
D04FD73924D4A7B4007D572D /* AccountEndpoint+Stubbing.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04FD73824D4A7B4007D572D /* AccountEndpoint+Stubbing.swift */; };
|
D04FD73924D4A7B4007D572D /* AccountEndpoint+Stubbing.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04FD73824D4A7B4007D572D /* AccountEndpoint+Stubbing.swift */; };
|
||||||
D04FD73A24D4A7B4007D572D /* AccountEndpoint+Stubbing.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04FD73824D4A7B4007D572D /* AccountEndpoint+Stubbing.swift */; };
|
D04FD73A24D4A7B4007D572D /* AccountEndpoint+Stubbing.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04FD73824D4A7B4007D572D /* AccountEndpoint+Stubbing.swift */; };
|
||||||
D04FD73C24D4A83A007D572D /* InstanceEndpoint+Stubbing.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04FD73B24D4A83A007D572D /* InstanceEndpoint+Stubbing.swift */; };
|
D04FD73C24D4A83A007D572D /* InstanceEndpoint+Stubbing.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04FD73B24D4A83A007D572D /* InstanceEndpoint+Stubbing.swift */; };
|
||||||
|
@ -172,8 +172,8 @@
|
||||||
D047FA9424C3E21200AF17C5 /* Metatext.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Metatext.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
D047FA9424C3E21200AF17C5 /* Metatext.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Metatext.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
D047FA9624C3E21200AF17C5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
D047FA9624C3E21200AF17C5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
D047FA9724C3E21200AF17C5 /* macOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = macOS.entitlements; sourceTree = "<group>"; };
|
D047FA9724C3E21200AF17C5 /* macOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = macOS.entitlements; sourceTree = "<group>"; };
|
||||||
D04FD73224D48F37007D572D /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
|
D04FD73224D48F37007D572D /* SecondaryNavigationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondaryNavigationView.swift; sourceTree = "<group>"; };
|
||||||
D04FD73524D49506007D572D /* SettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewModel.swift; sourceTree = "<group>"; };
|
D04FD73524D49506007D572D /* SecondaryNavigationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondaryNavigationViewModel.swift; sourceTree = "<group>"; };
|
||||||
D04FD73824D4A7B4007D572D /* AccountEndpoint+Stubbing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AccountEndpoint+Stubbing.swift"; sourceTree = "<group>"; };
|
D04FD73824D4A7B4007D572D /* AccountEndpoint+Stubbing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AccountEndpoint+Stubbing.swift"; sourceTree = "<group>"; };
|
||||||
D04FD73B24D4A83A007D572D /* InstanceEndpoint+Stubbing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "InstanceEndpoint+Stubbing.swift"; sourceTree = "<group>"; };
|
D04FD73B24D4A83A007D572D /* InstanceEndpoint+Stubbing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "InstanceEndpoint+Stubbing.swift"; sourceTree = "<group>"; };
|
||||||
D04FD74124D4AA34007D572D /* DevelopmentModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DevelopmentModels.swift; sourceTree = "<group>"; };
|
D04FD74124D4AA34007D572D /* DevelopmentModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DevelopmentModels.swift; sourceTree = "<group>"; };
|
||||||
|
@ -387,7 +387,7 @@
|
||||||
D06BAB5024D942CF0081B8FD /* IdentitiesView.swift */,
|
D06BAB5024D942CF0081B8FD /* IdentitiesView.swift */,
|
||||||
D0091B6724DC10B30040E8D2 /* PreferencesView.swift */,
|
D0091B6724DC10B30040E8D2 /* PreferencesView.swift */,
|
||||||
D0BEC93A24C96FD500E864C4 /* RootView.swift */,
|
D0BEC93A24C96FD500E864C4 /* RootView.swift */,
|
||||||
D04FD73224D48F37007D572D /* SettingsView.swift */,
|
D04FD73224D48F37007D572D /* SecondaryNavigationView.swift */,
|
||||||
D0BEC94924CA231200E864C4 /* TimelineView.swift */,
|
D0BEC94924CA231200E864C4 /* TimelineView.swift */,
|
||||||
);
|
);
|
||||||
path = Views;
|
path = Views;
|
||||||
|
@ -414,7 +414,7 @@
|
||||||
D052BBDF24D805E300A80A7A /* MainNavigationViewModel.swift */,
|
D052BBDF24D805E300A80A7A /* MainNavigationViewModel.swift */,
|
||||||
D0091B6A24DC10CE0040E8D2 /* PreferencesViewModel.swift */,
|
D0091B6A24DC10CE0040E8D2 /* PreferencesViewModel.swift */,
|
||||||
D0BEC93724C9632800E864C4 /* RootViewModel.swift */,
|
D0BEC93724C9632800E864C4 /* RootViewModel.swift */,
|
||||||
D04FD73524D49506007D572D /* SettingsViewModel.swift */,
|
D04FD73524D49506007D572D /* SecondaryNavigationViewModel.swift */,
|
||||||
D0BEC94624CA22C400E864C4 /* TimelineViewModel.swift */,
|
D0BEC94624CA22C400E864C4 /* TimelineViewModel.swift */,
|
||||||
);
|
);
|
||||||
path = "View Models";
|
path = "View Models";
|
||||||
|
@ -686,7 +686,7 @@
|
||||||
D0ED1BE324CFA84400B4899C /* MastodonError.swift in Sources */,
|
D0ED1BE324CFA84400B4899C /* MastodonError.swift in Sources */,
|
||||||
D0666A6324C6DC6C00F3F04B /* AppAuthorization.swift in Sources */,
|
D0666A6324C6DC6C00F3F04B /* AppAuthorization.swift in Sources */,
|
||||||
D065F53B24D3B33A00741304 /* View+Extensions.swift in Sources */,
|
D065F53B24D3B33A00741304 /* View+Extensions.swift in Sources */,
|
||||||
D04FD73324D48F37007D572D /* SettingsView.swift in Sources */,
|
D04FD73324D48F37007D572D /* SecondaryNavigationView.swift in Sources */,
|
||||||
D0DC174A24CFF15F00A75C65 /* AppAuthorizationEndpoint+Stubbing.swift in Sources */,
|
D0DC174A24CFF15F00A75C65 /* AppAuthorizationEndpoint+Stubbing.swift in Sources */,
|
||||||
D0666A5A24C6C64100F3F04B /* MastodonEncoder.swift in Sources */,
|
D0666A5A24C6C64100F3F04B /* MastodonEncoder.swift in Sources */,
|
||||||
D0666A5124C6C3BC00F3F04B /* Account.swift in Sources */,
|
D0666A5124C6C3BC00F3F04B /* Account.swift in Sources */,
|
||||||
|
@ -708,7 +708,7 @@
|
||||||
D0666A4224C6BB7B00F3F04B /* IdentityDatabase.swift in Sources */,
|
D0666A4224C6BB7B00F3F04B /* IdentityDatabase.swift in Sources */,
|
||||||
D0BEC94A24CA231200E864C4 /* TimelineView.swift in Sources */,
|
D0BEC94A24CA231200E864C4 /* TimelineView.swift in Sources */,
|
||||||
D0BEC93B24C96FD500E864C4 /* RootView.swift in Sources */,
|
D0BEC93B24C96FD500E864C4 /* RootView.swift in Sources */,
|
||||||
D04FD73624D49506007D572D /* SettingsViewModel.swift in Sources */,
|
D04FD73624D49506007D572D /* SecondaryNavigationViewModel.swift in Sources */,
|
||||||
D04FD74224D4AA34007D572D /* DevelopmentModels.swift in Sources */,
|
D04FD74224D4AA34007D572D /* DevelopmentModels.swift in Sources */,
|
||||||
D0DC175824D0130800A75C65 /* HTTPStubs.swift in Sources */,
|
D0DC175824D0130800A75C65 /* HTTPStubs.swift in Sources */,
|
||||||
D0DC177724D0CF2600A75C65 /* FakeKeychain.swift in Sources */,
|
D0DC177724D0CF2600A75C65 /* FakeKeychain.swift in Sources */,
|
||||||
|
@ -758,7 +758,7 @@
|
||||||
D0ED1BE424CFA84400B4899C /* MastodonError.swift in Sources */,
|
D0ED1BE424CFA84400B4899C /* MastodonError.swift in Sources */,
|
||||||
D0666A6424C6DC6C00F3F04B /* AppAuthorization.swift in Sources */,
|
D0666A6424C6DC6C00F3F04B /* AppAuthorization.swift in Sources */,
|
||||||
D065F53C24D3B33A00741304 /* View+Extensions.swift in Sources */,
|
D065F53C24D3B33A00741304 /* View+Extensions.swift in Sources */,
|
||||||
D04FD73424D48F37007D572D /* SettingsView.swift in Sources */,
|
D04FD73424D48F37007D572D /* SecondaryNavigationView.swift in Sources */,
|
||||||
D0DC174B24CFF15F00A75C65 /* AppAuthorizationEndpoint+Stubbing.swift in Sources */,
|
D0DC174B24CFF15F00A75C65 /* AppAuthorizationEndpoint+Stubbing.swift in Sources */,
|
||||||
D0666A5B24C6C64100F3F04B /* MastodonEncoder.swift in Sources */,
|
D0666A5B24C6C64100F3F04B /* MastodonEncoder.swift in Sources */,
|
||||||
D0666A5224C6C3BC00F3F04B /* Account.swift in Sources */,
|
D0666A5224C6C3BC00F3F04B /* Account.swift in Sources */,
|
||||||
|
@ -780,7 +780,7 @@
|
||||||
D0666A4324C6BB7B00F3F04B /* IdentityDatabase.swift in Sources */,
|
D0666A4324C6BB7B00F3F04B /* IdentityDatabase.swift in Sources */,
|
||||||
D0BEC94B24CA231200E864C4 /* TimelineView.swift in Sources */,
|
D0BEC94B24CA231200E864C4 /* TimelineView.swift in Sources */,
|
||||||
D0BEC93C24C96FD500E864C4 /* RootView.swift in Sources */,
|
D0BEC93C24C96FD500E864C4 /* RootView.swift in Sources */,
|
||||||
D04FD73724D49506007D572D /* SettingsViewModel.swift in Sources */,
|
D04FD73724D49506007D572D /* SecondaryNavigationViewModel.swift in Sources */,
|
||||||
D04FD74324D4AA34007D572D /* DevelopmentModels.swift in Sources */,
|
D04FD74324D4AA34007D572D /* DevelopmentModels.swift in Sources */,
|
||||||
D0DC175924D0130800A75C65 /* HTTPStubs.swift in Sources */,
|
D0DC175924D0130800A75C65 /* HTTPStubs.swift in Sources */,
|
||||||
D0DC177824D0CF2600A75C65 /* FakeKeychain.swift in Sources */,
|
D0DC177824D0CF2600A75C65 /* FakeKeychain.swift in Sources */,
|
||||||
|
|
|
@ -3,4 +3,4 @@
|
||||||
"go" = "Go";
|
"go" = "Go";
|
||||||
"add-identity.instance-url" = "Instance URL";
|
"add-identity.instance-url" = "Instance URL";
|
||||||
"oauth.error.code-not-found" = "OAuth error: code not found";
|
"oauth.error.code-not-found" = "OAuth error: code not found";
|
||||||
"settings" = "Settings";
|
"accounts" = "Accounts";
|
||||||
|
|
|
@ -24,5 +24,7 @@ extension MastodonPreferences {
|
||||||
case showAll
|
case showAll
|
||||||
case hideAll
|
case hideAll
|
||||||
case unknown
|
case unknown
|
||||||
|
|
||||||
|
static var unknownCase: Self { .unknown }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,5 +9,7 @@ struct Status {
|
||||||
case `private`
|
case `private`
|
||||||
case direct
|
case direct
|
||||||
case unknown
|
case unknown
|
||||||
|
|
||||||
|
static var unknownCase: Self { .unknown }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,15 +3,11 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
protocol Unknowable: RawRepresentable, CaseIterable where RawValue: Equatable {
|
protocol Unknowable: RawRepresentable, CaseIterable where RawValue: Equatable {
|
||||||
static var unknown: RawValue { get }
|
static var unknownCase: Self { get }
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Unknowable {
|
extension Unknowable {
|
||||||
init(rawValue: RawValue) {
|
init(rawValue: RawValue) {
|
||||||
self = Self.allCases.first { $0.rawValue == rawValue } ?? Self(rawValue: Self.unknown)
|
self = Self.allCases.first { $0.rawValue == rawValue } ?? Self.unknownCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Unknowable where RawValue == String {
|
|
||||||
static var unknown: String { "unknown" }
|
|
||||||
}
|
|
||||||
|
|
|
@ -52,8 +52,8 @@ extension MainNavigationViewModel {
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
|
|
||||||
func settingsViewModel() -> SettingsViewModel {
|
func settingsViewModel() -> SecondaryNavigationViewModel {
|
||||||
SettingsViewModel(environment: environment)
|
SecondaryNavigationViewModel(environment: environment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
class SettingsViewModel: ObservableObject {
|
class SecondaryNavigationViewModel: ObservableObject {
|
||||||
@Published private(set) var identity: Identity
|
@Published private(set) var identity: Identity
|
||||||
private let environment: IdentifiedEnvironment
|
private let environment: IdentifiedEnvironment
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ class SettingsViewModel: ObservableObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SettingsViewModel {
|
extension SecondaryNavigationViewModel {
|
||||||
func identitiesViewModel() -> IdentitiesViewModel {
|
func identitiesViewModel() -> IdentitiesViewModel {
|
||||||
IdentitiesViewModel(environment: environment)
|
IdentitiesViewModel(environment: environment)
|
||||||
}
|
}
|
97
Shared/Views/SecondaryNavigationView.swift
Normal file
97
Shared/Views/SecondaryNavigationView.swift
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
// Copyright © 2020 Metabolist. All rights reserved.
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import KingfisherSwiftUI
|
||||||
|
|
||||||
|
struct SecondaryNavigationView: View {
|
||||||
|
@StateObject var viewModel: SecondaryNavigationViewModel
|
||||||
|
@EnvironmentObject var rootViewModel: RootViewModel
|
||||||
|
@Environment(\.presentationMode) var presentationMode
|
||||||
|
@Environment(\.displayScale) var displayScale: CGFloat
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack(spacing: 0) {
|
||||||
|
NavigationView {
|
||||||
|
Form {
|
||||||
|
NavigationLink(
|
||||||
|
destination: IdentitiesView(viewModel: viewModel.identitiesViewModel())
|
||||||
|
.environmentObject(rootViewModel),
|
||||||
|
label: {
|
||||||
|
HStack {
|
||||||
|
KFImage(viewModel.identity.image,
|
||||||
|
options: .downsampled(dimension: 50, scaleFactor: displayScale))
|
||||||
|
VStack {
|
||||||
|
Text(viewModel.identity.handle)
|
||||||
|
.font(.headline)
|
||||||
|
.lineLimit(1)
|
||||||
|
.minimumScaleFactor(0.5)
|
||||||
|
Spacer()
|
||||||
|
Text("accounts").font(.subheadline)
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.navigationItems(presentationMode: presentationMode)
|
||||||
|
}
|
||||||
|
.navigationViewStyle
|
||||||
|
#if os(macOS)
|
||||||
|
Divider()
|
||||||
|
HStack {
|
||||||
|
Spacer()
|
||||||
|
Button(action: { presentationMode.wrappedValue.dismiss() }) {
|
||||||
|
Text("Done")
|
||||||
|
}
|
||||||
|
.keyboardShortcut(.defaultAction)
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
.frame
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private extension View {
|
||||||
|
func navigationItems(presentationMode: Binding<PresentationMode>) -> some View {
|
||||||
|
#if os(iOS)
|
||||||
|
return navigationBarTitleDisplayMode(.inline)
|
||||||
|
.toolbar {
|
||||||
|
ToolbarItem(placement: .cancellationAction) {
|
||||||
|
Button {
|
||||||
|
presentationMode.wrappedValue.dismiss()
|
||||||
|
} label: {
|
||||||
|
Image(systemName: "xmark.circle.fill")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
return self
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
var navigationViewStyle: some View {
|
||||||
|
#if os(iOS)
|
||||||
|
return navigationViewStyle(StackNavigationViewStyle())
|
||||||
|
#else
|
||||||
|
return self
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
var frame: some View {
|
||||||
|
#if os(macOS)
|
||||||
|
return frame(minWidth: 400, maxWidth: 600, minHeight: 350, maxHeight: 500)
|
||||||
|
#else
|
||||||
|
return self
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
struct SecondaryNavigationView_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
SecondaryNavigationView(viewModel: .development)
|
||||||
|
.environmentObject(RootViewModel.development)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -1,87 +0,0 @@
|
||||||
// Copyright © 2020 Metabolist. All rights reserved.
|
|
||||||
|
|
||||||
import SwiftUI
|
|
||||||
import KingfisherSwiftUI
|
|
||||||
|
|
||||||
struct SettingsView: View {
|
|
||||||
@StateObject var viewModel: SettingsViewModel
|
|
||||||
@EnvironmentObject var rootViewModel: RootViewModel
|
|
||||||
@Environment(\.presentationMode) var presentationMode
|
|
||||||
@Environment(\.displayScale) var displayScale: CGFloat
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
VStack(spacing: 0) {
|
|
||||||
NavigationView {
|
|
||||||
Form {
|
|
||||||
HStack {
|
|
||||||
KFImage(viewModel.identity.image,
|
|
||||||
options: .downsampled(dimension: 50, scaleFactor: displayScale))
|
|
||||||
Text(viewModel.identity.handle)
|
|
||||||
.font(.subheadline)
|
|
||||||
}
|
|
||||||
NavigationLink(
|
|
||||||
"accounts",
|
|
||||||
destination: IdentitiesView(
|
|
||||||
viewModel: viewModel.identitiesViewModel())
|
|
||||||
.environmentObject(rootViewModel))
|
|
||||||
}
|
|
||||||
.navigationBarTitleAndItems(presentationMode: presentationMode)
|
|
||||||
}
|
|
||||||
.navigationViewStyle
|
|
||||||
#if os(macOS)
|
|
||||||
Divider()
|
|
||||||
HStack {
|
|
||||||
Spacer()
|
|
||||||
Button(action: { presentationMode.wrappedValue.dismiss() }) {
|
|
||||||
Text("Done")
|
|
||||||
}
|
|
||||||
.keyboardShortcut(.defaultAction)
|
|
||||||
}
|
|
||||||
.padding()
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
.frame
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private extension View {
|
|
||||||
func navigationBarTitleAndItems(presentationMode: Binding<PresentationMode>) -> some View {
|
|
||||||
#if os(iOS)
|
|
||||||
return navigationBarTitle(Text("settings"), displayMode: .inline)
|
|
||||||
.navigationBarItems(
|
|
||||||
leading: Button {
|
|
||||||
presentationMode.wrappedValue.dismiss()
|
|
||||||
} label: {
|
|
||||||
Image(systemName: "xmark.circle.fill").imageScale(.large)
|
|
||||||
})
|
|
||||||
#else
|
|
||||||
return self
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
var navigationViewStyle: some View {
|
|
||||||
#if os(iOS)
|
|
||||||
return navigationViewStyle(StackNavigationViewStyle())
|
|
||||||
#else
|
|
||||||
return self
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
var frame: some View {
|
|
||||||
#if os(macOS)
|
|
||||||
return frame(minWidth: 400, maxWidth: 600, minHeight: 350, maxHeight: 500)
|
|
||||||
#else
|
|
||||||
return self
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
struct SettingsView_Previews: PreviewProvider {
|
|
||||||
static var previews: some View {
|
|
||||||
SettingsView(viewModel: .development)
|
|
||||||
.environmentObject(RootViewModel.development)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -23,7 +23,7 @@ struct TabNavigation: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.sheet(isPresented: $viewModel.presentingSettings) {
|
.sheet(isPresented: $viewModel.presentingSettings) {
|
||||||
SettingsView(viewModel: viewModel.settingsViewModel())
|
SecondaryNavigationView(viewModel: viewModel.settingsViewModel())
|
||||||
.environmentObject(rootViewModel)
|
.environmentObject(rootViewModel)
|
||||||
}
|
}
|
||||||
.alertItem($viewModel.alertItem)
|
.alertItem($viewModel.alertItem)
|
||||||
|
|
|
@ -84,7 +84,7 @@ private extension SidebarNavigation {
|
||||||
.buttonStyle(PlainButtonStyle())
|
.buttonStyle(PlainButtonStyle())
|
||||||
}
|
}
|
||||||
.sheet(isPresented: $viewModel.presentingSettings) {
|
.sheet(isPresented: $viewModel.presentingSettings) {
|
||||||
SettingsView(viewModel: viewModel.settingsViewModel())
|
SecondaryNavigationView(viewModel: viewModel.settingsViewModel())
|
||||||
.environmentObject(viewModel)
|
.environmentObject(viewModel)
|
||||||
.environmentObject(rootViewModel)
|
.environmentObject(rootViewModel)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue