Skip to content

Commit

Permalink
ALFMOB-40: Code review, added view model for VerticalProductCard
Browse files Browse the repository at this point in the history
  • Loading branch information
timea-v committed Nov 22, 2024
1 parent 4b87774 commit d6fe68e
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 144 deletions.
6 changes: 4 additions & 2 deletions Alfie/Alfie/Views/ProductListing/ProductListingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ struct ProductListingView<ViewModel: ProductListingViewModelProtocol>: View {
LazyVGrid(columns: gridStruct, spacing: Spacing.space200) {
ForEach(viewModel.products) { product in
VerticalProductCard(
configuration: .init(size: viewModel.style == .list ? .large : .medium),
product: product,
viewModel: .init(
configuration: .init(size: viewModel.style == .list ? .large : .medium),
product: product
),
onUserAction: { _, type in
handleUserAction(forProduct: product, actionType: type)
},
Expand Down
6 changes: 4 additions & 2 deletions Alfie/Alfie/Views/SearchView/SearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,10 @@ extension SearchView {

private func productCardView(_ product: Product) -> some View {
VerticalProductCard(
configuration: .init(size: .medium, hidePrice: true, hideAction: true),
product: product
viewModel: .init(
configuration: .init(size: .medium, hidePrice: true, hideAction: true),
product: product
)
) { _, _ in }
.onTapGesture {
coordinator.openDetails(for: product)
Expand Down
25 changes: 13 additions & 12 deletions Alfie/Alfie/Views/WishListView/WishListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ struct WishListView<ViewModel: WishListViewModelProtocol>: View {
) {
ForEach(viewModel.products) { product in
VerticalProductCard(
configuration: .init(size: .medium, hideDetails: false, actionType: .remove),
product: product,
onUserAction: { _, type in
handleUserAction(forProduct: product, actionType: type)
},
colorTitle: LocalizableGeneral.$color + ":",
sizeTitle: LocalizableGeneral.$size + ":",
oneSizeTitle: LocalizableGeneral.$oneSize,
addToBagTitle: LocalizableGeneral.$addToBag,
outOfStockTitle: LocalizableGeneral.$outOfStock,
isAddToBagDisabled: product.defaultVariant.stock == .zero
)
viewModel: .init(
configuration: .init(size: .medium, hideDetails: false, actionType: .remove),
product: product,
colorTitle: LocalizableGeneral.$color + ":",
sizeTitle: LocalizableGeneral.$size + ":",
oneSizeTitle: LocalizableGeneral.$oneSize,
addToBagTitle: LocalizableGeneral.$addToBag,
outOfStockTitle: LocalizableGeneral.$outOfStock,
isAddToBagDisabled: product.defaultVariant.stock == .zero
)
) { _, type in
handleUserAction(forProduct: product, actionType: type)
}
}
}
.padding(.horizontal, Spacing.space200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extension Product {
} else {
fixtures.map { fixture in
Product(
id: fixture.id,
styleNumber: fixture.styleNumber,
name: fixture.name,
brand: fixture.brand,
Expand Down Expand Up @@ -59,6 +60,7 @@ extension Product {
// MARK: - Necklace -

public static let necklace = Product(
id: "1",
styleNumber: "26427344",
name: "Sardinia Necklace",
brand: .init(name: "Amber Sceats", slug: "amber-sceats"),
Expand Down Expand Up @@ -95,6 +97,7 @@ extension Product {
// MARK: - Blazer -

public static let blazer = Product(
id: "2",
styleNumber: "26533700",
name: "June Double Breasted Blazer",
brand: .init(name: "Reiss", slug: "reiss"),
Expand Down Expand Up @@ -134,6 +137,7 @@ extension Product {
// MARK: - Dress -

public static let dress = Product(
id: "3",
styleNumber: "26320534",
name: "Tie front shirt dress",
brand: .init(name: "Gucci", slug: "gucci"),
Expand Down Expand Up @@ -173,6 +177,7 @@ extension Product {
// MARK: - Hat -

public static let hat = Product(
id: "4",
styleNumber: "26626706",
name: "Baseball hat with Gucci print | Baseball hat with Gucci print | Baseball hat with Gucci print",
brand: .init(name: "Gucci", slug: "gucci"),
Expand Down Expand Up @@ -214,6 +219,7 @@ extension Product {
// MARK: - Neck Dress -

public static let neckDress = Product(
id: "5",
styleNumber: "26203353",
name: "Admiral Crepe Funnel Neck Dress",
brand: .init(name: "Theory", slug: "theory"),
Expand Down Expand Up @@ -253,6 +259,7 @@ extension Product {
// MARK: - Sandal -

public static let sandal = Product(
id: "6",
styleNumber: "26241404",
name: "Women's Verona Sandal",
brand: .init(name: "Alias Mae", slug: "alias-mae"),
Expand Down Expand Up @@ -289,6 +296,7 @@ extension Product {
// MARK: - Jacket -

public static let jacket = Product(
id: "7",
styleNumber: "26630621",
name: "Maltese Rain Jacket",
brand: .init(name: "C&M Camilla & Marc | C&M Camilla & Marc", slug: "c-and-m-camilla-and-marc"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public struct ProductCarouselView<Header: View, Content: View, DataType: Identif
)
},
content: { product in
VerticalProductCard(configuration: .init(size: .small), product: product) { _, _ in }
VerticalProductCard(viewModel: .init(configuration: .init(size: .small), product: product)) { _, _ in }
}
)
}
Loading

0 comments on commit d6fe68e

Please sign in to comment.