Skip to content
Closed
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
53 changes: 2 additions & 51 deletions Stanford360/Activity/View/ActivityAddView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@
import SwiftUI

struct ActivityAddView: View {
@Environment(ActivityManager.self) private var activityManager
@Environment(Stanford360Standard.self) private var standard
@Environment(Stanford360Scheduler.self) var scheduler
@Environment(ActivityManager.self) private var activityManager

// Activity properties that can be initialized for editing
@State private var activeMinutes: String
@State private var selectedActivity: String
@State private var selectedDate: Date
@State private var showingDateError = false
@State private var showingAddActivity = false
private var activityId: String?

var body: some View {
ZStack {
Expand Down Expand Up @@ -62,63 +58,18 @@
}
}

private var saveButtonView: some View {
ActionButton(
title: "Save My Activity! 🌟",
action: {
Task {
await saveNewActivity()
}
},
isDisabled: activeMinutes.isEmpty
)
}

// MARK: - Initializers
init(selectedActivity: String = "Walking", activeMinutes: String = "", selectedDate: Date = Date()) {
self._selectedActivity = State(initialValue: selectedActivity)
self._activeMinutes = State(initialValue: activeMinutes)
self._selectedDate = State(initialValue: selectedDate)
self.activityId = nil

Check failure on line 66 in Stanford360/Activity/View/ActivityAddView.swift

View workflow job for this annotation

GitHub Actions / Build and Test / Test using xcodebuild or run fastlane

'nil' requires a contextual type

Check failure on line 66 in Stanford360/Activity/View/ActivityAddView.swift

View workflow job for this annotation

GitHub Actions / Build and Test / Test using xcodebuild or run fastlane

value of type 'ActivityAddView' has no member 'activityId'
}

init(activity: Activity) {
self._activeMinutes = State(initialValue: "\(activity.activeMinutes)")
self._selectedActivity = State(initialValue: activity.activityType)
self._selectedDate = State(initialValue: activity.date)
self.activityId = activity.id
}

private func saveNewActivity() async {
let minutes = Int(activeMinutes) ?? 0
let estimatedSteps = activityManager.getStepsFromMinutes(minutes)

let newActivity = Activity(
date: Date(),
steps: estimatedSteps,
activeMinutes: minutes,
activityType: selectedActivity
)

let prevActivityMinutes = activityManager.getTodayTotalMinutes()
let lastRecordedMilestone = activityManager.getLatestMilestone()
activityManager.activities.append(newActivity)
let activityMinutes = activityManager.getTodayTotalMinutes()
let updatedStreak = activityManager.streak
await standard.addActivityToFirestore(newActivity)
await scheduler.handleNotificationsOnLoggedActivity(prevActivityMinutes: prevActivityMinutes, newActivityMinutes: activityMinutes)
activityManager.milestoneManager.displayMilestoneMessage(
newTotal: Double(activityManager.getTodayTotalMinutes()),
lastMilestone: lastRecordedMilestone,
unit: "minutes of activity",
streak: updatedStreak
)
}


func saveNewActivityButton(showingAddActivity: Binding<Bool>) -> some View {
SaveActivityButton(
showingAddActivity: showingAddActivity,
selectedActivity: showingAddActivity.wrappedValue ? "Walking" : nil,

Check failure on line 72 in Stanford360/Activity/View/ActivityAddView.swift

View workflow job for this annotation

GitHub Actions / Build and Test / Test using xcodebuild or run fastlane

extra argument 'selectedActivity' in call
minutes: showingAddActivity.wrappedValue ? "0" : nil
)
}
Expand Down
38 changes: 0 additions & 38 deletions Stanford360/Activity/View/ActivityComponentsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,43 +83,6 @@ struct ActivityPickerView: View {
}
}

// MARK: - ActivityButtonView
struct ActivityButtonView: View {
let activityName: String
let iconName: String
@Binding var selectedActivity: String

var body: some View {
VStack(spacing: 6) {
Image(systemName: iconName)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 40, height: 40)
.foregroundColor(.blue) // Change color as needed
.accessibilityLabel(activityName)

Text(activityName)
.font(.subheadline)
.foregroundColor(.primary)
}
.frame(width: 65, height: 65)
.padding()
.background(
ZStack {
RoundedRectangle(cornerRadius: 12).fill(Color.white)
if selectedActivity == activityName {
RoundedRectangle(cornerRadius: 12)
.stroke(Color.blue, lineWidth: 3)
}
}
)
.shadow(radius: 2)
.onTapGesture {
selectedActivity = activityName
}
}
}

// MARK: - DatePickerView
struct DatePickerView: View {
@Binding var selectedDate: Date
Expand Down Expand Up @@ -225,7 +188,6 @@ struct ActionButton: View {

struct SaveActivityButton: View {
@Binding var showingAddActivity: Bool
var selectedActivity: String?
var minutes: String?
@State private var errorMessage: String?

Expand Down
Loading