Skip to content
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

Open
wants to merge 36 commits into
base: develop
Choose a base branch
from

Conversation

ahmdyasser
Copy link
Contributor

No description provided.

Copy link
Contributor

@ahmdmhasn ahmdmhasn left a 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.

@ahmdyasser ahmdyasser changed the title feat: Create product details screen feat: Add logic to product details screen Aug 17, 2022
@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Documentation would be better 😏

Copy link
Contributor

Choose a reason for hiding this comment

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

يعني اعمل ايه 😂😂 ؟

Comment on lines 48 to 78
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()
Copy link
Contributor

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.

Comment on lines 73 to 98

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
}
Copy link
Contributor

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

Copy link
Contributor Author

@ahmdyasser ahmdyasser Sep 4, 2022

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
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants