Skip to content

Commit

Permalink
[FEAT] DO-NOTTO-DO#86 - 선택한 날짜 API 함수로 전달 및 reload 시점 변경
Browse files Browse the repository at this point in the history
[FEAT] DO-NOTTO-DO#86 - 선택한 날짜 API 함수로 전달 및 reload 시점 변경
  • Loading branch information
yungu0010 authored Jan 13, 2023
2 parents 83e5c9f + f4e97bb commit aeee3cc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -123,8 +125,7 @@ extension ActionSheetViewController {

@objc private func deleteButtonDidTap() {
requestDeleteMission(id: id)
delegate?.reloadMissionData()
self.dismiss(animated: true)

}

@objc private func choiceFinishButtonDidTap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ extension HomeCalendarCollectionViewCell {
$0.collectionView.snp.makeConstraints {
$0.edges.equalToSuperview()
}
$0.delegate = self
$0.dataSource = self
}
}

Expand All @@ -86,7 +84,3 @@ extension HomeCalendarCollectionViewCell {
}
}
}

extension HomeCalendarCollectionViewCell: FSCalendarDataSource, FSCalendarDelegate {

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import UIKit

import SnapKit
import Then
import FSCalendar

final class HomeViewController: UIViewController {

Expand All @@ -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

Expand Down Expand Up @@ -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 ?? "")

}
}

Expand All @@ -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() {
Expand All @@ -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 }
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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 ?? "")
}
}

0 comments on commit aeee3cc

Please sign in to comment.