Created
July 14, 2023 09:37
-
-
Save saroar/6611734f8fb94b7e3075ac8e00bcd98f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - VCard | |
public struct VCard: Codable, Equatable { | |
public struct Contact: Codable, Equatable { | |
/// The last name of the contact. | |
public var lastName: String | |
/// The first name of the contact. | |
public var firstName: String | |
/// An additional name or middle name of the contact. | |
public var additionalName: String? | |
/// The name prefix or honorific of the contact (e.g., Mr., Mrs., Dr.). | |
public var namePrefix: String? | |
/// The name suffix of the contact (e.g., Jr., Sr., PhD). | |
public var nameSuffix: String? | |
/// Initializes a new instance of `ContactName` with values for each property. | |
/// | |
/// - Parameters: | |
/// - lastName: The last name of the contact. | |
/// - firstName: The first name of the contact. | |
/// - additionalName: An additional name or middle name of the contact. | |
/// - namePrefix: The name prefix or honorific of the contact (e.g., Mr., Mrs., Dr.). | |
/// - nameSuffix: The name suffix of the contact (e.g., Jr., Sr., PhD). | |
public init( | |
lastName: String, | |
firstName: String, | |
additionalName: String? = nil, | |
namePrefix: String? = nil, | |
nameSuffix: String? = nil | |
) { | |
self.lastName = lastName | |
self.firstName = firstName | |
self.additionalName = additionalName | |
self.namePrefix = namePrefix | |
self.nameSuffix = nameSuffix | |
} | |
/// Returns a string representation of the `ContactName` instance in vCard format. | |
public var vcardRepresentation: String { | |
"N:\(self.lastName);\(self.firstName);\(self.additionalName ?? "");\(self.namePrefix ?? "");\(self.nameSuffix ?? "")\n" | |
} | |
public var fullName: String { | |
get { | |
"\(firstName) \(lastName)" | |
} | |
} | |
public static var empty: Self = .init(lastName: "Empty", firstName: "Empty") | |
public static var Mock: Self = .init(lastName: "Stephan", firstName: "Danial") | |
} | |
public struct Address: Codable, Equatable { | |
public enum AType: String, Codable, CaseIterable { | |
case home, work, postal, dom, intl, parcel | |
} | |
/// Type: The type of address represented (dom(domestic), intl(international), postal, parcel, home, work) | |
public var type: AType | |
/// postOfficeAddress: Post Office Address | |
public var postOfficeAddress: String? | |
/// ExtendedAddress: Extended Address | |
public var extendedAddress: String? | |
/// Street (eg. 123 Main Street) | |
public var street: String? | |
/// Locality /City (eg. San Francisco) | |
public var locality: String? | |
/// The region/state specifier (eg. CA) | |
public var region: String? | |
/// Post code (eg. 91921) | |
public var postalCode: String? | |
/// Country (eg. USA) | |
public var country: String? | |
/// Create an address for a VCARD style QR Code | |
/// - Parameters: | |
/// - type: The type of address represented (dom(domestic), intl(international), postal, parcel, home, work) | |
/// - postOfficeAddress: Post Office Address | |
/// - extendedAddress: Extended Address | |
/// - street: Street (eg. 123 Main Street) | |
/// - locality: Locality /City (eg. San Francisco) | |
/// - region: The region specifier (eg. CA) | |
/// - postalCode: Post code (eg. 91921) | |
/// - country: Country (eg. USA) | |
public init( | |
type: AType, | |
postOfficeAddress: String?, | |
extendedAddress: String?, | |
street: String?, | |
locality: String?, | |
region: String?, | |
postalCode: String?, | |
country: String? | |
) { | |
self.type = type | |
self.postOfficeAddress = postOfficeAddress | |
self.extendedAddress = extendedAddress | |
self.street = street | |
self.locality = locality | |
self.region = region | |
self.postalCode = postalCode | |
self.country = country | |
} | |
public var vcardRepresentation: String { | |
return "ADR;TYPE=\(self.type):\(self.postOfficeAddress ?? "");\(self.extendedAddress ?? "");\(self.street ?? "");\(self.locality ?? "");\(self.region ?? "");\(self.postalCode ?? "");\(self.country ?? "")\n" | |
} | |
public static var work: Self = .init(type: .work, postOfficeAddress: nil, extendedAddress: nil, street: nil, locality: nil, region: nil, postalCode: nil, country: nil) | |
} | |
public struct Telephone: Codable, Equatable { | |
public enum TType: String, Codable, CaseIterable, Identifiable { | |
public var id: Self { | |
return self | |
} | |
case cell, work, home, fax | |
} | |
public var type: TType | |
public var number: String | |
public init(type: VCard.Telephone.TType, number: String) { | |
self.type = type | |
self.number = number | |
} | |
public static var empty: Self = .init(type: .work, number: "") | |
} | |
public struct SocialMedia: Codable, Equatable { | |
public var facebook: String? | |
public var skype: String? | |
public var instagram: String? | |
public var linkedIn: String? | |
public var twitter: String? | |
public var telegram: String? | |
public var vk: String? | |
public init( | |
facebook: String?, | |
skype: String?, | |
instagram: String?, | |
linkedIn: String?, | |
twitter: String?, | |
telegram: String?, | |
vk: String? | |
) { | |
self.facebook = facebook | |
self.skype = skype | |
self.instagram = instagram | |
self.linkedIn = linkedIn | |
self.twitter = twitter | |
self.telegram = telegram | |
self.vk = vk | |
} | |
public static var empty: Self = .init( | |
facebook: "", | |
skype: "", | |
instagram: "", | |
linkedIn: "", | |
twitter: "", | |
telegram: "", | |
vk: "" | |
) | |
public static var telegram: Self = .init( | |
facebook: "", | |
skype: "", | |
instagram: "", | |
linkedIn: "", | |
twitter: "", | |
telegram: "@iamdev2", | |
vk: "" | |
) | |
} | |
public var position: String? | |
public var formattedName: String | |
public var organization: String? | |
public var photo: String? | |
public var logo: String? | |
public var contact: Contact | |
public var addresses: [Address] = [] | |
public var telephones: [Telephone] = [] | |
public var emails: [String] = [] | |
public var urls: [URL] = [] | |
public var notes: [String] = [] | |
public var website: String? | |
public var socialMedia: SocialMedia? | |
/// Create a QR Code that contains a VCard | |
/// - Parameters: | |
/// - name: The name to be used for the card | |
/// - formattedName: The name as it is to be displayed | |
/// - addresses: User's addresses | |
/// - organization: User's organization | |
/// - position: Job position, functional position or function | |
/// - telephone: An array of phone numbers. Format is (+)number, eg. +61000000000 | |
/// - email: An array of email addresses (simple text, not validated) | |
/// - urls: Associated URLs | |
/// - notes: Some text to be attached to the card | |
public init( | |
contact: Contact, | |
formattedName: String, | |
addresses: [Address] = [], | |
organization: String?, | |
photo: String?, | |
logo: String?, | |
position: String? = nil, | |
telephones: [Telephone] = [], | |
emails: [String] = [], | |
urls: [URL] = [], | |
notes: [String] = [], | |
website: String?, | |
socialMedia: SocialMedia? | |
) { | |
self.contact = contact | |
self.formattedName = formattedName | |
self.organization = organization | |
self.addresses = addresses | |
self.photo = photo | |
self.logo = logo | |
self.position = position | |
self.telephones = telephones | |
self.emails = emails | |
self.urls = urls | |
self.notes = notes | |
self.socialMedia = socialMedia | |
} | |
} | |
public struct GenericPassForm: ReducerProtocol { | |
public struct State: Equatable { | |
@BindingState public var vCard: VCard | |
} | |
} | |
public var body: some View { | |
.... | |
WithViewStore(self.store) { viewStore in | |
GeometryReader { proxy in | |
ZStack(alignment: .center) { | |
Form { | |
Section { | |
ForEach(viewStore.$vCard.emails) { text in | |
TextField( | |
"", | |
text: text, | |
prompt: Text("*Email") | |
.font(.title2) | |
.fontWeight(.medium) | |
) | |
.keyboardType(.emailAddress) | |
.disableAutocorrection(true) | |
.font(.title2) | |
.fontWeight(.medium) | |
.padding(.vertical, 10) | |
} | |
} header: { | |
HStack { | |
Text("Email") | |
.font(.title2) | |
.fontWeight(.medium) | |
Spacer() | |
Button { | |
viewStore.send(.addOneMoreEmailSection) | |
} label: { | |
Image(systemName: "plus.square.on.square") | |
.resizable() | |
.frame(width: 30, height: 30) | |
} | |
} | |
.padding(.vertical, 10) | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment