From 9eb6ba23ef8457f849aee89f619e7a05ba3833b3 Mon Sep 17 00:00:00 2001 From: minhokim Date: Sun, 29 Sep 2024 18:11:11 +0900 Subject: [PATCH] =?UTF-8?q?[refactor]=20SettingFeature=20=EC=95=A1?= =?UTF-8?q?=EC=85=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 닉네임 설정 feature 수정 - 설정창 관련 feature 수정 --- .../NickNameSettingFeature.swift | 62 ++++++++++--------- .../NickNameSetting/NickNameSettingView.swift | 4 +- .../Sources/Setting/PokitSettingFeature.swift | 51 +++++++-------- .../Sources/Setting/PokitSettingView.swift | 10 +-- 4 files changed, 63 insertions(+), 64 deletions(-) diff --git a/Projects/Feature/FeatureSetting/Sources/Setting/NickNameSetting/NickNameSettingFeature.swift b/Projects/Feature/FeatureSetting/Sources/Setting/NickNameSetting/NickNameSettingFeature.swift index f08f9808..f6887a1c 100644 --- a/Projects/Feature/FeatureSetting/Sources/Setting/NickNameSetting/NickNameSettingFeature.swift +++ b/Projects/Feature/FeatureSetting/Sources/Setting/NickNameSetting/NickNameSettingFeature.swift @@ -46,25 +46,24 @@ public struct NickNameSettingFeature { public enum View: BindableAction, Equatable { case binding(BindingAction) case dismiss - case saveButtonTapped - - case onAppear + case 저장_버튼_눌렀을때 + case 뷰가_나타났을때 } public enum InnerAction: Equatable { - case textChanged - case 닉네임_중복_체크_네트워크_결과(Bool) - case 유저정보_갱신(BaseUser) + case 닉네임_텍스트_변경되었을때 + case 닉네임_중복_확인_API_반영(Bool) + case 닉네임_조회_API_반영(BaseUser) } public enum AsyncAction: Equatable { - case 닉네임_중복_체크_네트워크 - case 닉네임_조회 + case 닉네임_중복_확인_API + case 닉네임_조회_API } - public enum ScopeAction: Equatable { case doNothing } + public enum ScopeAction: Equatable { case 없음 } - public enum DelegateAction: Equatable { case doNothing } + public enum DelegateAction: Equatable { case 없음 } } /// - Initiallizer @@ -109,34 +108,36 @@ private extension NickNameSettingFeature { case .binding(\.text): state.buttonState = .disable return .run { send in - await send(.inner(.textChanged)) + await send(.inner(.닉네임_텍스트_변경되었을때)) } .debounce( id: CancelID.response, for: 0.5, scheduler: mainQueue ) + case .binding: return .none case .dismiss: return .run { _ in await dismiss() } - case .saveButtonTapped: + case .저장_버튼_눌렀을때: return .run { [nickName = state.text] send in let request = NicknameEditRequest(nickname: nickName) let _ = try await userClient.닉네임_수정(request) await dismiss() } - case .onAppear: - return .send(.async(.닉네임_조회)) + + case .뷰가_나타났을때: + return .send(.async(.닉네임_조회_API)) } } /// - Inner Effect func handleInnerAction(_ action: Action.InnerAction, state: inout State) -> Effect { switch action { - case .textChanged: + case .닉네임_텍스트_변경되었을때: /// [1]. 닉네임 텍스트필드가 비어있을 때 if state.text.isEmpty { state.buttonState = .disable @@ -155,18 +156,20 @@ private extension NickNameSettingFeature { return .none } else { /// [4]. 정상 케이스일 때 - return .run { send in await send(.async(.닉네임_중복_체크_네트워크)) } - } - case let .닉네임_중복_체크_네트워크_결과(isDuplicate): - if isDuplicate { - state.textfieldState = .error(message: "중복된 닉네임입니다.") - state.buttonState = .disable - } else { - state.textfieldState = .active - state.buttonState = .filled(.primary) + return .run { send in await send(.async(.닉네임_중복_확인_API)) } } + + case let .닉네임_중복_확인_API_반영(isDuplicate): + state.textfieldState = isDuplicate + ? .error(message: "중복된 닉네임입니다.") + : .active + + state.buttonState = isDuplicate + ? .disable + : .filled(.primary) return .none - case let .유저정보_갱신(user): + + case let .닉네임_조회_API_반영(user): state.domain.user = user state.domain.nickname = user.nickname return .none @@ -176,15 +179,16 @@ private extension NickNameSettingFeature { /// - Async Effect func handleAsyncAction(_ action: Action.AsyncAction, state: inout State) -> Effect { switch action { - case .닉네임_중복_체크_네트워크: + case .닉네임_중복_확인_API: return .run { [nickName = state.text] send in let result = try await userClient.닉네임_중복_체크(nickName) - await send(.inner(.닉네임_중복_체크_네트워크_결과(result.isDuplicate))) + await send(.inner(.닉네임_중복_확인_API_반영(result.isDuplicate))) } - case .닉네임_조회: + + case .닉네임_조회_API: return .run { send in let user = try await userClient.닉네임_조회().toDomain() - await send(.inner(.유저정보_갱신(user)), animation: .easeInOut) + await send(.inner(.닉네임_조회_API_반영(user)), animation: .easeInOut) } } } diff --git a/Projects/Feature/FeatureSetting/Sources/Setting/NickNameSetting/NickNameSettingView.swift b/Projects/Feature/FeatureSetting/Sources/Setting/NickNameSetting/NickNameSettingView.swift index 69e92718..f22a4af0 100644 --- a/Projects/Feature/FeatureSetting/Sources/Setting/NickNameSetting/NickNameSettingView.swift +++ b/Projects/Feature/FeatureSetting/Sources/Setting/NickNameSetting/NickNameSettingView.swift @@ -44,7 +44,7 @@ public extension NickNameSettingView { PokitBottomButton( "저장", state: store.buttonState, - action: { send(.saveButtonTapped) } + action: { send(.저장_버튼_눌렀을때) } ) .setKeyboardHeight() } @@ -52,7 +52,7 @@ public extension NickNameSettingView { .padding(.top, 16) .pokitNavigationBar { navigationBar } .ignoresSafeArea(edges: .bottom) - .task { await send(.onAppear).finish() } + .task { await send(.뷰가_나타났을때).finish() } } } } diff --git a/Projects/Feature/FeatureSetting/Sources/Setting/PokitSettingFeature.swift b/Projects/Feature/FeatureSetting/Sources/Setting/PokitSettingFeature.swift index 698db99e..15c4c580 100644 --- a/Projects/Feature/FeatureSetting/Sources/Setting/PokitSettingFeature.swift +++ b/Projects/Feature/FeatureSetting/Sources/Setting/PokitSettingFeature.swift @@ -43,18 +43,18 @@ public struct PokitSettingFeature { @CasePathable public enum View: BindableAction, Equatable { case binding(BindingAction) + case dismiss case 닉네임설정 case 알림설정 case 공지사항 case 서비스_이용약관 case 개인정보_처리방침 case 고객문의 - case 로그아웃 - case 로그아웃수행 - case 회원탈퇴 - case 회원탈퇴수행 - case dismiss - case onAppear + case 로그아웃_버튼_눌렀을때 + case 로그아웃_팝업_확인_눌렀을때 + case 회원탈퇴_버튼_눌렀을때 + case 회원탈퇴_팝업_확인_눌렀을때 + case 뷰가_나타났을때 } public enum InnerAction: Equatable { @@ -63,13 +63,11 @@ public struct PokitSettingFeature { } public enum AsyncAction: Equatable { - case 회원탈퇴_네트워크 - case 키_제거 + case 회원탈퇴_API + case 키_제거_수행 } - public enum ScopeAction: Equatable { - case doNothing - } + public enum ScopeAction: Equatable { case 없음 } public enum DelegateAction: Equatable { case linkCopyDetected(URL?) @@ -126,6 +124,9 @@ private extension PokitSettingFeature { case .binding: return .none + case .dismiss: + return .run { _ in await dismiss() } + case .닉네임설정: state.nickNameSettingState = NickNameSettingFeature.State() return .none @@ -153,30 +154,27 @@ private extension PokitSettingFeature { state.isWebViewPresented = true return .none - case .로그아웃: + case .로그아웃_버튼_눌렀을때: return .send(.inner(.로그아웃_팝업(isPresented: true))) - case .로그아웃수행: + case .로그아웃_팝업_확인_눌렀을때: return .run { send in - await send(.async(.키_제거)) + await send(.async(.키_제거_수행)) await send(.inner(.로그아웃_팝업(isPresented: false))) await send(.delegate(.로그아웃)) } - case .회원탈퇴: + case .회원탈퇴_버튼_눌렀을때: return .send(.inner(.회원탈퇴_팝업(isPresented: true))) - case .회원탈퇴수행: + case .회원탈퇴_팝업_확인_눌렀을때: return .run { send in - await send(.async(.회원탈퇴_네트워크)) + await send(.async(.회원탈퇴_API)) await send(.inner(.회원탈퇴_팝업(isPresented: false))) await send(.delegate(.회원탈퇴)) } - case .dismiss: - return .run { _ in await dismiss() } - - case .onAppear: + case .뷰가_나타났을때: return .run { send in for await _ in self.pasteboard.changes() { let url = try await pasteboard.probableWebURL() @@ -202,7 +200,7 @@ private extension PokitSettingFeature { /// - Async Effect func handleAsyncAction(_ action: Action.AsyncAction, state: inout State) -> Effect { switch action { - case .회원탈퇴_네트워크: + case .회원탈퇴_API: return .run { send in guard keychain.read(.refreshToken) != nil else { print("refresh가 없어서 벗어남") @@ -235,17 +233,14 @@ private extension PokitSettingFeature { ) } - await send(.async(.키_제거)) + await send(.async(.키_제거_수행)) - let request = WithdrawRequest( - authPlatform: platform - ) + let request = WithdrawRequest(authPlatform: platform) - // - TODO: 서버 디비 삭제 요청으로 바꿔야함 try await authClient.회원탈퇴(request) } - case .키_제거: + case .키_제거_수행: keychain.delete(.accessToken) keychain.delete(.refreshToken) keychain.delete(.serverRefresh) diff --git a/Projects/Feature/FeatureSetting/Sources/Setting/PokitSettingView.swift b/Projects/Feature/FeatureSetting/Sources/Setting/PokitSettingView.swift index 87dde923..b092f054 100644 --- a/Projects/Feature/FeatureSetting/Sources/Setting/PokitSettingView.swift +++ b/Projects/Feature/FeatureSetting/Sources/Setting/PokitSettingView.swift @@ -37,7 +37,7 @@ public extension PokitSettingView { PokitAlert( "로그아웃 하시겠습니까?", confirmText: "로그아웃", - action: { send(.로그아웃수행) } + action: { send(.로그아웃_팝업_확인_눌렀을때) } ) } .sheet(isPresented: $store.isWithdrawPresented) { @@ -45,7 +45,7 @@ public extension PokitSettingView { "회원 탈퇴하시겠습니까?", message: "함께 저장한 모든 정보가 삭제되며,\n복구하실 수 없습니다.", confirmText: "탈퇴하기", - action: { send(.회원탈퇴수행) } + action: { send(.회원탈퇴_팝업_확인_눌렀을때) } ) } .fullScreenCover(isPresented: $store.isWebViewPresented) { @@ -60,7 +60,7 @@ public extension PokitSettingView { ) { store in NickNameSettingView(store: store) } - .onAppear { send(.onAppear) } + .onAppear { send(.뷰가_나타났을때) } } } } @@ -114,12 +114,12 @@ private extension PokitSettingView { Section { SettingItem( title: "로그아웃", - action: { send(.로그아웃) } + action: { send(.로그아웃_버튼_눌렀을때) } ) SettingItem( title: "회원 탈퇴", - action: { send(.회원탈퇴) } + action: { send(.회원탈퇴_버튼_눌렀을때) } ) } }