Skip to content

Commit

Permalink
Load tito data into NFC writing
Browse files Browse the repository at this point in the history
  • Loading branch information
nvh committed Aug 25, 2024
1 parent 0186b13 commit c50b94a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
10 changes: 10 additions & 0 deletions SwiftIslandApp/Pages/Practical/NFC/ContactData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,15 @@ struct ContactData: Decodable, Encodable, Hashable, Defaults.Serializable {

mutating func update(with ticket: Ticket) {
self.name = ticket.name
if let email = ticket.email {
self.email = email
}
if let company = ticket.companyName {
self.company = company
}
if let phone = ticket.phoneNumber {
self.phone = phone
}

}
}
16 changes: 5 additions & 11 deletions SwiftIslandApp/Pages/Practical/NFC/WriteNFCView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,7 @@ struct WriteNFCView: View {
NavigationStack {
VStack {
if (NFCReaderSession.readingAvailable) {
Text("Input your details below to write this data to your NFC Tag.")
Button {
// TODO: don't use only the first ticket
if let ticket = appDataModel.tickets.first {
contact.update(with: ticket)
} else {
// TODO: Show error
}
} label: {
Text("Use Data from Ticket")
}.padding(20)
Text("Input your details below to write this data to your NFC Tag.").padding(20)
ContactLine(label: "Name", placeholder: "Taylor Swift", value: $contact.name)
ContactLine(label: "Company", placeholder: "Swift Island", value: $contact.company)
ContactLine(label: "Phone", placeholder: "+31612345678", value: $contact.phone)
Expand All @@ -41,6 +31,10 @@ struct WriteNFCView: View {
}
.padding(20)
.navigationTitle("Write Your Own Tag")
}.onAppear {
if let ticket = appDataModel.tickets.first {
contact.update(with: ticket)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ public struct Ticket {
let registrationReference: String
let createdAt: Date
let updatedAt: Date

internal init(id: Int, slug: String, firstName: String, lastName: String, releaseTitle: String, reference: String, registrationReference: String, createdAt: Date, updatedAt: Date) {
public let email: String?
public let companyName: String?
public let phoneNumber: String?

internal init(id: Int, slug: String, firstName: String, lastName: String, releaseTitle: String, reference: String, registrationReference: String, createdAt: Date, updatedAt: Date, email: String?, companyName: String?, phoneNumber: String?) {
self.id = id
self.slug = slug
self.firstName = firstName
Expand All @@ -26,10 +29,13 @@ public struct Ticket {
self.registrationReference = registrationReference
self.createdAt = createdAt
self.updatedAt = updatedAt
self.email = email
self.companyName = companyName
self.phoneNumber = phoneNumber
}

init() {
self.init(id: 0, slug: "", firstName: "", lastName: "", releaseTitle: "", reference: "", registrationReference: "", createdAt: Date(), updatedAt: Date())
self.init(id: 0, slug: "", firstName: "", lastName: "", releaseTitle: "", reference: "", registrationReference: "", createdAt: Date(), updatedAt: Date(), email: nil, companyName: nil, phoneNumber: nil)
}
}

Expand All @@ -44,6 +50,9 @@ extension Ticket: Decodable, Encodable {
case registrationReference = "registration_reference"
case createdAt = "created_at"
case updatedAt = "updated_at"
case email = "email"
case companyName = "company_name"
case phoneNumber = "phone_number"
}
}

Expand Down Expand Up @@ -103,7 +112,7 @@ extension Ticket {
reference: reference,
registrationReference: registrationReference,
createdAt: createdAt,
updatedAt: updatedAt)
updatedAt: updatedAt, email: nil, companyName: nil, phoneNumber: nil)
}
}

Expand Down

0 comments on commit c50b94a

Please sign in to comment.