From 550e907997dae26dbbf6d45c4119e9a1fa8b3b0d Mon Sep 17 00:00:00 2001 From: Vincent Nguyen Date: Wed, 15 Feb 2023 22:24:12 -0600 Subject: [PATCH 1/3] Add everything in Final Doc White X on QR Fix Dietary layout Alert now has name and dietary Profile Reloads on QR scan and loading view Name truncates --- .../ViewControllers/HIProfileCardView.swift | 71 ++++++++++++------- .../HIProfileViewController.swift | 17 ++++- .../HIScanQRCodeViewController.swift | 28 +++----- 3 files changed, 69 insertions(+), 47 deletions(-) diff --git a/HackIllinois/ViewControllers/HIProfileCardView.swift b/HackIllinois/ViewControllers/HIProfileCardView.swift index a0274661..1b679b36 100644 --- a/HackIllinois/ViewControllers/HIProfileCardView.swift +++ b/HackIllinois/ViewControllers/HIProfileCardView.swift @@ -24,7 +24,6 @@ struct HIProfileCardView: View { let baseText = (\HIAppearance.profileBaseText).value let id: String let isIpad = UIDevice.current.userInterfaceIdiom == .pad - let columns = [GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible())] @State var flipped: Bool = false @State var ticketRotation = 0.0 @State var contentRotation = 0.0 @@ -37,11 +36,11 @@ struct HIProfileCardView: View { ZStack { Rectangle() .frame(width: isIpad ? UIScreen.main.bounds.width - 56 * 2 : UIScreen.main.bounds.width - 32 * 2, - height: isIpad ? 978 : 569) + height: isIpad ? 978 + 80 : 569 + 40) .cornerRadius(UIDevice.current.userInterfaceIdiom == .pad ? 40 : 20) .foregroundColor(Color(background)) VStack(spacing: 0) { - Text("\(firstName) \(lastName)") + Text(formatName()) .font(Font(HIAppearance.Font.profileName ?? .systemFont(ofSize: 20))) .foregroundColor(Color(baseText)) .padding(isIpad ? 32 : 16) @@ -104,28 +103,40 @@ struct HIProfileCardView: View { VStack(spacing: isIpad ? 32 : 16) { Text("Dietary Restrictions") .font(Font(HIAppearance.Font.profileDietaryRestrictions ?? .systemFont(ofSize: 16))) - LazyVGrid(columns: columns) { - if dietaryRestrictions.isEmpty { - Rectangle() - .frame(width: isIpad ? 204 : 92, height: isIpad ? 48 : 24) - .cornerRadius(isIpad ? 40 : 20) - .foregroundColor(dietTextColor(diet: "None")) - .overlay( - Text("None") - .font(Font(HIAppearance.Font.profileDietaryRestrictionsLabel ?? .systemFont(ofSize: 12))) - .foregroundColor(.white) - ) - } else { + .foregroundColor(Color(baseText)) + + + VStack { + HStack(spacing: 4) { ForEach(dietaryRestrictions, id: \.self) { diet in - Rectangle() - .frame(width: isIpad ? 204 : 92, height: isIpad ? 48 : 24) - .cornerRadius(isIpad ? 40 : 20) - .foregroundColor(Color(dietBackgroundColor(diet: diet))) - .overlay( - Text(dietString(diet: diet)) - .font(Font(HIAppearance.Font.profileDietaryRestrictionsLabel ?? .systemFont(ofSize: 12))) - .foregroundColor(dietTextColor(diet: diet)) - ) + let index = dietaryRestrictions.firstIndex(of: diet) ?? 0 + if index < 3 { + Rectangle() + .frame(width: isIpad ? 204 : 92, height: isIpad ? 48 : 24) + .cornerRadius(isIpad ? 40 : 20) + .foregroundColor(Color(dietBackgroundColor(diet: diet))) + .overlay( + Text(dietString(diet: diet)) + .font(Font(HIAppearance.Font.profileDietaryRestrictionsLabel ?? .systemFont(ofSize: 12))) + .foregroundColor(dietTextColor(diet: diet)) + ) + } + } + } + HStack(spacing: 4) { + ForEach(dietaryRestrictions, id: \.self) { diet in + let index = dietaryRestrictions.firstIndex(of: diet) ?? 0 + if index > 2 { + Rectangle() + .frame(width: isIpad ? 204 : 92, height: isIpad ? 48 : 24) + .cornerRadius(isIpad ? 40 : 20) + .foregroundColor(Color(dietBackgroundColor(diet: diet))) + .overlay( + Text(dietString(diet: diet)) + .font(Font(HIAppearance.Font.profileDietaryRestrictionsLabel ?? .systemFont(ofSize: 12))) + .foregroundColor(dietTextColor(diet: diet)) + ) + } } } } @@ -135,15 +146,25 @@ struct HIProfileCardView: View { } .padding(.top, 24) } + .preferredColorScheme(.dark) .onAppear { startFetchingQR = true QRFetchLoop() + print("HELLLO") } .onDisappear { startFetchingQR = false } } + func formatName() -> String { + if lastName.count + firstName.count > 20 { + return firstName + " " + lastName.prefix(1) + "." + } else { + return firstName + " " + lastName + } + } + func getQRCodeDate(text: String) -> Data? { guard let filter = CIFilter(name: "CIQRCodeGenerator") else { return nil } let data = text.data(using: .ascii, allowLossyConversion: false) @@ -175,7 +196,7 @@ struct HIProfileCardView: View { return "Custom" } } - + func dietTextColor(diet: String) -> Color { switch diet { case "Vegetarian", "Vegan", "Gluten-Free", "Lactose-Intolerant", "Other": diff --git a/HackIllinois/ViewControllers/HIProfileViewController.swift b/HackIllinois/ViewControllers/HIProfileViewController.swift index 5349bb98..02e767b8 100644 --- a/HackIllinois/ViewControllers/HIProfileViewController.swift +++ b/HackIllinois/ViewControllers/HIProfileViewController.swift @@ -49,18 +49,20 @@ extension HIProfileViewController { extension HIProfileViewController { override func loadView() { super.loadView() - if HIApplicationStateController.shared.isGuest { + guard let user = HIApplicationStateController.shared.user else { return } + if HIApplicationStateController.shared.isGuest || user.roles.contains(.staff) { layoutErrorView() } else { updateProfile() reloadProfile() + NotificationCenter.default.addObserver(self, selector: #selector(updateOnCheckin), name: .qrCodeSuccessfulScan, object: nil) } } override func viewDidLoad() { super.viewDidLoad() super.setCustomTitle(customTitle: "PROFILE") } - + func updateProfileCard() { if addedProfileCard == true { profileCardController?.view.removeFromSuperview() @@ -98,6 +100,13 @@ extension HIProfileViewController { logoutButton.addTarget(self, action: #selector(didSelectLogoutButton(_:)), for: .touchUpInside) } + @objc func updateOnCheckin(_ notification: Notification) { + guard let user = HIApplicationStateController.shared.user else { return } + if !HIApplicationStateController.shared.isGuest && !user.roles.contains(.staff) { + reloadProfile() + } + } + func updateProfile() { updateProfileCard() if tiers.count > 0 { @@ -112,7 +121,11 @@ extension HIProfileViewController { } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) + guard let user = HIApplicationStateController.shared.user else { return } layoutLogOutButton() + if !HIApplicationStateController.shared.isGuest && !user.roles.contains(.staff) { + reloadProfile() + } } } diff --git a/HackIllinois/ViewControllers/HIScanQRCodeViewController.swift b/HackIllinois/ViewControllers/HIScanQRCodeViewController.swift index e4560174..dd743b27 100644 --- a/HackIllinois/ViewControllers/HIScanQRCodeViewController.swift +++ b/HackIllinois/ViewControllers/HIScanQRCodeViewController.swift @@ -36,15 +36,15 @@ class HIScanQRCodeViewController: HIBaseViewController { private let closeButton = HIButton { $0.tintHIColor = \.action $0.backgroundHIColor = \.clear - $0.activeImage = #imageLiteral(resourceName: "DarkCloseButton") - $0.baseImage = #imageLiteral(resourceName: "DarkCloseButton") + $0.activeImage = #imageLiteral(resourceName: "CloseButton") + $0.baseImage = #imageLiteral(resourceName: "CloseButton") } private let errorView = HIErrorView(style: .codePopup) private var selectedEventID = "" private var cancellables = Set() var currentUserID = "" - var currentUserNameLabel = HILabel(style: .detailTitle) - var userDietaryRestrictionsLabel = HILabel(style: .description) + var currentUserName = "" + var dietaryString = "" } // MARK: - UIViewController @@ -73,19 +73,8 @@ extension HIScanQRCodeViewController { let staffButtonController = UIHostingController(rootView: HIStaffButtonView(observable: observable)) addChild(staffButtonController) staffButtonController.view.backgroundColor = .clear - staffButtonController.view.frame = CGRect(x: 0, y: 200, width: Int(view.frame.maxX), height: 500) + staffButtonController.view.frame = CGRect(x: 0, y: 100, width: Int(view.frame.maxX), height: 600) view.addSubview(staffButtonController.view) - - view.addSubview(currentUserNameLabel) - currentUserNameLabel.text = "" - currentUserNameLabel.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 60).isActive = true - currentUserNameLabel.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 20).isActive = true - - view.addSubview(userDietaryRestrictionsLabel) - userDietaryRestrictionsLabel.text = "" - userDietaryRestrictionsLabel.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 60).isActive = true - userDietaryRestrictionsLabel.numberOfLines = 3 - userDietaryRestrictionsLabel.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 50).isActive = true } } view.addSubview(closeButton) @@ -261,7 +250,7 @@ extension HIScanQRCodeViewController: AVCaptureMetadataOutputObjectsDelegate { switch status { case "Success": alertTitle = "Success!" - alertMessage = "Success!" + alertMessage = "Name: \(currentUserName)\n Diet: \(dietaryString)" case "InvalidEventId": alertTitle = "Error!" alertMessage = "Invalid Event ID" @@ -304,14 +293,13 @@ extension HIScanQRCodeViewController: AVCaptureMetadataOutputObjectsDelegate { do { let (apiAttendeeContainer, _) = try result.get() DispatchQueue.main.async { [self] in - var dietaryString = "" + dietaryString = "" for diet in apiAttendeeContainer.dietary ?? [] { dietaryString += diet + ", " } guard let first = apiAttendeeContainer.firstName else { return } guard let last = apiAttendeeContainer.lastName else { return } - currentUserNameLabel.text = first + " " + last - userDietaryRestrictionsLabel.text! = dietaryString + currentUserName = first + " " + last } } catch { print("An error has occurred \(error)") From bad6f3897644c26d5759756e81972a31d3eddb95 Mon Sep 17 00:00:00 2001 From: Vincent Nguyen Date: Thu, 16 Feb 2023 14:17:14 -0600 Subject: [PATCH 2/3] Add deinit --- HackIllinois/UI/HIAppearance.swift | 2 +- HackIllinois/ViewControllers/HIProfileCardView.swift | 1 - HackIllinois/ViewControllers/HIProfileViewController.swift | 6 +++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/HackIllinois/UI/HIAppearance.swift b/HackIllinois/UI/HIAppearance.swift index 8c9973df..b8db4c4c 100644 --- a/HackIllinois/UI/HIAppearance.swift +++ b/HackIllinois/UI/HIAppearance.swift @@ -179,7 +179,7 @@ struct HIAppearance: Equatable { pointsBackground: white, profileCardBackground: lightBlue, profileCardVegetarian: vegetarian, - profileCardVegan: profileBaseText, + profileCardVegan: vegan, profileCardGlutenFree: glutenfree, profileCardLactoseIntolerant: lactoseintolerant, profileCardOther: other, diff --git a/HackIllinois/ViewControllers/HIProfileCardView.swift b/HackIllinois/ViewControllers/HIProfileCardView.swift index 1b679b36..0743b73a 100644 --- a/HackIllinois/ViewControllers/HIProfileCardView.swift +++ b/HackIllinois/ViewControllers/HIProfileCardView.swift @@ -150,7 +150,6 @@ struct HIProfileCardView: View { .onAppear { startFetchingQR = true QRFetchLoop() - print("HELLLO") } .onDisappear { startFetchingQR = false diff --git a/HackIllinois/ViewControllers/HIProfileViewController.swift b/HackIllinois/ViewControllers/HIProfileViewController.swift index 02e767b8..8307da49 100644 --- a/HackIllinois/ViewControllers/HIProfileViewController.swift +++ b/HackIllinois/ViewControllers/HIProfileViewController.swift @@ -18,6 +18,9 @@ import CoreImage.CIFilterBuiltins import SwiftUI class HIProfileViewController: HIBaseViewController { + deinit { + NotificationCenter.default.removeObserver(self) + } // MARK: - Properties private var profile = HIProfile() private var profileTier = "" @@ -47,6 +50,7 @@ extension HIProfileViewController { // MARK: - UIViewController extension HIProfileViewController { + override func loadView() { super.loadView() guard let user = HIApplicationStateController.shared.user else { return } @@ -62,7 +66,7 @@ extension HIProfileViewController { super.viewDidLoad() super.setCustomTitle(customTitle: "PROFILE") } - + func updateProfileCard() { if addedProfileCard == true { profileCardController?.view.removeFromSuperview() From 022ae77fcfa25617e64a323231c1b73668687045 Mon Sep 17 00:00:00 2001 From: Vincent Nguyen Date: Wed, 22 Feb 2023 21:05:39 -0600 Subject: [PATCH 3/3] Fix random alert not having data --- .../HIScanQRCodeViewController.swift | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/HackIllinois/ViewControllers/HIScanQRCodeViewController.swift b/HackIllinois/ViewControllers/HIScanQRCodeViewController.swift index dd743b27..0b45d515 100644 --- a/HackIllinois/ViewControllers/HIScanQRCodeViewController.swift +++ b/HackIllinois/ViewControllers/HIScanQRCodeViewController.swift @@ -286,7 +286,7 @@ extension HIScanQRCodeViewController: AVCaptureMetadataOutputObjectsDelegate { self.present(alert, animated: true, completion: nil) } - func getUserIdData(userID: String) { + func staffCheckIn(userID: String, status: String) { guard let user = HIApplicationStateController.shared.user else { return } HIAPI.RegistrationService.getAttendeeRegistrationUserID(userID: userID) .onCompletion { result in @@ -300,6 +300,7 @@ extension HIScanQRCodeViewController: AVCaptureMetadataOutputObjectsDelegate { guard let first = apiAttendeeContainer.firstName else { return } guard let last = apiAttendeeContainer.lastName else { return } currentUserName = first + " " + last + self.handleStaffCheckInAlert(status: status) } } catch { print("An error has occurred \(error)") @@ -316,12 +317,6 @@ extension HIScanQRCodeViewController: AVCaptureMetadataOutputObjectsDelegate { guard let user = HIApplicationStateController.shared.user else { return } if user.roles.contains(.staff) { if selectedEventID != "" { - if let qrInfo = decode(code) { - if let userId = qrInfo["userId"] { - currentUserID = userId as? String ?? "" - getUserIdData(userID: currentUserID) - } - } if let range = code.range(of: "userToken=") { let userToken = code[range.upperBound...] respondingToQRCodeFound = false @@ -329,8 +324,13 @@ extension HIScanQRCodeViewController: AVCaptureMetadataOutputObjectsDelegate { .onCompletion { result in do { let (codeResult, _) = try result.get() - DispatchQueue.main.async { - self.handleStaffCheckInAlert(status: codeResult.status) + DispatchQueue.main.async { [self] in + if let qrInfo = self.decode(code) { + if let userId = qrInfo["userId"] { + currentUserID = userId as? String ?? "" + staffCheckIn(userID: currentUserID, status: codeResult.status) + } + } } } catch { print(error, error.localizedDescription)