summaryrefslogtreecommitdiff
path: root/Jel/Views/SignIn/SignInToServerView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Jel/Views/SignIn/SignInToServerView.swift')
-rw-r--r--Jel/Views/SignIn/SignInToServerView.swift79
1 files changed, 79 insertions, 0 deletions
diff --git a/Jel/Views/SignIn/SignInToServerView.swift b/Jel/Views/SignIn/SignInToServerView.swift
new file mode 100644
index 0000000..ae8d82d
--- /dev/null
+++ b/Jel/Views/SignIn/SignInToServerView.swift
@@ -0,0 +1,79 @@
+//
+// SignInToServerView.swift
+// Jel
+//
+// Created by zerocool on 12/12/23.
+//
+
+import SwiftUI
+
+struct SignInToServerView: View {
+ @EnvironmentObject var jellyfinClient: JellyfinClientController
+ @ObservedObject var authState: AuthStateController
+
+ @State var username: String = ""
+ @State var password: String = ""
+
+ @State var isLoading: Bool = false
+ @State var hasError: Bool = false
+
+ var body: some View {
+ VStack {
+ Text("Sign in")
+ .font(.title)
+ TextField(text: $username) {
+ Text("Username")
+ }
+ .textContentType(.username)
+
+ SecureField(text: $password) {
+ Text("Password")
+ }
+ .textContentType(.password)
+ .onSubmit {
+ Task {
+ await logInToServer()
+ }
+ }
+
+ if !isLoading {
+ Button {
+ Task {
+ await logInToServer()
+ }
+ } label: {
+ Text("Sign in")
+ }
+ .disabled(username.isEmpty || password.isEmpty)
+ } else {
+ ProgressView()
+ .progressViewStyle(.circular)
+ }
+
+ if hasError {
+ Text("Unable to sign in")
+ .font(.callout)
+ .foregroundStyle(.red)
+ }
+ }
+ .padding()
+ .textFieldStyle(.roundedBorder)
+ .textInputAutocapitalization(.never)
+ .disabled(isLoading)
+ }
+
+ func logInToServer() async {
+ isLoading = true
+ hasError = false
+ do {
+ try await jellyfinClient.signIn(username: username, pw: password)
+ } catch {
+ hasError = true
+ }
+ isLoading = false
+ }
+}
+
+#Preview {
+ SignInToServerView(authState: AuthStateController())
+}