Skip to content

Commit 307b8c9

Browse files
authored
fix: 홈 화면에서의 루틴 등록 및 완료 관련 버그 수정
* Fix: 루틴 등록 완료 후 홈 화면으로 돌아가도록 수정 * feat: 홈 화면 pull to refresh 기능 추가하여 루틴 리스트 업데이트 * fix: 루틴 완료 표시 관련 버그 수정
1 parent 0973070 commit 307b8c9

5 files changed

Lines changed: 45 additions & 17 deletions

File tree

Projects/Presentation/Sources/Home/View/Component/DateView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ final class DateView: UIView {
124124
self.isSelected = isSelected
125125
}
126126

127-
func updateAllCompleted() {
128-
allCompletedIcon.isHidden.toggle()
127+
func updateAllCompleted(isCompleted: Bool) {
128+
allCompletedIcon.isHidden = !isCompleted
129129
}
130130
}

Projects/Presentation/Sources/Home/View/Component/WeekView.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ final class WeekView: UIView {
9191

9292
let isAllCompleted = allCompletedDates.contains(date)
9393
if isAllCompleted {
94-
dateView.updateAllCompleted()
94+
dateView.updateAllCompleted(isCompleted: true)
9595
}
9696
dateView.didTapDateButton = { [weak self] date in
9797
self?.selectDate(date: date)
@@ -109,7 +109,9 @@ final class WeekView: UIView {
109109
self.allCompletedDates = allCompletedDates
110110
for dateView in dateViews {
111111
if allCompletedDates.contains(dateView.key) {
112-
dateView.value.updateAllCompleted()
112+
dateView.value.updateAllCompleted(isCompleted: true)
113+
} else {
114+
dateView.value.updateAllCompleted(isCompleted: false)
113115
}
114116
}
115117
}

Projects/Presentation/Sources/Home/View/HomeViewController.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ final class HomeViewController: BaseViewController<HomeViewModel> {
7474

7575
// routineView
7676
private let emptyView = HomeEmptyView()
77+
private let refreshControl = UIRefreshControl()
7778
private let routineHeaderView = UIView()
7879
private let routineListLabel = UILabel()
7980
private let routineListButton = UIButton()
@@ -181,6 +182,12 @@ final class HomeViewController: BaseViewController<HomeViewModel> {
181182
self.navigationController?.pushViewController(routineCreationView, animated: true)
182183
}
183184

185+
routineScrollView.refreshControl = refreshControl
186+
refreshControl.addTarget(
187+
self,
188+
action: #selector(pullToRoutineRefresh),
189+
for: .valueChanged)
190+
184191
routineListLabel.text = "루틴 리스트"
185192
routineListLabel.font = BitnagilFont(style: .body2, weight: .semiBold).font
186193
routineListLabel.textColor = BitnagilColor.gray60
@@ -433,6 +440,7 @@ final class HomeViewController: BaseViewController<HomeViewModel> {
433440
.receive(on: DispatchQueue.main)
434441
.sink { [weak self] routines in
435442
self?.updateRoutineView(routines: routines)
443+
self?.routineScrollView.refreshControl?.endRefreshing()
436444
self?.hideIndicatorView()
437445
}
438446
.store(in: &cancellables)
@@ -635,6 +643,10 @@ final class HomeViewController: BaseViewController<HomeViewModel> {
635643
emotionRegistrationViewController.hidesBottomBarWhenPushed = true
636644
navigationController?.pushViewController(emotionRegistrationViewController, animated: true)
637645
}
646+
647+
@objc private func pullToRoutineRefresh() {
648+
viewModel.action(input: .refreshDailyRoutine)
649+
}
638650
}
639651

640652
// MARK: WeekViewDelegate

Projects/Presentation/Sources/RoutineCreation/View/RoutineCreationViewController.swift

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,6 @@ final class RoutineCreationViewController: BaseViewController<RoutineCreationVie
146146
UIAction { [weak self] _ in
147147
guard let self else { return }
148148
self.viewModel.action(input: .registerRoutine)
149-
if self.isFromMypage {
150-
if
151-
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
152-
let window = windowScene.windows.first(where: { $0.isKeyWindow }),
153-
let tabBarView = window.rootViewController as? TabBarView {
154-
self.navigationController?.popToRootViewController(animated: false)
155-
tabBarView.selectedIndex = 1
156-
viewModel.action(input: .showRecommendedRoutineToastMessageView)
157-
}
158-
} else {
159-
viewModel.action(input: .showUpdateRoutineToastMessageView)
160-
self.navigationController?.popViewController(animated: true)
161-
}
162149
},
163150
for: .touchUpInside)
164151
bindCreationCardViews()
@@ -314,6 +301,28 @@ final class RoutineCreationViewController: BaseViewController<RoutineCreationVie
314301
}
315302
}
316303
.store(in: &cancellables)
304+
305+
viewModel.output.routineCreationResultPublisher
306+
.receive(on: DispatchQueue.main)
307+
.sink { [weak self] creationResult in
308+
guard let self else { return }
309+
if creationResult {
310+
if self.isFromMypage {
311+
if
312+
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
313+
let window = windowScene.windows.first(where: { $0.isKeyWindow }),
314+
let tabBarView = window.rootViewController as? TabBarView {
315+
self.navigationController?.popToRootViewController(animated: false)
316+
tabBarView.selectedIndex = 1
317+
viewModel.action(input: .showRecommendedRoutineToastMessageView)
318+
}
319+
} else {
320+
viewModel.action(input: .showUpdateRoutineToastMessageView)
321+
self.navigationController?.popViewController(animated: true)
322+
}
323+
}
324+
}
325+
.store(in: &cancellables)
317326
}
318327

