mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-30 17:29:23 +00:00
Add AccountSetupSheet which is shared by Local, CloudKit, and credentials sheets.
This commit is contained in:
1 parent
ccb116ed37
commit
a2389fa7ee
4 files changed
+119
-109
No files matched your search
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// AccountSetupSheet.swift
|
||||
// NetNewsWire-iOS
|
||||
//
|
||||
// Created by Brent Simmons on 10/9/26.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
|
||||
/// The frame shared by the account setup sheets: a form titled with the account name and a Cancel button.
|
||||
/// While `isWorking` is true, a progress indicator shows and the sheet can’t be canceled or swiped away.
|
||||
struct AccountSetupSheet<Content: View>: View {
|
||||
|
||||
let accountType: AccountType
|
||||
let isWorking: Bool
|
||||
let content: Content
|
||||
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
init(accountType: AccountType, isWorking: Bool = false, @ViewBuilder content: () -> Content) {
|
||||
self.accountType = accountType
|
||||
self.isWorking = isWorking
|
||||
self.content = content()
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
Form {
|
||||
content
|
||||
}
|
||||
.navigationTitle(Text(verbatim: accountType.displayName))
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button(NSLocalizedString("Cancel", comment: "Cancel button"), role: .cancel) {
|
||||
dismiss()
|
||||
}
|
||||
.disabled(isWorking)
|
||||
}
|
||||
ToolbarItem(placement: .topBarTrailing) {
|
||||
if isWorking {
|
||||
ProgressView()
|
||||
}
|
||||
}
|
||||
}
|
||||
.interactiveDismissDisabled(isWorking)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,43 +19,32 @@ struct CloudKitAccountView: View {
|
||||
@State private var isShowingHelp = false
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
Form {
|
||||
Section {
|
||||
Button(NSLocalizedString("Use iCloud", comment: "Use iCloud button")) {
|
||||
addAccount()
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
} header: {
|
||||
AccountIconHeader(accountType: .cloudKit)
|
||||
} footer: {
|
||||
AccountSheetFooter(text: NSLocalizedString("NetNewsWire will use your iCloud account to sync your subscriptions across your Mac and iOS devices.", comment: "iCloud"), linkTitle: CloudKitWebDocumentation.limitationsAndSolutionsText) {
|
||||
isShowingHelp = true
|
||||
}
|
||||
AccountSetupSheet(accountType: .cloudKit) {
|
||||
Section {
|
||||
Button(NSLocalizedString("Use iCloud", comment: "Use iCloud button")) {
|
||||
addAccount()
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
} header: {
|
||||
AccountIconHeader(accountType: .cloudKit)
|
||||
} footer: {
|
||||
AccountSheetFooter(text: NSLocalizedString("NetNewsWire will use your iCloud account to sync your subscriptions across your Mac and iOS devices.", comment: "iCloud"), linkTitle: CloudKitWebDocumentation.limitationsAndSolutionsText) {
|
||||
isShowingHelp = true
|
||||
}
|
||||
}
|
||||
.navigationTitle(Text(verbatim: AccountType.cloudKit.displayName))
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button(NSLocalizedString("Cancel", comment: "Cancel button"), role: .cancel) {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
.alert(isPresented: isShowingiCloudDriveError, error: iCloudDriveError) { _ in
|
||||
Button(NSLocalizedString("Open Settings", comment: "Open Settings button")) {
|
||||
AddCloudKitAccountUtilities.openiCloudSettings()
|
||||
}
|
||||
.alert(isPresented: isShowingiCloudDriveError, error: iCloudDriveError) { _ in
|
||||
Button(NSLocalizedString("Open Settings", comment: "Open Settings button")) {
|
||||
AddCloudKitAccountUtilities.openiCloudSettings()
|
||||
}
|
||||
Button(NSLocalizedString("Cancel", comment: "Cancel button"), role: .cancel) {
|
||||
iCloudDriveError = nil
|
||||
}
|
||||
} message: { error in
|
||||
Text(verbatim: error.recoverySuggestion ?? "")
|
||||
}
|
||||
.sheet(isPresented: $isShowingHelp) {
|
||||
SafariView(url: CloudKitWebDocumentation.limitationsAndSolutionsURL)
|
||||
Button(NSLocalizedString("Cancel", comment: "Cancel button"), role: .cancel) {
|
||||
iCloudDriveError = nil
|
||||
}
|
||||
} message: { error in
|
||||
Text(verbatim: error.recoverySuggestion ?? "")
|
||||
}
|
||||
.sheet(isPresented: $isShowingHelp) {
|
||||
SafariView(url: CloudKitWebDocumentation.limitationsAndSolutionsURL)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,60 +44,42 @@ struct CredentialsAccountView: View {
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
Form {
|
||||
Section {
|
||||
TextField(accountType.usernamePlaceholder, text: $username)
|
||||
.textContentType(.username)
|
||||
.keyboardType(.emailAddress)
|
||||
AccountSetupSheet(accountType: accountType, isWorking: isValidating) {
|
||||
Section {
|
||||
TextField(accountType.usernamePlaceholder, text: $username)
|
||||
.textContentType(.username)
|
||||
.keyboardType(.emailAddress)
|
||||
.textInputAutocapitalization(.never)
|
||||
.autocorrectionDisabled()
|
||||
passwordRow
|
||||
if accountType.needsAPIURL {
|
||||
TextField(NSLocalizedString("API URL: https://fresh.rss.net/api/greader.php", comment: "FreshRSS API Helper"), text: $apiURLString)
|
||||
.textContentType(.URL)
|
||||
.keyboardType(.URL)
|
||||
.textInputAutocapitalization(.never)
|
||||
.autocorrectionDisabled()
|
||||
passwordRow
|
||||
if accountType.needsAPIURL {
|
||||
TextField(NSLocalizedString("API URL: https://fresh.rss.net/api/greader.php", comment: "FreshRSS API Helper"), text: $apiURLString)
|
||||
.textContentType(.URL)
|
||||
.keyboardType(.URL)
|
||||
.textInputAutocapitalization(.never)
|
||||
.autocorrectionDisabled()
|
||||
}
|
||||
} header: {
|
||||
AccountIconHeader(accountType: accountType)
|
||||
}
|
||||
Section {
|
||||
Button(actionTitle) {
|
||||
Task {
|
||||
await submit()
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.disabled(!canSubmit || isValidating)
|
||||
} footer: {
|
||||
AccountSheetFooter(text: accountType.footerText, linkTitle: accountType.signUpTitle) {
|
||||
isShowingSignUp = true
|
||||
} header: {
|
||||
AccountIconHeader(accountType: accountType)
|
||||
}
|
||||
Section {
|
||||
Button(actionTitle) {
|
||||
Task {
|
||||
await submit()
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.disabled(!canSubmit || isValidating)
|
||||
} footer: {
|
||||
AccountSheetFooter(text: accountType.footerText, linkTitle: accountType.signUpTitle) {
|
||||
isShowingSignUp = true
|
||||
}
|
||||
}
|
||||
.navigationTitle(Text(verbatim: accountType.displayName))
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button(NSLocalizedString("Cancel", comment: "Cancel button"), role: .cancel) {
|
||||
dismiss()
|
||||
}
|
||||
.disabled(isValidating)
|
||||
}
|
||||
ToolbarItem(placement: .topBarTrailing) {
|
||||
if isValidating {
|
||||
ProgressView()
|
||||
}
|
||||
}
|
||||
}
|
||||
.interactiveDismissDisabled(isValidating)
|
||||
.errorAlert(message: $errorMessage)
|
||||
.sheet(isPresented: $isShowingSignUp) {
|
||||
if let signUpURL = accountType.signUpURL {
|
||||
SafariView(url: signUpURL)
|
||||
}
|
||||
}
|
||||
.errorAlert(message: $errorMessage)
|
||||
.sheet(isPresented: $isShowingSignUp) {
|
||||
if let signUpURL = accountType.signUpURL {
|
||||
SafariView(url: signUpURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,37 +18,26 @@ struct LocalAccountView: View {
|
||||
@FocusState private var isNameFieldFocused: Bool
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
Form {
|
||||
Section {
|
||||
TextField(NSLocalizedString("Name", comment: "Name field placeholder"), text: $name)
|
||||
.textInputAutocapitalization(.words)
|
||||
.focused($isNameFieldFocused)
|
||||
.onSubmit {
|
||||
isNameFieldFocused = false
|
||||
}
|
||||
} header: {
|
||||
AccountIconHeader(accountType: .onMyMac)
|
||||
}
|
||||
Section {
|
||||
Button(NSLocalizedString("Add Account", comment: "Add Account")) {
|
||||
addAccount()
|
||||
AccountSetupSheet(accountType: .onMyMac) {
|
||||
Section {
|
||||
TextField(NSLocalizedString("Name", comment: "Name field placeholder"), text: $name)
|
||||
.textInputAutocapitalization(.words)
|
||||
.focused($isNameFieldFocused)
|
||||
.onSubmit {
|
||||
isNameFieldFocused = false
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
} footer: {
|
||||
Text(NSLocalizedString("Local accounts do not sync your feeds across devices.", comment: "Local"))
|
||||
.multilineTextAlignment(.center)
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
} header: {
|
||||
AccountIconHeader(accountType: .onMyMac)
|
||||
}
|
||||
.navigationTitle(Text(verbatim: AccountType.onMyMac.displayName))
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button(NSLocalizedString("Cancel", comment: "Cancel button"), role: .cancel) {
|
||||
dismiss()
|
||||
}
|
||||
Section {
|
||||
Button(NSLocalizedString("Add Account", comment: "Add Account")) {
|
||||
addAccount()
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
} footer: {
|
||||
Text(NSLocalizedString("Local accounts do not sync your feeds across devices.", comment: "Local"))
|
||||
.multilineTextAlignment(.center)
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user