Skip to content

Commit

Permalink
[refactor] SettingFeature 액션 수정
Browse files Browse the repository at this point in the history
- 닉네임 설정 feature 수정
- 설정창 관련 feature 수정
  • Loading branch information
stealmh committed Sep 29, 2024
1 parent 4500c7d commit 9eb6ba2
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,24 @@ public struct NickNameSettingFeature {
public enum View: BindableAction, Equatable {
case binding(BindingAction<State>)
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
Expand Down Expand Up @@ -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<Action> {
switch action {
case .textChanged:
case .닉네임_텍스트_변경되었을때:
/// [1]. 닉네임 텍스트필드가 비어있을 때
if state.text.isEmpty {
state.buttonState = .disable
Expand All @@ -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
Expand All @@ -176,15 +179,16 @@ private extension NickNameSettingFeature {
/// - Async Effect
func handleAsyncAction(_ action: Action.AsyncAction, state: inout State) -> Effect<Action> {
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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public extension NickNameSettingView {
PokitBottomButton(
"저장",
state: store.buttonState,
action: { send(.saveButtonTapped) }
action: { send(.저장_버튼_눌렀을때) }
)
.setKeyboardHeight()
}
.padding(.horizontal, 20)
.padding(.top, 16)
.pokitNavigationBar { navigationBar }
.ignoresSafeArea(edges: .bottom)
.task { await send(.onAppear).finish() }
.task { await send(.뷰가_나타났을때).finish() }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ public struct PokitSettingFeature {
@CasePathable
public enum View: BindableAction, Equatable {
case binding(BindingAction<State>)
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 {
Expand All @@ -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?)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -202,7 +200,7 @@ private extension PokitSettingFeature {
/// - Async Effect
func handleAsyncAction(_ action: Action.AsyncAction, state: inout State) -> Effect<Action> {
switch action {
case .회원탈퇴_네트워크:
case .회원탈퇴_API:
return .run { send in
guard keychain.read(.refreshToken) != nil else {
print("refresh가 없어서 벗어남")
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public extension PokitSettingView {
PokitAlert(
"로그아웃 하시겠습니까?",
confirmText: "로그아웃",
action: { send(.로그아웃수행) }
action: { send(.로그아웃_팝업_확인_눌렀을때) }
)
}
.sheet(isPresented: $store.isWithdrawPresented) {
PokitAlert(
"회원 탈퇴하시겠습니까?",
message: "함께 저장한 모든 정보가 삭제되며,\n복구하실 수 없습니다.",
confirmText: "탈퇴하기",
action: { send(.회원탈퇴수행) }
action: { send(.회원탈퇴_팝업_확인_눌렀을때) }
)
}
.fullScreenCover(isPresented: $store.isWebViewPresented) {
Expand All @@ -60,7 +60,7 @@ public extension PokitSettingView {
) { store in
NickNameSettingView(store: store)
}
.onAppear { send(.onAppear) }
.onAppear { send(.뷰가_나타났을때) }
}
}
}
Expand Down Expand Up @@ -114,12 +114,12 @@ private extension PokitSettingView {
Section {
SettingItem(
title: "로그아웃",
action: { send(.로그아웃) }
action: { send(.로그아웃_버튼_눌렀을때) }
)

SettingItem(
title: "회원 탈퇴",
action: { send(.회원탈퇴) }
action: { send(.회원탈퇴_버튼_눌렀을때) }
)
}
}
Expand Down

0 comments on commit 9eb6ba2

Please sign in to comment.