Files
InvestmentTrackerApp/PortfolioJournal/Views/Accounts/AccountsView.swift
T
alexandrev-tibco a8a9ad64f3 Xcode 27: compila sin warnings y migra API deprecadas de SwiftUI
- Imports de CoreData que faltaban (MemberImportVisibility) en AccountsView,
  ImportDataView, ChartsContainerView y AddSourceView.
- Aislamiento MainActor: IsolatedDefaultValues en el target de la app,
  LinearGradient @MainActor, WatchSyncMessage nonisolated, closures de
  ReviewPromptService/MonthlyCheckInStore/AppIntents.
- Warnings de valores sin usar (SnapshotGapDetector, DashboardLayoutStore,
  OnboardingView, GoalEditorView, CoreDataStack, SettingsViewModel).
- foregroundColor→foregroundStyle, cornerRadius→clipShape,
  navigationBarLeading/Trailing→topBarLeading/Trailing,
  Task.sleep(nanoseconds:)→sleep(for:), NavigationLink(isActive:)→
  navigationDestination(isPresented:).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F1u4K16xy7eQVtgsYNZ9Vn
2026-09-16 11:44:49 +02:00

128 lines
5.0 KiB
Swift

import SwiftUI
import CoreData
struct AccountsView: View {
@EnvironmentObject private var iapService: IAPService
@EnvironmentObject private var accountStore: AccountStore
@StateObject private var accountRepository = AccountRepository()
@State private var showingAddAccount = false
@State private var selectedAccount: Account?
@State private var showingPaywall = false
@State private var accountToDelete: Account?
@State private var showingDeleteBlocked = false
private var availableAccounts: [Account] {
accountRepository.accounts.filter { $0.safeId != nil }
}
var body: some View {
ZStack {
AppBackground()
List {
Section {
ForEach(availableAccounts, id: \.objectID) { account in
let canDelete = accountRepository.canDeleteAccount(account)
Button {
selectedAccount = account
} label: {
HStack {
VStack(alignment: .leading) {
HStack(spacing: 4) {
Text(account.name)
.font(.headline)
if account.isDefaultAccount {
Image(systemName: "star.fill")
.font(.caption2)
.foregroundStyle(Color.appWarning)
}
}
Text(account.currencyCode ?? AppSettings.getOrCreate(in: CoreDataStack.shared.viewContext).currency)
.font(.caption)
.foregroundStyle(.secondary)
}
Spacer()
if accountStore.selectedAccount?.safeId == account.safeId && !accountStore.showAllAccounts {
Image(systemName: "checkmark.circle.fill")
.foregroundStyle(Color.appPrimary)
}
}
}
.swipeActions(edge: .trailing) {
if canDelete {
Button(role: .destructive) {
accountToDelete = account
} label: {
Label("Delete", systemImage: "trash")
}
}
}
}
} header: {
Text("Accounts")
} footer: {
Text(iapService.isPremium ? "Create multiple accounts for business, family, or goals. The Default account cannot be deleted." : "Free users can create one account.")
}
}
.scrollContentBackground(.hidden)
}
.navigationTitle("Accounts")
.confirmationDialog(
"Delete Account",
isPresented: Binding(
get: { accountToDelete != nil },
set: { if !$0 { accountToDelete = nil } }
),
titleVisibility: .visible
) {
Button("Delete", role: .destructive) {
guard let accountToDelete else { return }
if accountRepository.canDeleteAccount(accountToDelete) {
accountRepository.deleteAccount(accountToDelete)
} else {
showingDeleteBlocked = true
}
self.accountToDelete = nil
}
} message: {
Text("This will remove the account and all its sources and snapshots.")
}
.alert("Cannot Delete Account", isPresented: $showingDeleteBlocked) {
Button("OK") {}
} message: {
Text("The Default account cannot be deleted. You must keep at least one account.")
}
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button {
if accountStore.canAddAccount() {
showingAddAccount = true
} else {
showingPaywall = true
}
} label: {
Image(systemName: "plus")
}
}
}
.sheet(isPresented: $showingAddAccount) {
AccountEditorView(account: nil)
}
.sheet(isPresented: $showingPaywall) {
PaywallView()
}
.sheet(item: $selectedAccount) { account in
AccountEditorView(account: account)
}
.onAppear {
accountRepository.fetchAccounts()
}
}
}
#Preview {
AccountsView()
.environmentObject(IAPService())
.environmentObject(AccountStore(iapService: IAPService()))
}