From f5a7caa0b5406636c51c4a1759197c1f6f3dd2ba Mon Sep 17 00:00:00 2001 From: anushkasankaran Date: Thu, 20 Feb 2025 00:06:13 -0600 Subject: [PATCH 1/3] Temp loading for pictures --- .../HIPointsShopSwiftUIView.swift | 64 +++++++++++++++---- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/HackIllinois/ViewControllers/HIPointsShopSwiftUIView.swift b/HackIllinois/ViewControllers/HIPointsShopSwiftUIView.swift index 109f987c..6c0977cb 100644 --- a/HackIllinois/ViewControllers/HIPointsShopSwiftUIView.swift +++ b/HackIllinois/ViewControllers/HIPointsShopSwiftUIView.swift @@ -32,6 +32,7 @@ class PointShopManager: ObservableObject { do { let (containedItem, _) = try result.get() self.items = containedItem.items + print("Loaded point shop items") } catch { print("Failed to preload point shop items with error: \(error)") } @@ -290,7 +291,6 @@ struct HIPointShopSwiftUIView: View { DispatchQueue.main.async { do { let (containedItem, _) = try result.get() - // ✅ Update the manager’s items shopManager.items = containedItem.items } catch { print("Failed to reload points shop: \(error)") @@ -411,6 +411,7 @@ struct PointShopItemCell: View { let item: Item @Binding var showError: Bool @Binding var errorMessage: [String] + @State private var image: UIImage? = nil var body: some View { ZStack { @@ -427,12 +428,19 @@ struct PointShopItemCell: View { .frame(width: 75 * (UIScreen.main.bounds.width/428)) // Item image - Image(systemName: "Profile0") - .data(url: URL(string: item.imageURL)!) - .resizable() - .scaledToFit() - .frame(width: 60 * (UIScreen.main.bounds.width/428), height: 60 * (UIScreen.main.bounds.width/428)) - + if let image = image { + Image(uiImage: image) + .resizable() + .scaledToFit() + .frame(width: 60 * (UIScreen.main.bounds.width/428), height: 60 * (UIScreen.main.bounds.width/428)) + } else { + ProgressView() // Placeholder while loading + .frame(width: 60 * (UIScreen.main.bounds.width/428), height: 60 * (UIScreen.main.bounds.width/428)) + .onAppear { + loadImage() + } + } + // Price + quantity HStack(spacing: 4) { Image("Coin") @@ -477,6 +485,18 @@ struct PointShopItemCell: View { alignment: .topTrailing ) } + + private func loadImage() { + guard let url = URL(string: item.imageURL) else { return } + + URLSession.shared.dataTask(with: url) { data, response, error in + if let data = data, let loadedImage = UIImage(data: data) { + DispatchQueue.main.async { + self.image = loadedImage + } + } + }.resume() + } } struct CartItemCell: View { @@ -484,6 +504,7 @@ struct CartItemCell: View { let item: Item @Binding var showError: Bool @Binding var errorMessage: [String] + @State private var image: UIImage? = nil var body: some View { ZStack { @@ -500,11 +521,18 @@ struct CartItemCell: View { .frame(width: 75 * (UIScreen.main.bounds.width/428)) // Item image - Image(systemName: "Profile0") - .data(url: URL(string: item.imageURL)!) - .resizable() - .scaledToFit() - .frame(width: 60 * (UIScreen.main.bounds.width/428), height: 60 * (UIScreen.main.bounds.width/428)) + if let image = image { + Image(uiImage: image) + .resizable() + .scaledToFit() + .frame(width: 60 * (UIScreen.main.bounds.width/428), height: 60 * (UIScreen.main.bounds.width/428)) + } else { + ProgressView() // Placeholder while loading + .frame(width: 60 * (UIScreen.main.bounds.width/428), height: 60 * (UIScreen.main.bounds.width/428)) + .onAppear { + loadImage() + } + } // Price + quantity HStack(spacing: 4) { @@ -553,6 +581,18 @@ struct CartItemCell: View { .frame(width: 140 * (UIScreen.main.bounds.width/428), height: 140 * (UIScreen.main.bounds.width/428)) .cornerRadius(12) } + + private func loadImage() { + guard let url = URL(string: item.imageURL) else { return } + + URLSession.shared.dataTask(with: url) { data, response, error in + if let data = data, let loadedImage = UIImage(data: data) { + DispatchQueue.main.async { + self.image = loadedImage + } + } + }.resume() + } } func addItemToCart(view: Int, showError: Binding, errorMessage: Binding<[String]>, itemId: String, completion: @escaping (String) -> Void) { From b94c5b54a2704de577ef7cc886b5e4148ac6f5bc Mon Sep 17 00:00:00 2001 From: anushkasankaran Date: Thu, 20 Feb 2025 00:11:48 -0600 Subject: [PATCH 2/3] Notify when cart is empty instead of displaying QR --- .../ViewControllers/HIPointsShopSwiftUIView.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/HackIllinois/ViewControllers/HIPointsShopSwiftUIView.swift b/HackIllinois/ViewControllers/HIPointsShopSwiftUIView.swift index 6c0977cb..1dd06de6 100644 --- a/HackIllinois/ViewControllers/HIPointsShopSwiftUIView.swift +++ b/HackIllinois/ViewControllers/HIPointsShopSwiftUIView.swift @@ -265,7 +265,7 @@ struct HIPointShopSwiftUIView: View { } Spacer() } - if startFetchingQR { + if startFetchingQR && !cartManager.items.isEmpty { VStack { Text("SCAN HERE TO COMPLETE PURCHASE") .padding(.bottom, 50) @@ -277,6 +277,14 @@ struct HIPointShopSwiftUIView: View { .scaledToFit() .frame(width: 250 * resizeFactor[0], height: 250 * resizeFactor[0]) } + } else if cartManager.items.isEmpty { + Text("CART IS EMPTY") + .font(Font.custom("Montserrat", size: 24).weight(.bold)) + .padding() + .background( + RoundedRectangle(cornerRadius: 12) + .fill(Color(red: 255 / 255, green: 247 / 255, blue: 240 / 255)) + ) } } .overlay(showError ? ErrorPopup(title: errorMessage[0], description: errorMessage[1], show: $showError) : nil) From e8b8f20af678b012229c877187978876f781d5c6 Mon Sep 17 00:00:00 2001 From: anushkasankaran Date: Thu, 20 Feb 2025 00:24:48 -0600 Subject: [PATCH 3/3] Multiline names for points shop items --- .../ViewControllers/HIPointsShopSwiftUIView.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/HackIllinois/ViewControllers/HIPointsShopSwiftUIView.swift b/HackIllinois/ViewControllers/HIPointsShopSwiftUIView.swift index 1dd06de6..09559865 100644 --- a/HackIllinois/ViewControllers/HIPointsShopSwiftUIView.swift +++ b/HackIllinois/ViewControllers/HIPointsShopSwiftUIView.swift @@ -433,7 +433,9 @@ struct PointShopItemCell: View { .font(.caption) .foregroundColor(.white) .multilineTextAlignment(.center) - .frame(width: 75 * (UIScreen.main.bounds.width/428)) + .frame(width: 100 * (UIScreen.main.bounds.width / 428)) + .lineLimit(2) // Allows up to two lines + .fixedSize(horizontal: false, vertical: true) // Item image if let image = image { @@ -526,7 +528,9 @@ struct CartItemCell: View { .font(.caption) .foregroundColor(.white) .multilineTextAlignment(.center) - .frame(width: 75 * (UIScreen.main.bounds.width/428)) + .frame(width: 100 * (UIScreen.main.bounds.width / 428)) + .lineLimit(2) // Allows up to two lines + .fixedSize(horizontal: false, vertical: true) // Item image if let image = image {