diff --git a/Projects/Presentation/Sources/Home/View/HomeView.swift b/Projects/Presentation/Sources/Home/View/HomeView.swift index 79b02243..91df0c67 100644 --- a/Projects/Presentation/Sources/Home/View/HomeView.swift +++ b/Projects/Presentation/Sources/Home/View/HomeView.swift @@ -106,13 +106,13 @@ final class HomeView: BaseViewController { configureGradientBackground() showIndicatorView() viewModel.action(input: .loadNickname) - viewModel.action(input: .fetchRoutines) } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) configureNavigationBar(navigationStyle: .hidden) viewModel.action(input: .loadEmotion) + viewModel.action(input: .fetchRoutines) } override func viewDidLayoutSubviews() { diff --git a/Projects/Presentation/Sources/Home/ViewModel/HomeViewModel.swift b/Projects/Presentation/Sources/Home/ViewModel/HomeViewModel.swift index c3e3c8d8..8f62576a 100644 --- a/Projects/Presentation/Sources/Home/ViewModel/HomeViewModel.swift +++ b/Projects/Presentation/Sources/Home/ViewModel/HomeViewModel.swift @@ -99,7 +99,7 @@ final class HomeViewModel: ViewModel { updateRoutineCompletion(updatedRoutine: updatedRoutine) case .refreshSelectedDateRoutine: - fetchRoutines(for: selectedDateSubject.value) + fetchDailyRoutine(for: selectedDateSubject.value) case .selectRoutineSortType(let routineSortType): sortRoutine(routineSortType: routineSortType) @@ -135,17 +135,51 @@ final class HomeViewModel: ViewModel { // MARK: - 루틴 // 루틴들을 불러옵니다. (처음에는 +-1 주, 그 이후에는 1주씩) private func fetchRoutines() { - var startDate = oldestDate - var endDate = latestDate - if routines.isEmpty { - startDate = calendar.date(byAdding: .weekOfYear, value: -1, to: today) ?? today - endDate = calendar.date(byAdding: .weekOfYear, value: 1, to: today) ?? today + oldestDate = calendar.date(byAdding: .weekOfYear, value: -1, to: today) ?? today + latestDate = calendar.date(byAdding: .weekOfYear, value: 1, to: today) ?? today + } + fetchRoutines(startDate: oldestDate, endDate: latestDate) + } + + // 날짜를 선택하고 그 날에 해당하는 루틴을 불러옵니다. + private func selectDate(date: Date) { + selectedDateSubject.send(date) + fetchRoutines() + fetchDailyRoutine(for: date) + } + + private func fetchDailyRoutine(for date: Date) { + if let dailyRoutines = routines[date.convertToString(dateType: .yearMonthDate)] { + routinesSubject.send(dailyRoutines) + return + } + var startDate: Date = Date() + var endDate: Date = Date() + if date < oldestDate { + // 캐싱된 데이터보다 이전의 날짜 조회 시, + startDate = calendar.date(byAdding: .weekOfYear, value: -1, to: oldestDate) ?? oldestDate + endDate = calendar.date(byAdding: .day, value: -1, to: oldestDate) ?? oldestDate oldestDate = startDate + } else if date > latestDate { + // 캐싱된 데이터보다 이후의 날짜 조회 시, + startDate = calendar.date(byAdding: .day, value: 1, to: latestDate) ?? latestDate + endDate = calendar.date(byAdding: .weekOfYear, value: 1, to: latestDate) ?? latestDate latestDate = endDate } + fetchRoutines(startDate: startDate, endDate: endDate) + + if let dailyRoutines = routines[date.convertToString(dateType: .yearMonthDate)] { + routinesSubject.send(dailyRoutines) + return + } else { + routinesSubject.send([]) + } + } + // 서버로부터 루틴들을 불러옵니다.. (루틴 조회 시작 날짜 ~ 루틴 조회 종료 날짜) + private func fetchRoutines(startDate: Date, endDate: Date) { Task { do { let entities = try await routineUseCase.fetchRoutines(startDate: startDate, endDate: endDate) @@ -154,35 +188,11 @@ final class HomeViewModel: ViewModel { } fetchRoutineResultSubject.send(true) } catch { - + // TODO: 에러 처리 } } } - // 날짜를 선택하고 그 날에 해당하는 루틴을 불러옵니다. - private func selectDate(date: Date) { - selectedDateSubject.send(date) - fetchRoutines(for: date) - } - - // 선택한 날의 루틴을 필터링하여 보여줍니다. (oldestDate, latestDate 업데이트) - private func fetchRoutines(for date: Date) { - if date <= oldestDate { - oldestDate = calendar.date(byAdding: .weekOfYear, value: -1, to: date) ?? date - latestDate = calendar.date(byAdding: .day, value: -1, to: date) ?? date - } else if date >= latestDate { - oldestDate = calendar.date(byAdding: .day, value: 1, to: date) ?? date - latestDate = calendar.date(byAdding: .weekOfYear, value: 1, to: date) ?? date - } - - let dateKey = date.convertToString(dateType: .yearMonthDate) - guard let dailyRoutines = routines[dateKey] else { - fetchRoutines() - return - } - routinesSubject.send(dailyRoutines) - } - // 반복 루틴을 삭제합니다. private func deleteAllRoutine() { guard let routineId = selectedRoutineSubject.value?.id diff --git a/Projects/Presentation/Sources/RecommendedRoutine/View/RecommendedRoutineView.swift b/Projects/Presentation/Sources/RecommendedRoutine/View/RecommendedRoutineView.swift index 5a86fc1a..c35f123c 100644 --- a/Projects/Presentation/Sources/RecommendedRoutine/View/RecommendedRoutineView.swift +++ b/Projects/Presentation/Sources/RecommendedRoutine/View/RecommendedRoutineView.swift @@ -327,6 +327,7 @@ extension RecommendedRoutineView: FloatingMenuViewDelegate { fatalError("routineCreationViewModel 의존성이 등록되지 않았습니다.") } let routineCreationView = RoutineCreationView(viewModel: routineCreationViewModel) + routineCreationView.hidesBottomBarWhenPushed = true self.navigationController?.pushViewController(routineCreationView, animated: true) } } diff --git a/Projects/Presentation/Sources/ResultRecommendedRoutine/View/ResultRecommendedRoutineView.swift b/Projects/Presentation/Sources/ResultRecommendedRoutine/View/ResultRecommendedRoutineView.swift index a8960c73..e4585f69 100644 --- a/Projects/Presentation/Sources/ResultRecommendedRoutine/View/ResultRecommendedRoutineView.swift +++ b/Projects/Presentation/Sources/ResultRecommendedRoutine/View/ResultRecommendedRoutineView.swift @@ -368,6 +368,7 @@ final class ResultRecommendedRoutineView: BaseViewController Bool { - if let text = textField.text { - delegate?.routineCreationInputView(self, didChangeText: text) - } + func textFieldShouldReturn(_ textField: UITextField) -> Bool { + textField.resignFirstResponder() return true } } diff --git a/Projects/Presentation/Sources/RoutineCreation/View/RoutineCreationView.swift b/Projects/Presentation/Sources/RoutineCreation/View/RoutineCreationView.swift index 7a1019ce..5b5a3b88 100644 --- a/Projects/Presentation/Sources/RoutineCreation/View/RoutineCreationView.swift +++ b/Projects/Presentation/Sources/RoutineCreation/View/RoutineCreationView.swift @@ -621,6 +621,8 @@ final class RoutineCreationView: BaseViewController { repeatInfoButton.isSelected = false repeatToolTipView.hideTooltip() } + + view.endEditing(true) } } diff --git a/Projects/Presentation/Sources/RoutineCreation/ViewModel/RoutineCreationViewModel.swift b/Projects/Presentation/Sources/RoutineCreation/ViewModel/RoutineCreationViewModel.swift index 39d9ef19..977c5af4 100644 --- a/Projects/Presentation/Sources/RoutineCreation/ViewModel/RoutineCreationViewModel.swift +++ b/Projects/Presentation/Sources/RoutineCreation/ViewModel/RoutineCreationViewModel.swift @@ -272,12 +272,7 @@ final class RoutineCreationViewModel: ViewModel { guard let name = nameSubject.value, !name.isEmpty, - executionTimeSubject.value != .none, - weekDaySubject.value.count > 0, - subRoutinesSubject - .value - .map({$0.subRoutineName}) - .allSatisfy({$0?.isEmpty == false }) + executionTimeSubject.value != .none else { checkRoutinePublisher.send(false) return diff --git a/SupportingFiles/Info.plist b/SupportingFiles/Info.plist index 9a0ba43f..17b219aa 100644 --- a/SupportingFiles/Info.plist +++ b/SupportingFiles/Info.plist @@ -62,5 +62,7 @@ UILaunchStoryboardName LaunchScreen + UIRequiresFullScreen +