Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 96 additions & 94 deletions Gymly/Calendar/CalendarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,120 +20,122 @@ struct CalendarView: View {
ZStack {
FloatingClouds(theme: CloudsTheme.graphite(scheme))
.ignoresSafeArea()
VStack {
HStack {
Button(action: {
currentMonth = calendar.date(byAdding: .month, value: -1, to: currentMonth) ?? currentMonth
}) {
Image(systemName: "chevron.left")
.bold()
.foregroundStyle(.red)
}
Spacer()
Text(viewModel.monthAndYearString(from: currentMonth))
.font(.title)
Spacer()
Button(action: {
currentMonth = calendar.date(byAdding: .month, value: 1, to: currentMonth) ?? currentMonth
}) {
Image(systemName: "chevron.right")
.bold()
.foregroundStyle(.red)
}
}
.padding()

GeometryReader { geometry in
VStack {
HStack {
ForEach(daysOfWeek, id: \.self) { day in
Spacer()
Text(day)
.frame(width: UIScreen.main.bounds.width * 0.085)
Button(action: {
currentMonth = calendar.date(byAdding: .month, value: -1, to: currentMonth) ?? currentMonth
}) {
Image(systemName: "chevron.left")
.bold()
.foregroundStyle(.red)
}
Spacer()
Text(viewModel.monthAndYearString(from: currentMonth))
.font(.title)
Spacer()
Button(action: {
currentMonth = calendar.date(byAdding: .month, value: 1, to: currentMonth) ?? currentMonth
}) {
Image(systemName: "chevron.right")
.bold()
.font(.subheadline)
Spacer()
.foregroundStyle(.red)
}
}
.padding(5)
.background(Color.red)
.overlay(
RoundedRectangle(cornerRadius: 5)
.stroke(.red, lineWidth: 4)
)
.padding(.bottom, 10)

let daysInMonth = viewModel.getDaysInMonth(for: currentMonth)
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 7)) {
ForEach(daysInMonth.indices, id: \.self) { index in
let day = daysInMonth[index]

if day.day != 0 {
if viewModel.formattedDateString(from: day.date) == viewModel.formattedDateString(from: Date()) {
NavigationLink("\(day.day)") {
CalendarDayView(viewModel: viewModel, date: viewModel.formattedDateString(from: day.date))
}
.frame(width: UIScreen.main.bounds.width * 0.085, height: UIScreen.main.bounds.height * 0.04)
.font(.system(size: 22))
.foregroundColor(Color.white)
.padding(.horizontal, 3)
.padding(.vertical, 2)
.background(Color.red)
.cornerRadius(25)
.overlay(
RoundedRectangle(cornerRadius: 25)
.stroke(.red, lineWidth: 4)
)
.fontWeight(.bold)
.padding(3)
} else {
ZStack {
let dayDateString = viewModel.formattedDateString(from: day.date)
.padding()

VStack {
HStack {
ForEach(daysOfWeek, id: \.self) { day in
Spacer()
Text(day)
.frame(width: geometry.size.width * 0.085)
.bold()
.font(.subheadline)
Spacer()
}
}
.padding(5)
.background(Color.red)
.overlay(
RoundedRectangle(cornerRadius: 5)
.stroke(.red, lineWidth: 4)
)
.padding(.bottom, 10)

let daysInMonth = viewModel.getDaysInMonth(for: currentMonth)
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 7)) {
ForEach(daysInMonth.indices, id: \.self) { index in
let day = daysInMonth[index]

if day.day != 0 {
if viewModel.formattedDateString(from: day.date) == viewModel.formattedDateString(from: Date()) {
NavigationLink("\(day.day)") {
CalendarDayView(viewModel: viewModel, date: dayDateString)
CalendarDayView(viewModel: viewModel, date: viewModel.formattedDateString(from: day.date))
}
.frame(width: UIScreen.main.bounds.width * 0.085, height: UIScreen.main.bounds.height * 0.04)
.frame(width: geometry.size.width * 0.085, height: geometry.size.width * 0.085)
.font(.system(size: 22))
.foregroundColor(Color.white)
.padding(.horizontal, 3)
.padding(.vertical, 2)
.background(Color.red)
.cornerRadius(25)
.overlay(
RoundedRectangle(cornerRadius: 25)
.stroke(.red, lineWidth: 4)
)
.fontWeight(.bold)
.padding(3)
.onAppear {
// Only log for today's date to reduce noise
if Calendar.current.isDate(day.date, inSameDayAs: Date()) {
print("🔍 CALENDAR: Today's date is '\(dayDateString)'")
print("🔍 CALENDAR: daysRecorded contains: \(config.daysRecorded)")
print("🔍 CALENDAR: Contains today? \(config.daysRecorded.contains(dayDateString))")
} else {
ZStack {
let dayDateString = viewModel.formattedDateString(from: day.date)

NavigationLink("\(day.day)") {
CalendarDayView(viewModel: viewModel, date: dayDateString)
}
.frame(width: geometry.size.width * 0.085, height: geometry.size.width * 0.085)
.font(.system(size: 22))
.foregroundColor(Color.white)
.padding(3)
.onAppear {
// Only log for today's date to reduce noise
if Calendar.current.isDate(day.date, inSameDayAs: Date()) {
print("🔍 CALENDAR: Today's date is '\(dayDateString)'")
print("🔍 CALENDAR: daysRecorded contains: \(config.daysRecorded)")
print("🔍 CALENDAR: Contains today? \(config.daysRecorded.contains(dayDateString))")
}
}
}

if config.daysRecorded.contains(dayDateString) || viewModel.hasDayStorage(for: dayDateString) {
Circle()
.frame(width: 10, height: 10)
.foregroundColor(.red)
.offset(x: 0, y: 20)
if config.daysRecorded.contains(dayDateString) || viewModel.hasDayStorage(for: dayDateString) {
Circle()
.frame(width: 10, height: 10)
.foregroundColor(.red)
.offset(x: 0, y: 20)
}
}
}
} else {
/// Empty day so the calendar is alligned right
Text("")
.padding(.vertical, 12)
.padding(.horizontal, 6)
}
} else {
/// Empty day so the calendar is alligned right
Text("")
.padding(.vertical, 12)
.padding(.horizontal, 6)
}
}
.padding(2)
.scrollContentBackground(.hidden)
.background(Color.clear)
.listRowBackground(Color.black.opacity(0.1))
Spacer()
}
.padding(2)
.scrollContentBackground(.hidden)
.background(Color.clear)
.listRowBackground(Color.black.opacity(0.1))
Spacer()
.frame(maxWidth: geometry.size.width * 0.92)
}
.navigationTitle("Calendar")
.onAppear() {
currentMonth = calendar.date(from: calendar.dateComponents([.year, .month], from: Date())) ?? currentMonth
// Clean up any duplicate dates in the daysRecorded array
viewModel.cleanupDuplicateDates()
}
.frame(maxWidth: UIScreen.main.bounds.width * 0.92)
}
.navigationTitle("Calendar")
.onAppear() {
currentMonth = calendar.date(from: calendar.dateComponents([.year, .month], from: Date())) ?? currentMonth
// Clean up any duplicate dates in the daysRecorded array
viewModel.cleanupDuplicateDates()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Gymly/Cells/SetCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ struct SetCell: View {
}
}
}
.onChange(of: showEditSheet) { newValue in
.onChange(of: showEditSheet) { oldValue, newValue in
if onSetTap == nil {
print("📱 showEditSheet changed to: \(newValue) for set \(index + 1)")
}
Expand Down
9 changes: 6 additions & 3 deletions Gymly/Cells/SettingUserInfoCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ struct SettingUserInfoCell: View {
@State var additionalInfo: String = "Normal Weight"
@State var icon: String = "figure.run"
@State var weightLastWeek: Double = 0.0
@State private var hasLoadedWeightData = false // Prevent multiple loads

var body: some View {
VStack {
GeometryReader { geo in
Expand Down Expand Up @@ -62,14 +64,15 @@ struct SettingUserInfoCell: View {
}
}
.onAppear() {
// Only fetch last week's weight if this is a weight cell and we haven't loaded yet
guard (metric == "Kg" || metric == "Lbs") && !hasLoadedWeightData else { return }
hasLoadedWeightData = true

getLastWeekWeight { weight in
if let weight = weight {
DispatchQueue.main.async {
self.weightLastWeek = weight
print("Last week's latest weight: \(weight) kg")
}
} else {
print("No weight data found.")
}
}
}
Expand Down
Loading