diff --git a/NotToDo/NotToDo/Presentation/Common/ActionSheet/ActionSheetViewController.swift b/NotToDo/NotToDo/Presentation/Common/ActionSheet/ActionSheetViewController.swift index 8051ede..6d5f15e 100644 --- a/NotToDo/NotToDo/Presentation/Common/ActionSheet/ActionSheetViewController.swift +++ b/NotToDo/NotToDo/Presentation/Common/ActionSheet/ActionSheetViewController.swift @@ -101,8 +101,10 @@ extension ActionSheetViewController { private func requestDeleteMission(id: Int) { HomeAPI.shared.deleteMission(id: id) { [weak self] response in - guard self != nil else { return } + guard let self = self else { return } guard response != nil else { return } + self.delegate?.reloadMissionData() + self.dismiss(animated: true) } } @@ -123,8 +125,7 @@ extension ActionSheetViewController { @objc private func deleteButtonDidTap() { requestDeleteMission(id: id) - delegate?.reloadMissionData() - self.dismiss(animated: true) + } @objc private func choiceFinishButtonDidTap() { diff --git a/NotToDo/NotToDo/Presentation/HomeScene/Cells/HomeCalendarCollectionViewCell.swift b/NotToDo/NotToDo/Presentation/HomeScene/Cells/HomeCalendarCollectionViewCell.swift index 4243e0d..6cc1d53 100644 --- a/NotToDo/NotToDo/Presentation/HomeScene/Cells/HomeCalendarCollectionViewCell.swift +++ b/NotToDo/NotToDo/Presentation/HomeScene/Cells/HomeCalendarCollectionViewCell.swift @@ -70,8 +70,6 @@ extension HomeCalendarCollectionViewCell { $0.collectionView.snp.makeConstraints { $0.edges.equalToSuperview() } - $0.delegate = self - $0.dataSource = self } } @@ -86,7 +84,3 @@ extension HomeCalendarCollectionViewCell { } } } - -extension HomeCalendarCollectionViewCell: FSCalendarDataSource, FSCalendarDelegate { - -} diff --git a/NotToDo/NotToDo/Presentation/HomeScene/ViewControllers/HomeViewController.swift b/NotToDo/NotToDo/Presentation/HomeScene/ViewControllers/HomeViewController.swift index 1d55bda..885620a 100644 --- a/NotToDo/NotToDo/Presentation/HomeScene/ViewControllers/HomeViewController.swift +++ b/NotToDo/NotToDo/Presentation/HomeScene/ViewControllers/HomeViewController.swift @@ -9,6 +9,7 @@ import UIKit import SnapKit import Then +import FSCalendar final class HomeViewController: UIViewController { @@ -17,6 +18,8 @@ final class HomeViewController: UIViewController { var missionList: [DailyMissionResponseDTO] = [] var banner: BannerResponseDTO? var missionId: Int? + private var clickedDay: String? + private let dateFormatter = DateFormatter() // MARK: - UI Components @@ -55,8 +58,8 @@ extension HomeViewController: CheckboxToolTipDelegate { extension HomeViewController: ActionSheetViewDelegate { func reloadMissionData() { requestWeeklyMissoinAPI(startDate: "2023-01-23") - requestDailyMissionAPI(date: "2023-01-25") - homeView.homeCollectionView.reloadData() + requestDailyMissionAPI(date: clickedDay ?? "") + } } @@ -69,6 +72,11 @@ extension HomeViewController: UICollectionViewDelegate { $0.refreshControl?.addTarget(self, action: #selector(handleRefreshControl), for: .valueChanged) } + + dateFormatter.do { + $0.locale = Locale(identifier: "ko_KR") + $0.dateFormat = "yyyy-MM-dd" + } } private func setAddTarget() { @@ -95,7 +103,7 @@ extension HomeViewController: UICollectionViewDelegate { } private func requestDailyMissionAPI(date: String) { - HomeAPI.shared.getDailyMission(date: "2023-01-25") { [weak self] result in + HomeAPI.shared.getDailyMission(date: date) { [weak self] result in switch result { case let .success(data): guard let data = data as? [DailyMissionResponseDTO] else { return } @@ -162,6 +170,7 @@ extension HomeViewController: UICollectionViewDataSource { switch indexPath.section { case 0: guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: HomeCalendarCollectionViewCell.identifier, for: indexPath) as? HomeCalendarCollectionViewCell else { return UICollectionViewCell() } + cell.calendar.delegate = self return cell default: if missionList.isEmpty { @@ -186,6 +195,7 @@ extension HomeViewController: UICollectionViewDataSource { actionSheetViewController.modalPresentationStyle = .overFullScreen actionSheetViewController.modalTransitionStyle = .crossDissolve actionSheetViewController.id = missionId + actionSheetViewController.delegate = self actionSheetViewController.situation = self?.missionList[indexPath.row].situation ?? "" actionSheetViewController.mission = self?.missionList[indexPath.row].title ?? "" self?.present(actionSheetViewController, animated: true) @@ -271,3 +281,10 @@ extension HomeViewController: UICollectionViewDelegateFlowLayout { } } } + +extension HomeViewController: FSCalendarDelegate { + func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) { + clickedDay = dateFormatter.string(from: date) + requestDailyMissionAPI(date: clickedDay ?? "") + } +}