Skip to content

Commit 74bfa16

Browse files
authored
Fix: 루틴 삭제하기 기능 QA 이슈 수정 (#T3-207)
* Fix: ToastView message 변경 가능하도록 확장 (#T3-207) * Feat: 삭제 성공 후 토스트 메시지 띄우기 (#T3-207) * Fix: 삭제된 루틴에 대하여 수정 버튼 없애기 (#T3-207) * Fix: 이미 삭제된 루틴에 대하여 당일 삭제만 가능하도록 수정 (#T3-207)
1 parent e1d6541 commit 74bfa16

File tree

7 files changed

+51
-8
lines changed

7 files changed

+51
-8
lines changed

Projects/Presentation/Sources/Common/Component/RoutineCardView.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,15 @@ final class RoutineCardView: UIView {
235235
}
236236

237237
if let _ = routine as? Routine {
238-
addSubview(editButton)
239238
addSubview(deleteButton)
240239

241-
editButton.snp.makeConstraints { make in
242-
make.top.equalToSuperview().offset(Layout.plusButtonTopSpacing)
243-
make.trailing.equalTo(deleteButton).offset(-Layout.editButtonTrailingSpacing)
244-
make.size.equalTo(Layout.plusButtonSize)
240+
if !routine.isDeleted {
241+
addSubview(editButton)
242+
editButton.snp.makeConstraints { make in
243+
make.top.equalToSuperview().offset(Layout.plusButtonTopSpacing)
244+
make.trailing.equalTo(deleteButton).offset(-Layout.editButtonTrailingSpacing)
245+
make.size.equalTo(Layout.plusButtonSize)
246+
}
245247
}
246248

247249
deleteButton.snp.makeConstraints { make in

Projects/Presentation/Sources/Common/Component/ToastView.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class ToastView: UIView {
1717

1818
private let checkIcon = UIImageView()
1919
private let messageLabel = UILabel()
20-
private let message: String
20+
private var message: String
2121

2222
init(message: String) {
2323
self.message = message
@@ -62,7 +62,12 @@ final class ToastView: UIView {
6262
}
6363
}
6464

65-
func showToastMessageView() {
65+
func showToastMessageView(message: String? = nil) {
66+
if let message {
67+
self.message = message
68+
self.messageLabel.text = message
69+
}
70+
6671
alpha = 0
6772
isHidden = false
6873

Projects/Presentation/Sources/Common/Extension/Notification+.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ import Foundation
99

1010
extension Notification.Name {
1111
static let showRecommendedRoutineToast = Notification.Name("showRecommendedRoutineToast")
12+
static let showDeletedRoutineToast = Notification.Name("showDeletedRoutineToast")
1213
}

Projects/Presentation/Sources/Common/Protocol/RoutineProtocol.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ protocol RoutineProtocol {
1111
var title: String { get }
1212
var routineType: RoutineCategoryType? { get }
1313
var subRoutines: [String] { get }
14+
var isDeleted: Bool { get }
1415
}

Projects/Presentation/Sources/Onboarding/Model/RecommendedRoutine.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public struct RecommendedRoutine: BitnagilChoiceProtocol, RoutineProtocol, Hasha
1515
let routineCategory: RoutineCategoryType
1616
let routineType: RoutineCategoryType?
1717
let routineLevel: RoutineLevelType
18+
let isDeleted: Bool
1819

1920
init(
2021
id: Int,
@@ -32,6 +33,7 @@ public struct RecommendedRoutine: BitnagilChoiceProtocol, RoutineProtocol, Hasha
3233
self.routineCategory = routineCategory
3334
self.routineType = routineType
3435
self.routineLevel = routineLevel
36+
self.isDeleted = false
3537
}
3638
}
3739

Projects/Presentation/Sources/RoutineList/View/RoutineListViewController.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ final class RoutineListViewController: BaseViewController<RoutineListViewModel>
2020
static let routineScrollViewTopSpacing: CGFloat = 16
2121
static let routineStackViewSpacing: CGFloat = 12
2222
static let routineStackViewBottomSpacing: CGFloat = 60
23+
static let toastMessageViewHeight: CGFloat = 52
24+
static let toastMessageViewBottomSpacing: CGFloat = 20
2325
}
2426

2527
private let weekView: WeekView
2628
private let emptyView = HomeEmptyView()
2729
private let routineScrollView = UIScrollView()
2830
private let routineStackView = UIStackView()
2931
private var routineCardViews: [String: RoutineCardView] = [:]
32+
private let deleteToastMessage: String = "삭제가 완료되었습니다."
33+
private var toastMessageView = ToastView(message: "")
3034
private var dimmedView: UIView?
3135
private var cancellables: Set<AnyCancellable>
3236

@@ -79,6 +83,7 @@ final class RoutineListViewController: BaseViewController<RoutineListViewModel>
7983
view.addSubview(emptyView)
8084
view.addSubview(routineScrollView)
8185
routineScrollView.addSubview(routineStackView)
86+
view.addSubview(toastMessageView)
8287

8388
weekView.snp.makeConstraints { make in
8489
make.top.equalTo(safeArea).offset(Layout.weekViewTopSpacing)
@@ -104,6 +109,13 @@ final class RoutineListViewController: BaseViewController<RoutineListViewModel>
104109
make.bottom.equalToSuperview().inset(Layout.routineStackViewBottomSpacing)
105110
make.width.equalTo(routineScrollView.snp.width)
106111
}
112+
113+
toastMessageView.snp.makeConstraints { make in
114+
make.leading.equalTo(safeArea).offset(Layout.horizontalMargin)
115+
make.trailing.equalTo(safeArea).inset(Layout.horizontalMargin)
116+
make.height.equalTo(Layout.toastMessageViewHeight)
117+
make.bottom.equalTo(safeArea).inset(Layout.toastMessageViewBottomSpacing)
118+
}
107119
}
108120

109121
override func bind() {
@@ -129,6 +141,14 @@ final class RoutineListViewController: BaseViewController<RoutineListViewModel>
129141
self?.updateRoutineStackView(routines: routines)
130142
}
131143
.store(in: &cancellables)
144+
145+
NotificationCenter.default.publisher(for: .showDeletedRoutineToast)
146+
.receive(on: DispatchQueue.main)
147+
.sink { [weak self] _ in
148+
guard let self else { return }
149+
self.toastMessageView.showToastMessageView(message: deleteToastMessage)
150+
}
151+
.store(in: &cancellables)
132152
}
133153

134154
private func updateRoutineStackView(routines: [Routine]) {
@@ -222,7 +242,7 @@ extension RoutineListViewController: RoutineCardViewDelegate {
222242
view.addSubview(newDimmedView)
223243
dimmedView = newDimmedView
224244

225-
if routine.repeatDay.isEmpty {
245+
if routine.repeatDay.isEmpty || routine.isDeleted {
226246
let routineDeleteAlertViewController = RoutineDeleteAlertViewController(viewModel: viewModel, isDeleteAllRoutines: false)
227247
if let sheet = routineDeleteAlertViewController.sheetPresentationController {
228248
sheet.prefersGrabberVisible = false

Projects/Presentation/Sources/RoutineList/ViewModel/RoutineListViewModel.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ final class RoutineListViewModel: ViewModel {
7373
let endDateString = endDate.convertToString(dateType: .yearMonthDate)
7474

7575
let routinesDictionary = try await routineRepository.fetchRoutines(from: startDateString, to: endDateString)
76+
77+
self.routines.removeAll()
7678
for dailyRoutine in routinesDictionary {
7779
let date = dailyRoutine.key
7880
let routine = dailyRoutine.value.routines.map({ $0.toRoutine() })
@@ -118,9 +120,19 @@ final class RoutineListViewModel: ViewModel {
118120
}
119121
deleteRoutineResultSubject.send(true)
120122
fetchRoutines()
123+
showDeletedRoutineToastMessageView()
121124
} catch {
122125
deleteRoutineResultSubject.send(false)
123126
}
124127
}
125128
}
129+
130+
private func showDeletedRoutineToastMessageView() {
131+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) {
132+
NotificationCenter.default.post(
133+
name: .showDeletedRoutineToast,
134+
object: nil,
135+
userInfo: nil)
136+
}
137+
}
126138
}

0 commit comments

Comments
 (0)