reaaaranged

Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
Matt Bruce 2024-12-20 14:17:51 -06:00
parent cb8f3f7204
commit 1df20c79cb
7 changed files with 74 additions and 47 deletions

View File

@ -0,0 +1,16 @@
//
// Activity.swift
// FitnessApp
//
// Created by Matt Bruce on 12/20/24.
//
import SwiftUI
struct Activity {
let id: Int
let title: String
let subtitle: String
let image: String
let tintColor: Color
let amount: String
}

View File

@ -0,0 +1,17 @@
//
// Workout.swift
// FitnessApp
//
// Created by Matt Bruce on 12/20/24.
//
import SwiftUI
struct Workout {
let id: Int
let title: String
let image: String
let tintColor: Color
let duration: String
let date: String
let calories: String
}

View File

@ -0,0 +1,30 @@
//
// HomeViewModel.swift
// FitnessApp
//
// Created by Matt Bruce on 12/20/24.
//
import SwiftUI
@Observable
class HomeViewModel {
var activities: [Activity] = []
var workouts: [Workout] = []
var calories: Int = 123
var active: Int = 205
var stand: Int = 80
var mockActivities = [
Activity(id: 0, title: "Today Steps", subtitle: "10,000 steps", image: "figure.walk", tintColor: .green, amount: "9,812"),
Activity(id: 1, title: "Today Steps", subtitle: "1,000 steps", image: "figure.walk", tintColor: .blue, amount: "812"),
Activity(id: 2, title: "Today Steps", subtitle: "12,000 steps", image: "figure.walk", tintColor: .purple, amount: "9,0000"),
Activity(id: 3, title: "Today Steps", subtitle: "50,000 steps", image: "figure.run", tintColor: .red, amount: "104,812")
]
var mockWorkouts = [
Workout(id: 0, title: "Running", image: "figure.run", tintColor: .green, duration: "1 hrs", date: "Aug 3", calories: "100 kcal"),
Workout(id: 1, title: "Strength Training", image: "figure.run", tintColor: .purple, duration: "1.5 hrs", date: "Aug 3", calories: "130 kcal"),
Workout(id: 2, title: "Walking", image: "figure.run", tintColor: .blue, duration: ".5 hrs", date: "Aug 3", calories: "250 kcal"),
Workout(id: 3, title: "Bike", image: "figure.run", tintColor: .red, duration: "2 hrs", date: "Aug 29", calories: "500 kcal")
]
}

View File

@ -7,15 +7,6 @@
import SwiftUI
struct Activity {
let id: Int
let title: String
let subtitle: String
let image: String
let tintColor: Color
let amount: String
}
struct ActivityCard: View {
@State var activity: Activity

View File

@ -8,24 +8,8 @@
import SwiftUI
struct HomeView: View {
@State var calories: Int = 123
@State var active: Int = 205
@State var stand: Int = 80
var mockActivities = [
Activity(id: 0, title: "Today Steps", subtitle: "10,000 steps", image: "figure.walk", tintColor: .green, amount: "9,812"),
Activity(id: 1, title: "Today Steps", subtitle: "1,000 steps", image: "figure.walk", tintColor: .blue, amount: "812"),
Activity(id: 2, title: "Today Steps", subtitle: "12,000 steps", image: "figure.walk", tintColor: .purple, amount: "9,0000"),
Activity(id: 3, title: "Today Steps", subtitle: "50,000 steps", image: "figure.run", tintColor: .red, amount: "104,812")
]
var mockWorkouts = [
Workout(id: 0, title: "Running", image: "figure.run", tintColor: .green, duration: "1 hrs", date: "Aug 3", calories: "100 kcal"),
Workout(id: 1, title: "Strength Training", image: "figure.run", tintColor: .purple, duration: "1.5 hrs", date: "Aug 3", calories: "130 kcal"),
Workout(id: 2, title: "Walking", image: "figure.run", tintColor: .blue, duration: ".5 hrs", date: "Aug 3", calories: "250 kcal"),
Workout(id: 3, title: "Bike", image: "figure.run", tintColor: .red, duration: "2 hrs", date: "Aug 29", calories: "500 kcal")
]
@State var viewModel: HomeViewModel = .init()
var body: some View {
NavigationStack {
ScrollView(showsIndicators: false) {
@ -44,7 +28,7 @@ struct HomeView: View {
.bold()
.foregroundColor(.red)
Text("123 kcal")
Text("\(viewModel.calories)")
.bold()
}.padding(.bottom)
@ -54,7 +38,7 @@ struct HomeView: View {
.bold()
.foregroundColor(.green)
Text("52 mins")
Text("\(viewModel.active)")
.bold()
}.padding(.bottom)
@ -65,7 +49,7 @@ struct HomeView: View {
.bold()
.foregroundColor(.blue)
Text("8 hrs")
Text("\(viewModel.stand)")
.bold()
}
@ -75,9 +59,9 @@ struct HomeView: View {
ZStack {
Spacer()
ProgressCircleView(progress: $calories, goal: 600, color: .red)
ProgressCircleView(progress: $active, goal: 600, color: .green).padding(.all, 20)
ProgressCircleView(progress: $stand, goal: 600, color: .blue).padding(.all, 40)
ProgressCircleView(progress: $viewModel.calories, goal: 600, color: .red)
ProgressCircleView(progress: $viewModel.active, goal: 600, color: .green).padding(.all, 20)
ProgressCircleView(progress: $viewModel.stand, goal: 600, color: .blue).padding(.all, 40)
}
.padding(.horizontal)
@ -105,13 +89,13 @@ struct HomeView: View {
.padding(.horizontal)
LazyVGrid(columns: Array(repeating: GridItem(spacing: 20), count: 2)) {
ForEach(mockActivities, id: \.id) { activity in
ForEach(viewModel.mockActivities , id: \.id) { activity in
ActivityCard(activity: activity)
}
}.padding(.horizontal)
//Fitness Activity
//Recent Workouts
HStack {
Text("Recent Workouts")
.font(.title2)
@ -130,7 +114,7 @@ struct HomeView: View {
.padding(.horizontal)
.padding(.top)
LazyVStack{
ForEach(mockWorkouts, id: \.id) { workout in
ForEach(viewModel.mockWorkouts, id: \.id) { workout in
WorkoutCard(workout: workout)
}
}

View File

@ -7,17 +7,6 @@
import SwiftUI
struct Workout {
let id: Int
let title: String
let image: String
let tintColor: Color
let duration: String
let date: String
let calories: String
}
struct WorkoutCard: View {
@State var workout: Workout