From d9a94870eadcd76d78261f21309d324b506bf7b5 Mon Sep 17 00:00:00 2001 From: Dagyeong Choi Date: Mon, 2 Dec 2024 19:38:20 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B3=B5=EB=B0=B1=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC=20=EB=B0=8F=20=ED=99=94=EB=A9=B4=20?= =?UTF-8?q?=EC=9E=AC=20=EC=A7=84=EC=9E=85=20=EC=8B=9C=20=EB=8B=89=EB=84=A4?= =?UTF-8?q?=EC=9E=84=20=EB=A1=9C=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Profile/View/ProfileViewController.swift | 14 +++++++++++++- .../Profile/ViewModel/ProfileViewModel.swift | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Presentation/Presentation/Sources/Profile/View/ProfileViewController.swift b/Presentation/Presentation/Sources/Profile/View/ProfileViewController.swift index 455513d0..d6a95f20 100644 --- a/Presentation/Presentation/Sources/Profile/View/ProfileViewController.swift +++ b/Presentation/Presentation/Sources/Profile/View/ProfileViewController.swift @@ -196,7 +196,11 @@ final class ProfileViewController: UIViewController { private func updateProfileState(nickname: String) { nicknameCountLabel.text = "\(nickname.count)/\(nicknameMaxCount)" nicknameTextField.text = nickname - if !nickname.isEmpty { + let trimmedNickname = nickname.trimmingCharacters(in: .whitespacesAndNewlines) + + if !nickname.isEmpty, + !trimmedNickname.isEmpty + { completeButton.isEnabled = true completeButton.tintColor = .airplainBlue } else { @@ -216,10 +220,18 @@ final class ProfileViewController: UIViewController { } @objc private func dismissView() { + viewModel.action(input: .resetProfile) dismiss(animated: true) } @objc private func saveProfile() { + guard + let completedNickname = nicknameTextField + .text? + .trimmingCharacters(in: .whitespacesAndNewlines) + else { return } + + viewModel.action(input: .updateProfileNickname(nickname: completedNickname)) viewModel.action(input: .saveProfile) dismiss(animated: true) } diff --git a/Presentation/Presentation/Sources/Profile/ViewModel/ProfileViewModel.swift b/Presentation/Presentation/Sources/Profile/ViewModel/ProfileViewModel.swift index 39bed640..21e0ea66 100644 --- a/Presentation/Presentation/Sources/Profile/ViewModel/ProfileViewModel.swift +++ b/Presentation/Presentation/Sources/Profile/ViewModel/ProfileViewModel.swift @@ -14,6 +14,7 @@ public final class ProfileViewModel: ViewModel { case updateProfileNickname(nickname: String) case updateProfileIcon(profileIcon: ProfileIcon) case saveProfile + case resetProfile } struct Output { @@ -33,9 +34,14 @@ public final class ProfileViewModel: ViewModel { func action(input: Input) { switch input { - case .updateProfileNickname(let nickname): updateProfileNickname(nickname: nickname) - case .updateProfileIcon(let profileIcon): updateProfileIcon(profileIcon: profileIcon) - case .saveProfile: saveProfile() + case .updateProfileNickname(let nickname): + updateProfileNickname(nickname: nickname) + case .updateProfileIcon(let profileIcon): + updateProfileIcon(profileIcon: profileIcon) + case .saveProfile: + saveProfile() + case .resetProfile: + resetProfile() } } @@ -52,4 +58,8 @@ public final class ProfileViewModel: ViewModel { private func saveProfile() { profileUseCase.saveProfile(profile: profileSubject.value) } + + private func resetProfile() { + profileSubject.value = profileUseCase.loadProfile() + } }