Files
InvestmentTrackerApp/PortfolioJournal/Utilities/DashboardLayoutStore.swift
T
alexandrev-tibco be7119f4b9 Calm 2.0 Fase 1: sistema de diseño limpio + Home en 3 zonas (1.5.0 build 51)
Sistema:
- AppBackground: fuera gradiente + formas decorativas → systemGroupedBackground
  plano en toda la app. La profundidad la da la jerarquía, no la decoración.

Home (3 zonas: estado / acción / contexto):
- TotalValueCard: hero tipográfico — número 44pt rounded sobre card limpia,
  chip de delta semántico (verde/rojo), sparkline de evolución 56pt estilo
  Stocks, fila secundaria YoY / inception / forecast. Fuera el gradiente azul.
- MonthlyCheckInCard state-driven: pendiente → protagonista con progreso real
  de fuentes (N de M) y un CTA; completado → fila discreta con checkmark,
  próximo check-in y streak integrado. En iPad va a ancho completo bajo el
  hero (zona de acción), fuera del grid.
- InsightsRow: de carrusel de chips a un insight único rotatorio (tap para
  ciclar, dots de posición).
- Eliminados del top: streak badge (vive en el check-in) y banner de pending
  updates (el progreso del check-in lo comunica).
- Defaults nuevos: momentumStreaks/pendingUpdates/periodReturns/monthlySummary
  ocultos por defecto (siguen disponibles en Customize; configs guardadas de
  usuarios existentes se respetan).
- Strings nuevas en 7 idiomas (checkin_done_*, checkin_sources_progress).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WoScpmHdVj1aUf4rAp6hbe
2026-07-08 23:58:06 +02:00

127 lines
4.1 KiB
Swift

import Foundation
struct DashboardSectionConfig: Identifiable, Codable, Hashable {
let id: String
var isVisible: Bool
var isCollapsed: Bool
var columnSpan: Int
init(id: String, isVisible: Bool, isCollapsed: Bool, columnSpan: Int = 1) {
self.id = id
self.isVisible = isVisible
self.isCollapsed = isCollapsed
self.columnSpan = columnSpan
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decode(String.self, forKey: .id)
isVisible = try container.decode(Bool.self, forKey: .isVisible)
isCollapsed = try container.decode(Bool.self, forKey: .isCollapsed)
columnSpan = try container.decodeIfPresent(Int.self, forKey: .columnSpan) ?? 1
}
}
enum DashboardSection: String, CaseIterable, Identifiable {
case totalValue
case monthlyCheckIn
case momentumStreaks
case monthlySummary
case evolution
case categoryBreakdown
case goals
case pendingUpdates
case periodReturns
case contributionsVsReturns
var id: String { rawValue }
var title: String {
switch self {
case .totalValue:
return "Total Portfolio Value"
case .monthlyCheckIn:
return "Monthly Check-in"
case .momentumStreaks:
return "Momentum & Streaks"
case .monthlySummary:
return "Cashflow vs Growth"
case .evolution:
return "Portfolio Evolution"
case .categoryBreakdown:
return "By Category"
case .goals:
return "Goals"
case .pendingUpdates:
return "Pending Updates"
case .periodReturns:
return "Returns"
case .contributionsVsReturns:
return "Invested vs. Returns"
}
}
}
enum DashboardLayoutStore {
private static let storageKey = "dashboardLayoutConfig"
static func load() -> [DashboardSectionConfig] {
let defaults = defaultConfigs()
guard let data = UserDefaults.standard.data(forKey: storageKey),
let decoded = try? JSONDecoder().decode([DashboardSectionConfig].self, from: data) else {
return defaults
}
var merged: [DashboardSectionConfig] = []
for config in decoded {
if let section = DashboardSection(rawValue: config.id) {
merged.append(config)
} else {
continue
}
}
for section in DashboardSection.allCases {
if !merged.contains(where: { $0.id == section.id }) {
merged.append(defaults.first(where: { $0.id == section.id }) ?? DashboardSectionConfig(
id: section.id,
isVisible: true,
isCollapsed: false
))
}
}
return merged
}
static func save(_ configs: [DashboardSectionConfig]) {
guard let data = try? JSONEncoder().encode(configs) else { return }
UserDefaults.standard.set(data, forKey: storageKey)
}
static func reset() {
UserDefaults.standard.removeObject(forKey: storageKey)
}
/// Calm 2.0 defaults: three zones state (total value), action (check-in),
/// context. Redundant cards start hidden: pending updates and streaks now
/// live inside the check-in card, period returns inside the hero. All remain
/// available via Customize.
private static let hiddenByDefault: Set<DashboardSection> = [
.momentumStreaks, .pendingUpdates, .periodReturns, .monthlySummary
]
private static func defaultConfigs() -> [DashboardSectionConfig] {
DashboardSection.allCases.map { section in
DashboardSectionConfig(
id: section.id,
isVisible: !hiddenByDefault.contains(section),
isCollapsed: false,
// The check-in row is slim full width on the iPad grid so it
// reads as the "action" zone instead of leaving a gap cell.
columnSpan: section == .monthlyCheckIn ? 2 : 1
)
}
}
}