Skip to content

[Woo POS] UI - Cart: Product rows #12749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions WooCommercePOS/WooCommercePOS/Presentation/CartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,43 @@ struct CartView: View {
var body: some View {
VStack {
Text("Cart")
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, 32)
.padding(.vertical, 8)
.font(.title)
.foregroundColor(Color.white)
ForEach(viewModel.productsInCart, id: \.product.productID) { cartProduct in
ProductRowView(cartProduct: cartProduct) {
viewModel.removeProductFromCart(cartProduct)
}
.background(Color.tertiaryBackground)
.padding(.horizontal, 32)
}
Spacer()
Button("Pay now") {
viewModel.submitCart()
}
.background(Color.secondaryBackground)
checkoutButton()
.padding(.horizontal, 32)

}
.frame(maxWidth: .infinity)
.background(Color.secondaryBackground)
}

@ViewBuilder
private func checkoutButton() -> some View {
Button("Checkout") {
viewModel.submitCart()
}
.padding(.all, 20)
.frame(maxWidth: .infinity, idealHeight: 120)
.font(.title)
.foregroundColor(Color.primaryBackground)
.background(Color.white)
.cornerRadius(10)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose @ViewBuilder is not needed. Since there are not if statements etc.

It might be a personal preference, but I prefer having private vars for creating view components like this, so private var checkoutButton: some View instead of a `function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose ViewBuilder is not needed.

You're right! Removed on 8f221c4

It might be a personal preference, but I prefer having private vars for creating view components like this, so private var checkoutButton: some View instead of a `function.

Sounds good to me! Updated on: 84e7f7f

}

#if DEBUG
#Preview {
CartView(viewModel: PointOfSaleDashboardViewModel(products: ProductFactory.makeFakeProducts()))
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ struct ProductCardView: View {
.foregroundStyle(Color.primaryBackground)
HStack(spacing: 8) {
QuantityBadgeView()
.frame(width: 50, height: 50)
.frame(width: 56, height: 56)
Spacer()
Button(action: {
onProductCardTapped?()
}, label: { })
.buttonStyle(PlusButtonStyle())
.frame(width: 50, height: 50)
.frame(width: 56, height: 56)
}
}
.frame(maxWidth: .infinity)
Expand Down
16 changes: 11 additions & 5 deletions WooCommercePOS/WooCommercePOS/Presentation/ProductRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,28 @@ struct ProductRowView: View {
var body: some View {
HStack {
Text(cartProduct.product.name)
.foregroundColor(Color.white)
.padding(.horizontal, 32)
.foregroundColor(Color.primaryBackground)
Spacer()
Button(action: {
onProductRemoveTapped?()
}, label: {
Image(systemName: "minus.circle.fill")
.foregroundColor(Color.white)
Image(systemName: "x.circle")
})
.frame(width: 56, height: 56, alignment: .trailing)
.padding(.horizontal, 32)
.foregroundColor(Color.lightBlue)
.background(Color(.clear))
}
.frame(maxWidth: .infinity)
.border(Color.gray, width: 1)
.frame(maxWidth: .infinity, idealHeight: 120)
.foregroundColor(Color.tertiaryBackground)
}
}

#if DEBUG
#Preview {
ProductRowView(cartProduct: CartProduct(id: UUID(),
product: ProductFactory.makeProduct(),
quantity: 2))
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ extension Color {
return Color(red: 142.0 / 255.0, green: 208.0 / 255.0, blue: 240.0 / 255.0)
}

/// Tertiary POS background color
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the comment ;) I suppose it was a copy paste :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops 😂 Fixed: 84e7f7f

///
static var lightBlue: Color {
return Color(red: 202.0 / 255.0, green: 237.0 / 255.0, blue: 255.0 / 255.0)
}

/// Default POS text color
///
static var primaryText: Color {
Expand Down