This commit is contained in:
2025-07-19 16:42:47 -04:00
parent 6e46775f58
commit e3c3f2c6f0
38 changed files with 556 additions and 367 deletions

View File

@ -1,15 +0,0 @@
//
// Badge.swift
// Workouts
//
// Created by rzen on 7/13/25 at 5:42PM.
//
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
//
import SwiftUICore
struct Badge: Hashable {
var text: String
var color: Color
}

View File

@ -1,24 +0,0 @@
//
// BadgeView.swift
// Workouts
//
// Created by rzen on 7/14/25 at 2:20PM.
//
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
//
import SwiftUI
struct BadgeView: View {
var badge: Badge
var body: some View {
Text("\(badge.text)")
.bold()
.padding([.leading,.trailing], 5)
.background(badge.color)
.foregroundColor(.white)
.cornerRadius(4)
}
}

View File

@ -1,71 +0,0 @@
//
// ListItem.swift
// Workouts
//
// Created by rzen on 7/13/25 at 10:42AM.
//
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
//
import SwiftUI
enum CheckboxStatus {
case checked
case unchecked
case intermediate
case cancelled
var color: Color {
switch (self) {
case .checked: .green
case .unchecked: .gray
case .intermediate: .yellow
case .cancelled: .red
}
}
var systemName: String {
switch (self) {
case .checked: "checkmark.circle.fill"
case .unchecked: "circle"
case .intermediate: "ellipsis.circle"
case .cancelled: "cross.circle"
}
}
}
struct CheckboxListItem: View {
var status: CheckboxStatus
var title: String
var subtitle: String?
var count: Int?
var body: some View {
HStack (alignment: .top) {
Image(systemName: status.systemName)
.resizable()
.scaledToFit()
.frame(width: 30)
.foregroundStyle(status.color)
VStack (alignment: .leading) {
Text("\(title)")
.font(.headline)
HStack (alignment: .bottom) {
if let subtitle = subtitle {
Text("\(subtitle)")
.font(.footnote)
}
}
}
if let count = count {
Spacer()
Text("\(count)")
.font(.caption)
.foregroundColor(.gray)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
.contentShape(Rectangle())
}
}

View File

@ -0,0 +1,50 @@
//
// Date+humanTimeInterval.swift
// Workouts
//
// Created by rzen on 7/19/25 at 1:06PM.
//
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
//
import Foundation
extension Date {
func humanTimeInterval(to referenceDate: Date = Date()) -> String {
let seconds = Int(referenceDate.timeIntervalSince(self))
let absSeconds = abs(seconds)
let minute = 60
let hour = 3600
let day = 86400
let week = 604800
let month = 2592000
let year = 31536000
switch absSeconds {
case 0..<5:
return "just now"
case 5..<minute:
return "\(absSeconds) seconds"
case minute..<hour:
let minutes = absSeconds / minute
return "\(minutes) minute\(minutes == 1 ? "" : "s")"
case hour..<day:
let hours = absSeconds / hour
return "\(hours) hour\(hours == 1 ? "" : "s")"
case day..<week:
let days = absSeconds / day
return "\(days) day\(days == 1 ? "" : "s")"
case week..<month:
let weeks = absSeconds / week
return "\(weeks) week\(weeks == 1 ? "" : "s")"
case month..<year:
let months = absSeconds / month
return "\(months) month\(months == 1 ? "" : "s")"
default:
let years = absSeconds / year
return "\(years) year\(years == 1 ? "" : "s")"
}
}
}

View File

@ -1,57 +0,0 @@
//
// ListItem.swift
// Workouts
//
// Created by rzen on 7/13/25 at 10:42AM.
//
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
//
import SwiftUI
struct ListItem: View {
var title: String?
var text: String?
var subtitle: String?
var count: Int?
var badges: [Badge]? = []
var body: some View {
HStack {
VStack (alignment: .leading) {
if let title = title {
Text("\(title)")
.font(.headline)
if let text = text {
Text("\(text)")
.font(.footnote)
}
} else {
if let text = text {
Text("\(text)")
}
}
HStack (alignment: .bottom) {
if let badges = badges {
ForEach (badges, id: \.self) { badge in
BadgeView(badge: badge)
}
}
if let subtitle = subtitle {
Text("\(subtitle)")
.font(.footnote)
}
}
}
if let count = count {
Spacer()
Text("\(count)")
.font(.caption)
.foregroundColor(.gray)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
.contentShape(Rectangle())
}
}