wip
This commit is contained in:
@ -1,15 +0,0 @@
|
||||
//
|
||||
// Badge.swift
|
||||
// Workouts
|
||||
//
|
||||
// Created by rzen on 7/13/25 at 5:42 PM.
|
||||
//
|
||||
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
|
||||
//
|
||||
|
||||
import SwiftUICore
|
||||
|
||||
struct Badge: Hashable {
|
||||
var text: String
|
||||
var color: Color
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
//
|
||||
// BadgeView.swift
|
||||
// Workouts
|
||||
//
|
||||
// Created by rzen on 7/14/25 at 2:20 PM.
|
||||
//
|
||||
// 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)
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
//
|
||||
// ListItem.swift
|
||||
// Workouts
|
||||
//
|
||||
// Created by rzen on 7/13/25 at 10:42 AM.
|
||||
//
|
||||
// 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())
|
||||
}
|
||||
}
|
||||
|
50
Workouts/Utils/Date+humanTimeInterval.swift
Normal file
50
Workouts/Utils/Date+humanTimeInterval.swift
Normal file
@ -0,0 +1,50 @@
|
||||
//
|
||||
// Date+humanTimeInterval.swift
|
||||
// Workouts
|
||||
//
|
||||
// Created by rzen on 7/19/25 at 1:06 PM.
|
||||
//
|
||||
// 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")"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,57 +0,0 @@
|
||||
//
|
||||
// ListItem.swift
|
||||
// Workouts
|
||||
//
|
||||
// Created by rzen on 7/13/25 at 10:42 AM.
|
||||
//
|
||||
// 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())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user