- removed toast msg for guest signup.

- fixed the product listing issue inside shop products
This commit is contained in:
2024-10-17 19:25:38 +05:30
parent 4ef01bafd7
commit 821988ff41
9 changed files with 89 additions and 51 deletions

View File

@@ -19,8 +19,14 @@ class ShopProductsVM{
var selectedSubCategory = 0
var pageTitle : String?
// var pageNo = 0
// var stopFetch = false
// PAgination variables
var pageNo = 0
var stopFetch = false
var isShopDataLoading = false
var totalDataCount = 0 // this will hold the total count from api
var cartButton: UIBarButtonItem!
var bottomBanner = GADBannerView()
@@ -92,10 +98,11 @@ class ShopProductsVM{
self.subCategoryData.append(contentsOf: data)
self.selectedSubCategory = -1
self.vc.subCategoryCV.reloadData()
if let subCatID = data.first?.id{
Utilities.startProgressHUD()
self.getShopProducts(subCategoryID: subCatID)
}
// if let subCatID = data.first?.id{
// }
Utilities.startProgressHUD()
self.getShopProducts(subCategoryID: selectedSubCategory)
self.vc.noDataStack.isHidden = true
default:
Utilities.dismissProgressHUD()
@@ -131,6 +138,7 @@ class ShopProductsVM{
case .success(let data):
guard let self else{
Utilities.dismissProgressHUD()
self?.isShopDataLoading = false
return
}
switch data.success{
@@ -140,7 +148,7 @@ class ShopProductsVM{
*/
Utilities.dismissProgressHUD()
vc.spinnerView.stopAnimating()
if stopFetch == true { return}
self.isShopDataLoading = false
Utilities.alertWithBtnCompletion(title: "Error", msgBody: data.message ?? K.ConstantString.unRecognised, okBtnStr: "Retry?", vc: self.vc) { isDone in
if isDone{
self.getShopProducts(subCategoryID: subCategoryID)
@@ -149,15 +157,18 @@ class ShopProductsVM{
case 1:
Utilities.dismissProgressHUD()
vc.spinnerView.stopAnimating()
self.isShopDataLoading = false
guard let count = data.data?.totalRecords ,let data = data.data?.result else{return}
self.totalDataCount = count
if pageNo == 0{
self.shopProductsData.removeAll()
}
pageNo += 1
self.shopProductsData.append(contentsOf: data)
self.vc.productCV.reloadData()
if self.shopProductsData.count == count{
stopFetch = true
}
/*
check for single product
@@ -174,27 +185,28 @@ class ShopProductsVM{
/*
If ads found then only load it or else directly append the data and reload
*/
if let adsData = AuthFunc.shareInstance.adsData{
// check if ads data contains ad for webseries
if let shopSuperCatAd = adsData.result?.filter({$0.slug == AdsEnum.shop_super_category.rawValue}).first{
if shopSuperCatAd.googleAd != nil{
//setup google banner ads.
AdReusable.sharedInstance.setupBannerAd(bannerView: self.bottomBanner, in: vc.adView, adUnitID: K.GoogleAdIDs.shop, viewController: self.vc, height: 8, width: 15)
}
if bottomBanner.isHidden == false {return}
if let adsData = AuthFunc.shareInstance.adsData, let shopSuperCatAd = adsData.result?.filter({$0.slug == AdsEnum.shop_super_category.rawValue}).first {
if shopSuperCatAd.googleAd != nil{
//setup google banner ads.
AdReusable.sharedInstance.setupBannerAd(bannerView: self.bottomBanner, in: vc.adView, adUnitID: K.GoogleAdIDs.shop, viewController: self.vc, height: 8, width: 15)
}
}
default:
Utilities.dismissProgressHUD()
vc.spinnerView.stopAnimating()
self.isShopDataLoading = false
break
}
case .failure(let error):
guard let self else{
Utilities.dismissProgressHUD()
self?.vc.spinnerView.stopAnimating()
self?.isShopDataLoading = false
return
}
Utilities.dismissProgressHUD()
self.isShopDataLoading = false
vc.spinnerView.stopAnimating()
Utilities.alertWithBtnCompletion(title: "Error", msgBody: error.localizedDescription, okBtnStr: "Retry?", vc: self.vc) { isDone in
// if isDone{
@@ -206,6 +218,36 @@ class ShopProductsVM{
}
}
// MARK: - Animating scrollView
extension ShopProductsVC: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
// dont do network call if the showdata count is same as the total count provided by api
// also check if already the api call is done
if vm.shopProductsData.count == vm.totalDataCount || vm.isShopDataLoading == true {return}
let contentHeight = scrollView.contentSize.height
let height = scrollView.frame.size.height
// Get the current vertical offset of the scroll view
let y = scrollView.contentOffset.y
// Check if the user scrolled to the bottom
if y > contentHeight - height * 1.6{
// check if internet is available
if CheckReachability.reachability?.isReachable == false{
return
}
spinnerView.startAnimating()
vm.isShopDataLoading = true
vm.getShopProducts(subCategoryID: vm.selectedSubCategory)
}
}
}
class FooterSpinnerView: UICollectionReusableView {
override init(frame: CGRect) {