From 30382f6f5297d32468abb23566c957042dc9b4ae Mon Sep 17 00:00:00 2001 From: Robin Kutesa Date: Mon, 1 Jun 2026 01:50:37 +0300 Subject: [PATCH] Replace hardcoded name/initials with live auth user data Profile header and ProfileStatsSheet now read displayName and email from AuthManager.shared instead of hardcoded "Robin Kutesa" / "RK". Initials are computed dynamically from the user's display name. Co-Authored-By: Kutesir --- KisaniCal/Views/SettingsView.swift | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/KisaniCal/Views/SettingsView.swift b/KisaniCal/Views/SettingsView.swift index 29b33f5..cc8a17b 100644 --- a/KisaniCal/Views/SettingsView.swift +++ b/KisaniCal/Views/SettingsView.swift @@ -4,6 +4,7 @@ struct SettingsView: View { @Environment(\.colorScheme) var cs @EnvironmentObject var workoutVM: WorkoutViewModel @EnvironmentObject var taskVM: TaskViewModel + @ObservedObject private var auth = AuthManager.shared // Persisted settings @AppStorage("appearanceMode") private var appearanceMode = 0 @@ -59,7 +60,7 @@ struct SettingsView: View { HStack(spacing: 12) { ZStack { Circle().fill(AppColors.accentSoft) - Text("RK") + Text(initials(for: auth.currentUser?.displayName)) .font(AppFonts.sans(15, weight: .bold)) .foregroundColor(AppColors.accent) } @@ -67,7 +68,7 @@ struct SettingsView: View { .overlay(Circle().stroke(AppColors.accent.opacity(0.18), lineWidth: 1.5)) VStack(alignment: .leading, spacing: 5) { - Text("Robin Kutesa") + Text(auth.currentUser?.displayName ?? "My Account") .font(AppFonts.sans(14, weight: .semibold)) .foregroundColor(AppColors.text(cs)) HStack(spacing: 5) { @@ -939,6 +940,7 @@ private struct ProfileStatsSheet: View { @AppStorage("streakGoal") private var streakGoal = 5 @AppStorage("healthOn") private var healthOn = false @ObservedObject private var hk = HealthKitManager.shared + @ObservedObject private var auth = AuthManager.shared // ── Task metrics ── private var totalTasks: Int { taskVM.tasks.count } @@ -992,14 +994,15 @@ private struct ProfileStatsSheet: View { VStack(spacing: 8) { ZStack { Circle().fill(AppColors.accentSoft) - Text("RK").font(AppFonts.sans(24, weight: .bold)).foregroundColor(AppColors.accent) + Text(initials(for: auth.currentUser?.displayName)) + .font(AppFonts.sans(24, weight: .bold)).foregroundColor(AppColors.accent) } .frame(width: 68, height: 68) .overlay(Circle().stroke(AppColors.accent.opacity(0.25), lineWidth: 2)) - Text("Robin Kutesa") + Text(auth.currentUser?.displayName ?? "My Account") .font(AppFonts.sans(18, weight: .bold)).foregroundColor(AppColors.text(cs)) - Text("kisaniCAL.") + Text(auth.currentUser?.email ?? "kisaniCAL.") .font(AppFonts.mono(11)).foregroundColor(AppColors.text3(cs)) } .frame(maxWidth: .infinity).padding(.vertical, 14) @@ -1205,6 +1208,15 @@ private struct PStatCell: View { } } +private func initials(for name: String?) -> String { + guard let name, !name.isEmpty else { return "?" } + let parts = name.split(separator: " ") + if parts.count >= 2 { + return (String(parts[0].prefix(1)) + String(parts[1].prefix(1))).uppercased() + } + return String(name.prefix(2)).uppercased() +} + private func streakBars(_ streak: Int, goal: Int) -> String { let filled = min(max(streak, 0), goal) return String(repeating: "|", count: filled) + String(repeating: "·", count: goal - filled)