-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat: Add logic to product details screen #113
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may need to rename the pull request to be more related to the changes.
Dokan/Dokan/Scenes/ProductDetails/TitleQuantity/ProductTitleQuantityView.swift
Show resolved
Hide resolved
@@ -14,4 +14,6 @@ public protocol ProductRepository { | |||
/// Load all products at a page. Completes with products list or error if any. | |||
/// | |||
func loadProducts(at page: Int, completion: @escaping (Result<[Product], Error>) -> Void) | |||
|
|||
func loadSingleProduct(productID: Int, completion: @escaping (Result<Product, Error>) -> Void) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation would be better 😏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
يعني اعمل ايه 😂😂 ؟
Dokan/Dokan/Scenes/ProductDetails/TitleQuantity/ProductTitleQuantityView.swift
Outdated
Show resolved
Hide resolved
Dokan/Dokan/Scenes/ProductDetails/TitleQuantity/ProductTitleQuantityView.swift
Outdated
Show resolved
Hide resolved
func initView() { | ||
let model: tQViewModel = productViewModel.getproductViewModel() | ||
configureView(viewModel: model) | ||
changeStockBackGroundColor(stockCount: model.stockCount) | ||
} | ||
|
||
func initViewModel() { | ||
|
||
productViewModel.uploadLoadingState = { [weak self] () in | ||
guard let self = self else { return } | ||
|
||
DispatchQueue.main.async { [weak self] in | ||
guard let self = self else { return } | ||
|
||
switch self.productViewModel.state { | ||
|
||
case .loading, .error, .empty: | ||
self.startSkeletonView() | ||
case .populated: | ||
self.stopSkeletonView() | ||
} | ||
} | ||
} | ||
|
||
productViewModel.reloadViewClosure = { [weak self] () in | ||
DispatchQueue.main.async { [weak self] in | ||
self?.initView() | ||
} | ||
} | ||
|
||
productViewModel.initFetchSingleProduct() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code needs more enhancement to handle the case when the view model gets updated and follow single responsibility.
Dokan/Dokan/Scenes/ProductDetails/ProductDetailsViewModel.swift
Outdated
Show resolved
Hide resolved
Dokan/Dokan/Scenes/ProductDetails/ProductDetailsViewModel.swift
Outdated
Show resolved
Hide resolved
Dokan/Dokan/Scenes/ProductDetails/ProductDetailsViewModel.swift
Outdated
Show resolved
Hide resolved
|
||
func getproductViewModel() -> tQViewModel { | ||
return titleQuantityViewModel! | ||
} | ||
|
||
func getImageview(indexPath: IndexPath) -> sliderViewModel { | ||
return imageViewModel[indexPath.row] | ||
} | ||
|
||
private func createProductTitleQuantityView(product: Product) -> tQViewModel { | ||
|
||
return tQViewModel(title: product.title, currency: "$", price: product.price, reviewAverage: 4.8, reviewCount: 23, stockCount: 8) | ||
} | ||
|
||
private func createProductImage(product: Product) -> sliderViewModel { | ||
|
||
return sliderViewModel(productImage: product.thumbnailUrl) | ||
} | ||
|
||
func processFetchProduct(product: Product) { | ||
self.product = product | ||
var imgs = [sliderViewModel]() | ||
titleQuantityViewModel = createProductTitleQuantityView(product: product) | ||
imgs.append(createProductImage(product: product)) | ||
imageViewModel = imgs | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these methods are not accessible in the controller since they're not defined in ProductDetailsViewModelOutput
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this fix it?
protocol ProductDetailsViewModelOutput {
func fetchProduct()
func getproductViewModel() -> TQViewModel
func getImageview(indexPath: IndexPath) -> sliderViewModel
func processFetchProduct(product: Product)
func createProductTitleQuantityView(product: Product) -> TQViewModel
func createProductImage(product: Product) -> sliderViewModel
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dokan/Dokan/Scenes/ProductDetails/ProductDetailsViewModel.swift
Outdated
Show resolved
Hide resolved
…antityView.swift Co-authored-by: Ahmed M. Hassan <[email protected]>
Co-authored-by: Ahmed M. Hassan <[email protected]>
Co-authored-by: Ahmed M. Hassan <[email protected]>
No description provided.