Manos Chorianopoulos

ProfileViewController filter functionality

......@@ -17,6 +17,8 @@ protocol ProfileCouponFiltersTableViewCellDelegate: AnyObject {
weak var delegate: ProfileCouponFiltersTableViewCellDelegate?
var data: [CouponFilterModel]?
var couponFilterSelected: CouponFilterModel?
// var couponFilterSelected: CouponFilterModel = CouponFilterModel(title: "Ενεργά")
public override func awakeFromNib() {
super.awakeFromNib()
......@@ -72,8 +74,9 @@ protocol ProfileCouponFiltersTableViewCellDelegate: AnyObject {
// Configure the view for the selected state
}
func configureCell(data: [CouponFilterModel]?) {
func configureCell(data: [CouponFilterModel]?, couponFilterSelected: CouponFilterModel) {
self.data = data
self.couponFilterSelected = couponFilterSelected
self.collectionView.reloadData();
}
......@@ -93,8 +96,9 @@ extension ProfileCouponFiltersTableViewCell: UICollectionViewDataSource, UIColle
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ProfileFilterCollectionViewCell", for: indexPath) as! ProfileFilterCollectionViewCell
if let filter = self.data?[indexPath.row] {
// TODO: Fix dynamic
let isSelected = self.data?[indexPath.row].title == "Ενεργά"
// let isSelected = self.data?[indexPath.row].title == "Ενεργά"
// let isSelected = self.data?[indexPath.row].title == self.couponFilterSelected.title
let isSelected = self.data?[indexPath.row].title == self.couponFilterSelected?.title ?? "Ενεργά"
cell.configureCell(data: filter, isSelected: isSelected)
}
return cell;
......
......@@ -242,7 +242,7 @@ import UIKit
// Favorite Offers
let redeemedOffers = allOffers.filter { $0.redeemed ?? false }
redeemedOffersSection = SectionModel(
title: "Αγαπημένα",
title: "Εξαργυρωμένα",
count: redeemedOffers.count,
offers: redeemedOffers
)
......@@ -256,6 +256,19 @@ import UIKit
self.navigationController?.pushViewController(vc, animated: true)
}
private func handleFilterPress(with filter: CouponFilterModel) {
switch (filter.title) {
case "Ενεργά":
self.filteredOffersSection = activeOffersSection
case "Αγαπημένα":
self.filteredOffersSection = favoriteOffersSection
case "Εξαργυρωμένα":
self.filteredOffersSection = redeemedOffersSection
default:
self.filteredOffersSection = activeOffersSection
}
}
}
// MARK: - TableView
......@@ -328,7 +341,7 @@ extension ProfileViewController: UITableViewDelegate, UITableViewDataSource {
let cell = tableView.dequeueReusableCell(withIdentifier: "ProfileCouponFiltersTableViewCell", for: indexPath) as! ProfileCouponFiltersTableViewCell
cell.delegate = self // Set the offers delegate
cell.configureCell(data: self.couponFilters)
cell.configureCell(data: self.couponFilters, couponFilterSelected: self.couponFilterSelected)
return cell
......@@ -343,25 +356,12 @@ extension ProfileViewController: UITableViewDelegate, UITableViewDataSource {
}
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if (indexPath.section == 0) {
// Do nothing - Each button is handled differently
} else if (indexPath.section == 1) {
// Do nothing
} else if (indexPath.section == 2) {
// Do nothing
} else if (indexPath.section == 3) {
// Do nothing
} else if (indexPath.section == 4) {
// Do nothing
} else if (indexPath.section == 5) {
// Do nothing
} else if (indexPath.section == 6) {
// Do nothing
} else if (indexPath.section == 7) {
if (indexPath.section <= 3) {
// Do nothing
} else {
// Do nothing
if let offer = self.filteredOffersSection?.offers[indexPath.row] {
openCouponViewController(with: offer)
}
}
}
}
......@@ -378,6 +378,7 @@ extension ProfileViewController: MyRewardsOffersScrollTableViewCellDelegate {
extension ProfileViewController: ProfileCouponFiltersTableViewCellDelegate {
func didSelectFilter(_ filter: CouponFilterModel) {
self.couponFilterSelected = filter
handleFilterPress(with: filter)
self.tableView.reloadData()
}
}
......