✨ Add Subscription Colors
This commit is contained in:
@@ -6,6 +6,7 @@ struct AddSubscriptionView: View {
|
||||
|
||||
@State private var name: String = ""
|
||||
@State private var payments: [Payment] = [Payment(amount: 0, intervall: .monthly)]
|
||||
@State private var color: Color = .blue
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
@@ -14,6 +15,10 @@ struct AddSubscriptionView: View {
|
||||
TextField("Name", text: $name)
|
||||
}
|
||||
|
||||
Section(header: Text("Color")) {
|
||||
ColorPicker("Select Color", selection: $color)
|
||||
}
|
||||
|
||||
ForEach($payments) { $payment in
|
||||
Section(header: Text("Payment")) {
|
||||
HStack {
|
||||
@@ -41,7 +46,7 @@ struct AddSubscriptionView: View {
|
||||
|
||||
Section {
|
||||
Button("Add Subscription") {
|
||||
let newSubscription = Subscription(name: name, payments: payments)
|
||||
let newSubscription = Subscription(name: name, payments: payments, color: color)
|
||||
subs.append(newSubscription)
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@ import SwiftUI
|
||||
struct ContentView: View {
|
||||
@State private var showAddSubscriptionSheet = false
|
||||
@State private var subs: [Subscription] = [
|
||||
Subscription(name: "Test", payments: [Payment(amount: 9.99, intervall: .monthly)]),
|
||||
Subscription(name: "Fitness First", payments: [Payment(amount: 8, intervall: .weekly), Payment(amount: 30, intervall: .quarter)])
|
||||
Subscription(name: "Test", payments: [Payment(amount: 9.99, intervall: .monthly)], color: .blue),
|
||||
Subscription(name: "Fitness First", payments: [Payment(amount: 8, intervall: .weekly), Payment(amount: 30, intervall: .quarter)], color: .red)
|
||||
]
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
Form {
|
||||
List {
|
||||
ForEach(subs) { sub in
|
||||
Section {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
@@ -27,6 +27,8 @@ struct ContentView: View {
|
||||
}
|
||||
.padding(.vertical, 8)
|
||||
}
|
||||
.listRowBackground(sub.color.opacity(0.2))
|
||||
.cornerRadius(8)
|
||||
}
|
||||
.onDelete(perform: deleteSubscription)
|
||||
|
||||
|
||||
@@ -5,10 +5,12 @@ final class Subscription: Identifiable {
|
||||
public let id = UUID()
|
||||
var name: String
|
||||
var payments: [Payment]
|
||||
var color: Color
|
||||
|
||||
init(name: String, payments: [Payment]) {
|
||||
init(name: String, payments: [Payment], color: Color) {
|
||||
self.name = name
|
||||
self.payments = payments
|
||||
self.color = color
|
||||
}
|
||||
|
||||
func getMonthlyAmount() -> Float {
|
||||
|
||||
Reference in New Issue
Block a user