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 <tqwyy79vzn@privaterelay.appleid.com>
This commit is contained in:
@@ -4,6 +4,7 @@ struct SettingsView: View {
|
|||||||
@Environment(\.colorScheme) var cs
|
@Environment(\.colorScheme) var cs
|
||||||
@EnvironmentObject var workoutVM: WorkoutViewModel
|
@EnvironmentObject var workoutVM: WorkoutViewModel
|
||||||
@EnvironmentObject var taskVM: TaskViewModel
|
@EnvironmentObject var taskVM: TaskViewModel
|
||||||
|
@ObservedObject private var auth = AuthManager.shared
|
||||||
|
|
||||||
// Persisted settings
|
// Persisted settings
|
||||||
@AppStorage("appearanceMode") private var appearanceMode = 0
|
@AppStorage("appearanceMode") private var appearanceMode = 0
|
||||||
@@ -59,7 +60,7 @@ struct SettingsView: View {
|
|||||||
HStack(spacing: 12) {
|
HStack(spacing: 12) {
|
||||||
ZStack {
|
ZStack {
|
||||||
Circle().fill(AppColors.accentSoft)
|
Circle().fill(AppColors.accentSoft)
|
||||||
Text("RK")
|
Text(initials(for: auth.currentUser?.displayName))
|
||||||
.font(AppFonts.sans(15, weight: .bold))
|
.font(AppFonts.sans(15, weight: .bold))
|
||||||
.foregroundColor(AppColors.accent)
|
.foregroundColor(AppColors.accent)
|
||||||
}
|
}
|
||||||
@@ -67,7 +68,7 @@ struct SettingsView: View {
|
|||||||
.overlay(Circle().stroke(AppColors.accent.opacity(0.18), lineWidth: 1.5))
|
.overlay(Circle().stroke(AppColors.accent.opacity(0.18), lineWidth: 1.5))
|
||||||
|
|
||||||
VStack(alignment: .leading, spacing: 5) {
|
VStack(alignment: .leading, spacing: 5) {
|
||||||
Text("Robin Kutesa")
|
Text(auth.currentUser?.displayName ?? "My Account")
|
||||||
.font(AppFonts.sans(14, weight: .semibold))
|
.font(AppFonts.sans(14, weight: .semibold))
|
||||||
.foregroundColor(AppColors.text(cs))
|
.foregroundColor(AppColors.text(cs))
|
||||||
HStack(spacing: 5) {
|
HStack(spacing: 5) {
|
||||||
@@ -939,6 +940,7 @@ private struct ProfileStatsSheet: View {
|
|||||||
@AppStorage("streakGoal") private var streakGoal = 5
|
@AppStorage("streakGoal") private var streakGoal = 5
|
||||||
@AppStorage("healthOn") private var healthOn = false
|
@AppStorage("healthOn") private var healthOn = false
|
||||||
@ObservedObject private var hk = HealthKitManager.shared
|
@ObservedObject private var hk = HealthKitManager.shared
|
||||||
|
@ObservedObject private var auth = AuthManager.shared
|
||||||
|
|
||||||
// ── Task metrics ──
|
// ── Task metrics ──
|
||||||
private var totalTasks: Int { taskVM.tasks.count }
|
private var totalTasks: Int { taskVM.tasks.count }
|
||||||
@@ -992,14 +994,15 @@ private struct ProfileStatsSheet: View {
|
|||||||
VStack(spacing: 8) {
|
VStack(spacing: 8) {
|
||||||
ZStack {
|
ZStack {
|
||||||
Circle().fill(AppColors.accentSoft)
|
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)
|
.frame(width: 68, height: 68)
|
||||||
.overlay(Circle().stroke(AppColors.accent.opacity(0.25), lineWidth: 2))
|
.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))
|
.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))
|
.font(AppFonts.mono(11)).foregroundColor(AppColors.text3(cs))
|
||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity).padding(.vertical, 14)
|
.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 {
|
private func streakBars(_ streak: Int, goal: Int) -> String {
|
||||||
let filled = min(max(streak, 0), goal)
|
let filled = min(max(streak, 0), goal)
|
||||||
return String(repeating: "|", count: filled) + String(repeating: "·", count: goal - filled)
|
return String(repeating: "|", count: filled) + String(repeating: "·", count: goal - filled)
|
||||||
|
|||||||
Reference in New Issue
Block a user