319328
private func bindCreationCardViews() {

Projects/Presentation/Sources/RoutineCreation/ViewModel/RoutineCreationViewModel.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ final class RoutineCreationViewModel: ViewModel {
4444
let periodPublisher: AnyPublisher<(Date?, Date?), Never>
4545
let executionTimePublisher: AnyPublisher<Date?, Never>
4646
let isRoutineValid: AnyPublisher<Bool, Never>
47+
let routineCreationResultPublisher: AnyPublisher<Bool, Never>
4748
let networkErrorPublisher: AnyPublisher<(() -> Void)?, Never>
4849
}
4950

@@ -55,6 +56,7 @@ final class RoutineCreationViewModel: ViewModel {
5556
private let periodEndSubject = CurrentValueSubject<Date?, Never>(nil)
5657
private let executionTimeSubject = CurrentValueSubject<ExecutionTime, Never>(.init(startAt: nil))
5758
private let checkRoutinePublisher = CurrentValueSubject<Bool, Never>(false)
59+
private let routineCreationResultSubject = PassthroughSubject<Bool, Never>()
5860
private let routineUseCase: RoutineUseCaseProtocol
5961
private let networkRetryHandler: NetworkRetryHandler
6062
private let recommenededRoutineUseCase: RecommendedRoutineUseCaseProtocol
@@ -82,6 +84,7 @@ final class RoutineCreationViewModel: ViewModel {
8284
.map { $0.startAt }
8385
.eraseToAnyPublisher(),
8486
isRoutineValid: checkRoutinePublisher.eraseToAnyPublisher(),
87+
routineCreationResultPublisher: routineCreationResultSubject.eraseToAnyPublisher(),
8588
networkErrorPublisher: networkRetryHandler.networkErrorActionSubject.eraseToAnyPublisher())
8689

8790
updateIsRoutineValid()
@@ -302,8 +305,10 @@ final class RoutineCreationViewModel: ViewModel {
302305

303306
try await routineUseCase.saveRoutine(routine: routine)
304307

308+
routineCreationResultSubject.send(true)
305309
networkRetryHandler.clearRetryState()
306310
} catch {
311+
routineCreationResultSubject.send(false)
307312
networkRetryHandler.handleNetworkError(error) { [weak self] in
308313
self?.registerRoutine()
309314
}

0 commit comments

Comments
 (0)