Files
NetNewsWire/iOS/Inspector/AccountInspectorView.swift
T
Brent Simmons 23b691303f
CI / SwiftLint (push) Canceled after 0s
CI / macOS Tests (push) Canceled after 0s
CI / iOS Simulator Tests (push) Canceled after 0s
Remove setting for syncing unread content to iCloud.
2026-12-03 16:31:10 -08:00

149 lines
3.7 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// AccountInspectorView.swift
// NetNewsWire-iOS
//
// Created by Brent Simmons on 11/14/26.
// Copyright © 2026 Ranchero Software. All rights reserved.
//
import SwiftUI
import RSCore
import Account
/// An account’s name, active state, credentials, and removal.
struct AccountInspectorView: View {
let account: Account
/// Shown as a sheet with a Done button, rather than pushed onto Settings.
let isModal: Bool
@Environment(\.dismiss) private var dismiss
@State private var name: String
@State private var isActive: Bool
@State private var isShowingCredentials = false
@State private var isShowingRemoveConfirmation = false
@State private var isShowingLimitationsAndSolutions = false
init(account: Account, isModal: Bool) {
self.account = account
self.isModal = isModal
self._name = State(initialValue: account.name ?? "")
self._isActive = State(initialValue: account.isActive)
}
var body: some View {
List {
Section {
TextField(account.defaultName, text: $name)
.textInputAutocapitalization(.words)
Toggle(String(localized: "Active", comment: "Active"), isOn: $isActive)
} header: {
AccountIconHeader(accountType: account.type)
}
if showsCredentials {
Section {
Button(String(localized: "Credentials", comment: "Credentials")) {
isShowingCredentials = true
}
}
}
if showsRemoveAccount {
Section {
Button(role: .destructive) {
isShowingRemoveConfirmation = true
} label: {
Text("Remove Account", comment: "Remove Account")
.frame(maxWidth: .infinity)
}
} footer: {
if account.type == .cloudKit {
Button(String(localized: "How to Optimize iCloud Syncing", comment: "Help link")) {
isShowingLimitationsAndSolutions = true
}
.font(.subheadline)
.foregroundStyle(.tint)
.frame(maxWidth: .infinity)
}
}
}
}
.settingsAccentTint()
.navigationTitle(account.nameForDisplay)
.toolbar {
if isModal {
ToolbarItem(placement: .confirmationAction) {
doneButton
}
}
}
.onChange(of: name) {
saveName()
}
.onChange(of: isActive) {
account.isActive = isActive
}
.sheet(isPresented: $isShowingCredentials) {
account.credentialsView()
}
.sheet(isPresented: $isShowingLimitationsAndSolutions) {
SafariView(url: CloudKitWebDocumentation.limitationsAndSolutionsURL)
}
.alert(String(localized: "Remove Account", comment: "Remove Account"), isPresented: $isShowingRemoveConfirmation) {
Button(String(localized: "Cancel", comment: "Cancel button"), role: .cancel) {
}
Button(String(localized: "Remove", comment: "Remove"), role: .destructive) {
removeAccount()
}
} message: {
Text(removeAccountMessage)
}
}
}
// MARK: - Private
private extension AccountInspectorView {
var isDefaultAccount: Bool {
account == AccountManager.shared.defaultAccount
}
var showsCredentials: Bool {
!isDefaultAccount && account.hasCredentialsView
}
var showsRemoveAccount: Bool {
!isDefaultAccount
}
var removeAccountMessage: String {
switch account.type {
case .feedly:
NSLocalizedString("Are you sure you want to remove this account? NetNewsWire will no longer be able to access articles and feeds unless the account is added again.", comment: "Log Out and Remove Account")
default:
NSLocalizedString("Are you sure you want to remove this account? This cannot be undone.", comment: "Remove Account")
}
}
@ViewBuilder var doneButton: some View {
if #available(iOS 26, *) {
Button(role: .confirm) {
dismiss()
}
} else {
Button(String(localized: "Done", comment: "Done")) {
dismiss()
}
}
}
func saveName() {
account.name = name.isEmpty ? nil : name
}
func removeAccount() {
AccountManager.shared.deleteAccount(account)
dismiss()
}
}