diff --git a/Shared/Account/AccountLoginView.swift b/Shared/Account/AccountLoginView.swift index d89211b..fc360ab 100644 --- a/Shared/Account/AccountLoginView.swift +++ b/Shared/Account/AccountLoginView.swift @@ -1,102 +1,125 @@ import SwiftUI struct AccountLoginView: View { @State private var username: String = "" @State private var password: String = "" @State private var server: String = "" @State private var isShowingAlert: Bool = false @State private var alertMessage: String = "" @Binding var accountModel: AccountModel @Binding var isLoggedIn: Bool @Binding var isLoggingIn: Bool var body: some View { VStack { HStack { Image(systemName: "person.circle") .foregroundColor(.gray) + #if os(iOS) TextField("Username", text: $username) + .keyboardType(.emailAddress) + .autocapitalization(.none) + .disableAutocorrection(true) + .textFieldStyle(RoundedBorderTextFieldStyle()) + #else + TextField("Username", text: $username) + #endif } HStack { Image(systemName: "lock.circle") .foregroundColor(.gray) + #if os(iOS) + SecureField("Password", text: $password) + .autocapitalization(.none) + .disableAutocorrection(true) + .textFieldStyle(RoundedBorderTextFieldStyle()) + #else SecureField("Password", text: $password) + #endif } HStack { Image(systemName: "link.circle") .foregroundColor(.gray) + #if os(iOS) + TextField("Server URL", text: $server) + .keyboardType(.URL) + .autocapitalization(.none) + .disableAutocorrection(true) + .textFieldStyle(RoundedBorderTextFieldStyle()) + #else TextField("Server URL", text: $server) + #endif } Spacer() if isLoggingIn { ProgressView("Logging in...") } else { Button(action: { accountModel.login( to: server, as: username, password: password, completion: loginHandler ) isLoggingIn = true }, label: { Text("Login") }).disabled(isLoggedIn) } } .alert(isPresented: $isShowingAlert) { Alert( title: Text("Error Logging In"), message: Text(alertMessage), dismissButton: .default(Text("OK")) ) } } func loginHandler(result: Result) { do { _ = try result.get() isLoggedIn = true isLoggingIn = false } catch AccountError.serverNotFound { alertMessage = """ The server could not be found. Please check that you've entered the information correctly and try again. """ isLoggedIn = false isLoggingIn = false isShowingAlert = true } catch AccountError.invalidCredentials { alertMessage = """ Invalid username or password. Please check that you've entered the information correctly and try again. """ isLoggedIn = false isLoggingIn = false isShowingAlert = true } catch { alertMessage = "An unknown error occurred. Please try again." isLoggedIn = false isLoggingIn = false isShowingAlert = true } } } struct AccountLoginView_LoggedOutPreviews: PreviewProvider { static var previews: some View { AccountLoginView( accountModel: .constant(AccountModel()), isLoggedIn: .constant(false), isLoggingIn: .constant(false) ) } } struct AccountLoginView_LoggingInPreviews: PreviewProvider { static var previews: some View { AccountLoginView( accountModel: .constant(AccountModel()), isLoggedIn: .constant(false), isLoggingIn: .constant(true) ) } } diff --git a/Shared/Account/AccountView.swift b/Shared/Account/AccountView.swift index f168b55..ef838c3 100644 --- a/Shared/Account/AccountView.swift +++ b/Shared/Account/AccountView.swift @@ -1,21 +1,25 @@ import SwiftUI struct AccountView: View { @State private var accountModel = AccountModel() @State private var isLoggingIn: Bool = false @State private var isLoggedIn: Bool = false var body: some View { if isLoggedIn { - AccountLogoutView(accountModel: $accountModel, isLoggedIn: $isLoggedIn, isLoggingIn: $isLoggingIn) + HStack { + Spacer() + AccountLogoutView(accountModel: $accountModel, isLoggedIn: $isLoggedIn, isLoggingIn: $isLoggingIn) + Spacer() + } } else { AccountLoginView(accountModel: $accountModel, isLoggedIn: $isLoggedIn, isLoggingIn: $isLoggingIn) } } } struct AccountLogin_Previews: PreviewProvider { static var previews: some View { AccountView() } } diff --git a/Shared/Preferences/PreferencesView.swift b/Shared/Preferences/PreferencesView.swift index 8a8f9ee..290dd46 100644 --- a/Shared/Preferences/PreferencesView.swift +++ b/Shared/Preferences/PreferencesView.swift @@ -1,29 +1,28 @@ import SwiftUI struct PreferencesView: View { @State private var appearance: Int = 0 var body: some View { #if os(iOS) Picker(selection: $appearance, label: Text("Appearance")) { Text("System").tag(0) Text("Light Mode").tag(1) Text("Dark Mode").tag(2) } .pickerStyle(SegmentedPickerStyle()) #elseif os(macOS) - Picker(selection: $appearance, label: EmptyView()) { + Picker(selection: $appearance, label: Text("Appearance")) { Text("System").tag(0) Text("Light Mode").tag(1) Text("Dark Mode").tag(2) } - .pickerStyle(RadioGroupPickerStyle()) #endif } } struct SwiftUIView_Previews: PreviewProvider { static var previews: some View { PreferencesView() } } diff --git a/macOS/Settings/SettingsView.swift b/macOS/Settings/SettingsView.swift index b60095a..40af22c 100644 --- a/macOS/Settings/SettingsView.swift +++ b/macOS/Settings/SettingsView.swift @@ -1,43 +1,41 @@ import SwiftUI struct SettingsView: View { @State var selectedView = 0 var body: some View { TabView(selection: $selectedView) { Form { - Section(header: Text("Log in to your account")) { + Section(header: Text("Login Details")) { AccountView() } } .tabItem { Image(systemName: "person.crop.circle") Text("Account") } .tag(0) - Form { - Section(header: Text("Appearance")) { - PreferencesView() - Spacer() - } + VStack { + PreferencesView() + Spacer() } .tabItem { Image(systemName: "gear") Text("Preferences") } .tag(1) } } } struct SettingsView_AccountTabPreviews: PreviewProvider { static var previews: some View { SettingsView(selectedView: 0) } } struct SettingsView_PreferencesTabPreviews: PreviewProvider { static var previews: some View { SettingsView(selectedView: 1) } }