Skip to content

Commit 8340844

Browse files
committed
[BOOK-421] fix: Emotion Edit 로직 수정
1 parent 32c13b3 commit 8340844

File tree

3 files changed

+42
-24
lines changed

3 files changed

+42
-24
lines changed

src/Projects/BKDomain/Sources/Entity/Emotion.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright © 2025 Booket. All rights reserved
22

3-
public enum Emotion: String, CaseIterable, Decodable {
3+
public enum Emotion: String, CaseIterable, Decodable, Equatable {
44
case warmth = "따뜻함"
55
case joy = "즐거움"
66
case sad = "슬픔"

src/Projects/BKPresentation/Sources/MainFlow/NoteEdit/View/EmotionEditView.swift

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@ import Combine
66
import UIKit
77
import SnapKit
88

9+
enum EmotionEditViewEvent {
10+
case editButtonTapped
11+
case emotionDidChange(Emotion?)
12+
}
13+
914
final class EmotionEditView: BaseView {
1015
private let scrollView = UIScrollView()
1116
private let contentView = UIView()
1217
private let emotionRegistrationView = EmotionRegistrationView()
1318
private let editButton = BKButton(style: .primary, size: .large)
1419

15-
private let editButtonTappedSubject = PassthroughSubject<Void, Never>()
16-
var editButtonTappedPublisher: AnyPublisher<Void, Never> {
17-
editButtonTappedSubject.eraseToAnyPublisher()
18-
}
19-
20-
private let getCurrentEmotionSubject = PassthroughSubject<Void, Never>()
21-
var getCurrentEmotionPublisher: AnyPublisher<Void, Never> {
22-
getCurrentEmotionSubject.eraseToAnyPublisher()
23-
}
20+
let eventPublisher = PassthroughSubject<EmotionEditViewEvent, Never>()
21+
private var cancellables = Set<AnyCancellable>()
2422

25-
var selectedEmotion: Emotion? {
23+
private var currentSelectedEmotion: Emotion? {
2624
guard let form = emotionRegistrationView.registrationForm(),
2725
case .emotion(let emotionForm) = form else { return nil }
2826
return emotionForm.emotion
@@ -37,6 +35,15 @@ final class EmotionEditView: BaseView {
3735
override func configure() {
3836
editButton.title = "수정하기"
3937
editButton.addTarget(self, action: #selector(editButtonTapped), for: .touchUpInside)
38+
39+
emotionRegistrationView.inputChangedPublisher
40+
.sink { [weak self] _ in
41+
guard let self = self else { return }
42+
43+
let newEmotion = self.currentSelectedEmotion
44+
self.eventPublisher.send(.emotionDidChange(newEmotion))
45+
}
46+
.store(in: &cancellables)
4047
}
4148

4249
override func setupLayout() {
@@ -69,12 +76,12 @@ final class EmotionEditView: BaseView {
6976
emotionRegistrationView.setSelectedEmotion(emotion)
7077
}
7178

72-
func getCurrentSelectedEmotion() {
73-
getCurrentEmotionSubject.send(())
79+
@objc private func editButtonTapped() {
80+
eventPublisher.send(.editButtonTapped)
7481
}
7582

76-
@objc private func editButtonTapped() {
77-
editButtonTappedSubject.send(())
83+
func setEditButtonEnabled(_ isEnabled: Bool) {
84+
editButton.isDisabled = !isEnabled
7885
}
7986
}
8087

src/Projects/BKPresentation/Sources/MainFlow/NoteEdit/View/EmotionEditViewController.swift

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,41 @@ final class EmotionEditViewController: BaseViewController<EmotionEditView> {
1616
weak var coordinator: NoteEditCoordinator?
1717
private var cancellables = Set<AnyCancellable>()
1818

19-
private let currentEmotion: Emotion?
19+
private let initialEmotion: Emotion?
20+
@Published private var selectedEmotion: Emotion?
2021
private let completion: (Emotion) -> Void
2122

2223
init(currentEmotion: Emotion?, completion: @escaping (Emotion) -> Void) {
23-
self.currentEmotion = currentEmotion
24+
self.initialEmotion = currentEmotion
2425
self.completion = completion
26+
self._selectedEmotion = .init(initialValue: currentEmotion)
2527
super.init()
2628
}
2729

2830
override func viewWillAppear(_ animated: Bool) {
2931
super.viewWillAppear(animated)
3032

31-
// 현재 선택된 감정이 있으면 초기 설정
32-
if let emotion = currentEmotion {
33+
if let emotion = initialEmotion {
3334
contentView.setSelectedEmotion(emotion)
3435
}
36+
contentView.setEditButtonEnabled(false)
3537
}
3638

3739
override func bindAction() {
38-
contentView.editButtonTappedPublisher
39-
.compactMap { [weak self] in self?.contentView.selectedEmotion }
40-
.sink { [weak self] selectedEmotion in
41-
self?.completion(selectedEmotion)
42-
self?.navigationController?.popViewController(animated: true)
40+
contentView.eventPublisher
41+
.sink { [weak self] event in
42+
guard let self = self else { return }
43+
switch event {
44+
case .emotionDidChange(let newEmotion):
45+
self.selectedEmotion = newEmotion
46+
let isDiff = (newEmotion != self.initialEmotion)
47+
self.contentView.setEditButtonEnabled(isDiff)
48+
case .editButtonTapped:
49+
if let emotion = self.selectedEmotion {
50+
self.completion(emotion)
51+
self.navigationController?.popViewController(animated: true)
52+
}
53+
}
4354
}
4455
.store(in: &cancellables)
4556
}

0 commit comments

Comments
 (0)