summaryrefslogtreecommitdiff
path: root/Hutch/Views/More/AddAccountView.swift
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-04-01 11:36:01 -0500
committerChristian Cleberg <[email protected]>2026-04-01 11:37:35 -0500
commit7b59ee6098c4649a51cafe4b58e3a675567e2c08 (patch)
tree3ec7aa3c843c13d24a164d89f1d724ac48d2210a /Hutch/Views/More/AddAccountView.swift
parent3f03c433a7435e283244e94f09bd513bd45f3202 (diff)
downloadhutch-2.6.0.tar.gz
hutch-2.6.0.tar.bz2
hutch-2.6.0.zip
feat: add multi-account supportv2.6.0
Implements: https://todo.sr.ht/~ccleberg/Hutch/11
Diffstat (limited to 'Hutch/Views/More/AddAccountView.swift')
-rw-r--r--Hutch/Views/More/AddAccountView.swift59
1 files changed, 59 insertions, 0 deletions
diff --git a/Hutch/Views/More/AddAccountView.swift b/Hutch/Views/More/AddAccountView.swift
new file mode 100644
index 0000000..cfaa2b2
--- /dev/null
+++ b/Hutch/Views/More/AddAccountView.swift
@@ -0,0 +1,59 @@
+import SwiftUI
+
+struct AddAccountView: View {
+ @Environment(AppState.self) private var appState
+ @Environment(\.dismiss) private var dismiss
+
+ @State private var token = ""
+ @State private var isConnecting = false
+ @State private var errorMessage: String?
+
+ var body: some View {
+ NavigationStack {
+ Form {
+ Section {
+ SecureField("Personal Access Token", text: $token)
+ .autocorrectionDisabled()
+ .textInputAutocapitalization(.never)
+ } footer: {
+ Text("Generate a token at meta.sr.ht → OAuth2 clients.")
+ }
+
+ if let errorMessage {
+ Section {
+ Text(errorMessage)
+ .foregroundStyle(.red)
+ }
+ }
+ }
+ .navigationTitle("Add Account")
+ .navigationBarTitleDisplayMode(.inline)
+ .toolbar {
+ ToolbarItem(placement: .cancellationAction) {
+ Button("Cancel") { dismiss() }
+ .disabled(isConnecting)
+ }
+ ToolbarItem(placement: .confirmationAction) {
+ Button("Connect") { connect() }
+ .disabled(token.trimmingCharacters(in: .whitespaces).isEmpty || isConnecting)
+ }
+ }
+ .interactiveDismissDisabled(isConnecting)
+ }
+ }
+
+ private func connect() {
+ isConnecting = true
+ errorMessage = nil
+ let trimmed = token.trimmingCharacters(in: .whitespaces)
+ Task {
+ do {
+ try await appState.addAccount(token: trimmed)
+ dismiss()
+ } catch {
+ errorMessage = error.localizedDescription
+ }
+ isConnecting = false
+ }
+ }
+}