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