Skip to content

Commit

Permalink
Merge pull request #142 from YAPP-Github/refactor/#129-LoginFeature
Browse files Browse the repository at this point in the history
refactor: ๋กœ๊ทธ์ธ ํ”Œ๋กœ์šฐ Feature ์•ก์…˜ ์ปจ๋ฒค์…˜ ์ˆ˜์ •
  • Loading branch information
ShapeKim98 authored Oct 15, 2024
2 parents c0ab92f + 167cc1a commit 423efee
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ public struct AgreeToTermsFeature {
/// - Binding
case binding(BindingAction<State>)
/// - Button Tapped
case nextButtonTapped
case backButtonTapped
case ๊ฐœ์ธ์ •๋ณด_๋™์˜_๋ฒ„ํŠผ_ํด๋ฆญ
case ์„œ๋น„์Šค_์ด์šฉ์•ฝ๊ด€_๋ฒ„ํŠผ_ํด๋ฆญ
case ๋งˆ์ผ€ํŒ…_์ •๋ณด_์ˆ˜์‹ _๋ฒ„ํŠผ_ํด๋ฆญ
case ๋‹ค์Œ_๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ
case ๋’ค๋กœ๊ฐ€๊ธฐ_๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ
case ๊ฐœ์ธ์ •๋ณด_๋™์˜_๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ
case ์„œ๋น„์Šค_์ด์šฉ์•ฝ๊ด€_๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ
case ๋งˆ์ผ€ํŒ…_์ •๋ณด_์ˆ˜์‹ _๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ
}
public enum InnerAction: Equatable {
case checkAgreements
case personalAndUsageAgreeSelected
case serviceAgreeSelected
case marketingAgreeSelected
case allAgreementSelected
case ๋™์˜_์ฒดํฌ_ํ™•์ธ
case ๊ฐœ์ธ์ •๋ณด_๋™์˜_์„ ํƒํ–ˆ์„๋•Œ
case ์„œ๋น„์Šค_์ด์šฉ์•ฝ๊ด€_๋™์˜_์„ ํƒํ–ˆ์„๋•Œ
case ๋งˆ์ผ€ํŒ…_์ •๋ณด_์ˆ˜์‹ _๋™์˜_์„ ํƒํ–ˆ์„๋•Œ
case ์ „์ฒด_๋™์˜_์„ ํƒํ–ˆ์„๋•Œ
}
public enum AsyncAction: Equatable { case doNothing }
public enum ScopeAction: Equatable { case doNothing }
public enum AsyncAction: Equatable { case ์—†์Œ }
public enum ScopeAction: Equatable { case ์—†์Œ }
public enum DelegateAction: Equatable {
case pushRegisterNicknameView
}
Expand Down Expand Up @@ -91,29 +91,29 @@ private extension AgreeToTermsFeature {
/// - View Effect
func handleViewAction(_ action: Action.ViewAction, state: inout State) -> Effect<Action> {
switch action {
case .nextButtonTapped:
case .๋‹ค์Œ_๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ:
return .send(.delegate(.pushRegisterNicknameView))
case .backButtonTapped:
case .๋’ค๋กœ๊ฐ€๊ธฐ_๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ:
return .run { _ in await self.dismiss() }
case .binding(\.isAgreeAllTerms):
return .send(.inner(.allAgreementSelected))
return .send(.inner(.์ „์ฒด_๋™์˜_์„ ํƒํ–ˆ์„๋•Œ))
case .binding(\.isPersonalAndUsageArgee):
return .send(.inner(.personalAndUsageAgreeSelected))
return .send(.inner(.๊ฐœ์ธ์ •๋ณด_๋™์˜_์„ ํƒํ–ˆ์„๋•Œ))
case .binding(\.isServiceAgree):
return .send(.inner(.serviceAgreeSelected))
return .send(.inner(.์„œ๋น„์Šค_์ด์šฉ์•ฝ๊ด€_๋™์˜_์„ ํƒํ–ˆ์„๋•Œ))
case .binding(\.isMarketingAgree):
return .send(.inner(.marketingAgreeSelected))
return .send(.inner(.๋งˆ์ผ€ํŒ…_์ •๋ณด_์ˆ˜์‹ _๋™์˜_์„ ํƒํ–ˆ์„๋•Œ))
case .binding:
return .none
case .๊ฐœ์ธ์ •๋ณด_๋™์˜_๋ฒ„ํŠผ_ํด๋ฆญ:
case .๊ฐœ์ธ์ •๋ณด_๋™์˜_๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ:
state.webViewURL = Constants.๊ฐœ์ธ์ •๋ณด_์ฒ˜๋ฆฌ๋ฐฉ์นจ_์ฃผ์†Œ
state.isWebViewPresented = true
return .none
case .์„œ๋น„์Šค_์ด์šฉ์•ฝ๊ด€_๋ฒ„ํŠผ_ํด๋ฆญ:
case .์„œ๋น„์Šค_์ด์šฉ์•ฝ๊ด€_๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ:
state.webViewURL = Constants.์„œ๋น„์Šค_์ด์šฉ์•ฝ๊ด€_์ฃผ์†Œ
state.isWebViewPresented = true
return .none
case .๋งˆ์ผ€ํŒ…_์ •๋ณด_์ˆ˜์‹ _๋ฒ„ํŠผ_ํด๋ฆญ:
case .๋งˆ์ผ€ํŒ…_์ •๋ณด_์ˆ˜์‹ _๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ:
state.webViewURL = Constants.๋งˆ์ผ€ํŒ…_์ •๋ณด_์ˆ˜์‹ _์ฃผ์†Œ
state.isWebViewPresented = true
return .none
Expand All @@ -123,19 +123,19 @@ private extension AgreeToTermsFeature {
func handleInnerAction(_ action: Action.InnerAction, state: inout State) -> Effect<Action> {
switch action {
/// - ๊ฐœ๋ณ„ ๋™์˜ ์ฒดํฌ ๋ฐ•์Šค๋ฅผ ํ™•์ธ ํ•˜์—ฌ ์ „์ฒด ๋™์˜ ์ฒดํฌ ์—ฌ๋ถ€ ๊ฒฐ์ •
case .checkAgreements:
case .๋™์˜_์ฒดํฌ_ํ™•์ธ:
let isAgreeAllterm = state.isPersonalAndUsageArgee
&& state.isServiceAgree
&& state.isMarketingAgree
state.isAgreeAllTerms = isAgreeAllterm
return .none
/// - ๊ฐ๊ฐ์˜ ๊ฐœ๋ณ„ ๋™์˜ ์ฒดํฌ๋ฐ•์Šค๊ฐ€ ์„ ํƒ ๋˜์—ˆ์„ ๋•Œ
case .personalAndUsageAgreeSelected,
.serviceAgreeSelected,
.marketingAgreeSelected:
return .send(.inner(.checkAgreements))
case .๊ฐœ์ธ์ •๋ณด_๋™์˜_์„ ํƒํ–ˆ์„๋•Œ,
.์„œ๋น„์Šค_์ด์šฉ์•ฝ๊ด€_๋™์˜_์„ ํƒํ–ˆ์„๋•Œ,
.๋งˆ์ผ€ํŒ…_์ •๋ณด_์ˆ˜์‹ _๋™์˜_์„ ํƒํ–ˆ์„๋•Œ:
return .send(.inner(.๋™์˜_์ฒดํฌ_ํ™•์ธ))
/// - ์ „์ฒด ๋™์˜ ์ฒดํฌ๋ฐ•์œผ๊ฐ€ ์„ ํƒ ๋˜์—ˆ์„ ๋•Œ
case .allAgreementSelected:
case .์ „์ฒด_๋™์˜_์„ ํƒํ–ˆ์„๋•Œ:
state.isPersonalAndUsageArgee = state.isAgreeAllTerms
state.isServiceAgree = state.isAgreeAllTerms
state.isMarketingAgree = state.isAgreeAllTerms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public extension AgreeToTermsView {
PokitBottomButton(
"๋‹ค์Œ",
state: store.isPersonalAndUsageArgee && store.isServiceAgree ? .filled(.primary) : .disable,
action: { send(.nextButtonTapped) }
action: { send(.๋‹ค์Œ_๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ) }
)
}
.pokitMaxWidth()
Expand All @@ -49,7 +49,7 @@ public extension AgreeToTermsView {
PokitHeader {
PokitHeaderItems(placement: .leading) {
PokitToolbarButton(.icon(.arrowLeft)) {
send(.backButtonTapped)
send(.๋’ค๋กœ๊ฐ€๊ธฐ_๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ)
}
}
}
Expand Down Expand Up @@ -98,19 +98,19 @@ extension AgreeToTermsView {
termsButton(
"(ํ•„์ˆ˜)๊ฐœ์ธ์ •๋ณด ์ˆ˜์ง‘ ๋ฐ ์ด์šฉ ๋™์˜",
isSelected: $store.isPersonalAndUsageArgee,
action: { send(.๊ฐœ์ธ์ •๋ณด_๋™์˜_๋ฒ„ํŠผ_ํด๋ฆญ) }
action: { send(.๊ฐœ์ธ์ •๋ณด_๋™์˜_๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ) }
)

termsButton(
"(ํ•„์ˆ˜)์„œ๋น„์Šค ์ด์šฉ์•ฝ๊ด€",
isSelected: $store.isServiceAgree,
action: { send(.์„œ๋น„์Šค_์ด์šฉ์•ฝ๊ด€_๋ฒ„ํŠผ_ํด๋ฆญ) }
action: { send(.์„œ๋น„์Šค_์ด์šฉ์•ฝ๊ด€_๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ) }
)

termsButton(
"(์„ ํƒ)๋งˆ์ผ€ํŒ… ์ •๋ณด ์ˆ˜์‹ ",
isSelected: $store.isMarketingAgree,
action: { send(.๋งˆ์ผ€ํŒ…_์ •๋ณด_์ˆ˜์‹ _๋ฒ„ํŠผ_ํด๋ฆญ) }
action: { send(.๋งˆ์ผ€ํŒ…_์ •๋ณด_์ˆ˜์‹ _๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ) }
)
}
.padding(.leading, 20)
Expand Down
110 changes: 53 additions & 57 deletions Projects/Feature/FeatureLogin/Sources/Login/LoginFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,22 @@ public struct LoginFeature {
@CasePathable
public enum View: Equatable {
/// - Button Tapped
case appleLoginButtonTapped
case googleLoginButtonTapped
case ์• ํ”Œ๋กœ๊ทธ์ธ_๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ
case ๊ตฌ๊ธ€๋กœ๊ทธ์ธ_๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ
}
public enum InnerAction: Equatable {
case pushAgreeToTermsView
case pushRegisterNicknameView
case pushSelectFieldView(nickname: String)
case pushSignUpDoneView
case ์• ํ”Œ๋กœ๊ทธ์ธ(SocialLoginInfo)
case ๊ตฌ๊ธ€๋กœ๊ทธ์ธ(SocialLoginInfo)
case ์•ฝ๊ด€๋™์˜_ํ™”๋ฉด์ด๋™
case ๋‹‰๋„ค์ž„_๋“ฑ๋ก_ํ™”๋ฉด์ด๋™
case ๊ด€์‹ฌ๋ถ„์•ผ_์„ ํƒ_ํ™”๋ฉด์ด๋™(nickname: String)
case ํšŒ์›๊ฐ€์ž…_์™„๋ฃŒ_ํ™”๋ฉด์ด๋™
case ๋กœ๊ทธ์ธ_์ดํ›„_ํ™”๋ฉด์ด๋™(isRegistered: Bool)
}
public enum AsyncAction: Equatable {
case ํšŒ์›๊ฐ€์ž…
case ๋กœ๊ทธ์ธ(SocialLoginInfo)
case ํšŒ์›๊ฐ€์ž…_API
case ์• ํ”Œ๋กœ๊ทธ์ธ_API(SocialLoginInfo)
case ๊ตฌ๊ธ€๋กœ๊ทธ์ธ_API(SocialLoginInfo)
case ์• ํ”Œ๋กœ๊ทธ์ธ_์†Œ์…œ_API
case ๊ตฌ๊ธ€๋กœ๊ทธ์ธ_์†Œ์…œ_API
}
public enum ScopeAction {
case agreeToTerms(AgreeToTermsFeature.Action.DelegateAction)
Expand Down Expand Up @@ -106,34 +107,48 @@ private extension LoginFeature {
/// - View Effect
func handleViewAction(_ action: Action.View, state: inout State) -> Effect<Action> {
switch action {
case .appleLoginButtonTapped:
return .run { send in
let response = try await socialLogin.appleLogin()
await send(.async(.๋กœ๊ทธ์ธ(response)))
}

case .googleLoginButtonTapped:
return .run { send in
let response = try await socialLogin.googleLogin()
await send(.async(.๋กœ๊ทธ์ธ(response)))
}
case .์• ํ”Œ๋กœ๊ทธ์ธ_๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ:
return .send(.async(.์• ํ”Œ๋กœ๊ทธ์ธ_์†Œ์…œ_API))
case .๊ตฌ๊ธ€๋กœ๊ทธ์ธ_๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ:
return .send(.async(.๊ตฌ๊ธ€๋กœ๊ทธ์ธ_์†Œ์…œ_API))
}
}
/// - Inner Effect
func handleInnerAction(_ action: Action.InnerAction, state: inout State) -> Effect<Action> {
switch action {
case .pushAgreeToTermsView:
case .์•ฝ๊ด€๋™์˜_ํ™”๋ฉด์ด๋™:
state.path.append(.agreeToTerms(AgreeToTermsFeature.State()))
return .none
case .pushRegisterNicknameView:
case .๋‹‰๋„ค์ž„_๋“ฑ๋ก_ํ™”๋ฉด์ด๋™:
state.path.append(.registerNickname(RegisterNicknameFeature.State()))
return .none
case .pushSelectFieldView(let nickname):
case .๊ด€์‹ฌ๋ถ„์•ผ_์„ ํƒ_ํ™”๋ฉด์ด๋™(let nickname):
state.path.append(.selecteField(SelectFieldFeature.State(nickname: nickname)))
return .none
case .pushSignUpDoneView:
case .ํšŒ์›๊ฐ€์ž…_์™„๋ฃŒ_ํ™”๋ฉด์ด๋™:
return .send(.delegate(.ํšŒ์›๊ฐ€์ž…_์™„๋ฃŒ_ํ™”๋ฉด_์ด๋™))
case let .์• ํ”Œ๋กœ๊ทธ์ธ(response):
case let .๋กœ๊ทธ์ธ_์ดํ›„_ํ™”๋ฉด์ด๋™(isRegistered):
/// [3]. ์ด๋ฏธ ํšŒ์›๊ฐ€์ž…ํ–ˆ๋˜ ์œ ์ €๋ผ๋ฉด `๋ฉ”์ธ`์ด๋™
if isRegistered {
return .run { send in await send(.delegate(.dismissLoginRootView)) }
} else {
return .run { send in await send(.inner(.์•ฝ๊ด€๋™์˜_ํ™”๋ฉด์ด๋™)) }
}
}
}
/// - Async Effect
func handleAsyncAction(_ action: Action.AsyncAction, state: inout State) -> Effect<Action> {
switch action {
case .ํšŒ์›๊ฐ€์ž…_API:
return .run { [nickName = state.nickName, interests = state.interests] send in
guard let nickName else { return }
guard let interests else { return }
let signUpRequest = SignupRequest(nickName: nickName, interests: interests)
let _ = try await userClient.ํšŒ์›๋“ฑ๋ก(signUpRequest)

await send(.inner(.ํšŒ์›๊ฐ€์ž…_์™„๋ฃŒ_ํ™”๋ฉด์ด๋™))
}
case let .์• ํ”Œ๋กœ๊ทธ์ธ_API(response):
return .run { send in
guard let idToken = response.idToken else { return }
guard let authCode = response.authCode else { return }
Expand All @@ -157,7 +172,7 @@ private extension LoginFeature {

await send(.inner(.๋กœ๊ทธ์ธ_์ดํ›„_ํ™”๋ฉด์ด๋™(isRegistered: tokenResponse.isRegistered)))
}
case let .๊ตฌ๊ธ€๋กœ๊ทธ์ธ(response):
case let .๊ตฌ๊ธ€๋กœ๊ทธ์ธ_API(response):
return .run { send in
guard let idToken = response.idToken else { return }
let platform = response.provider.description
Expand All @@ -173,34 +188,15 @@ private extension LoginFeature {

await send(.inner(.๋กœ๊ทธ์ธ_์ดํ›„_ํ™”๋ฉด์ด๋™(isRegistered: tokenResponse.isRegistered)))
}
case let .๋กœ๊ทธ์ธ_์ดํ›„_ํ™”๋ฉด์ด๋™(isRegistered):
/// [3]. ์ด๋ฏธ ํšŒ์›๊ฐ€์ž…ํ–ˆ๋˜ ์œ ์ €๋ผ๋ฉด `๋ฉ”์ธ`์ด๋™
if isRegistered {
return .run { send in await send(.delegate(.dismissLoginRootView)) }
} else {
return .run { send in await send(.inner(.pushAgreeToTermsView)) }
}
}
}
/// - Async Effect
func handleAsyncAction(_ action: Action.AsyncAction, state: inout State) -> Effect<Action> {
switch action {
case .ํšŒ์›๊ฐ€์ž…:
return .run { [nickName = state.nickName, interests = state.interests] send in
guard let nickName else { return }
guard let interests else { return }
let signUpRequest = SignupRequest(nickName: nickName, interests: interests)
let _ = try await userClient.ํšŒ์›๋“ฑ๋ก(signUpRequest)

await send(.inner(.pushSignUpDoneView))
case .์• ํ”Œ๋กœ๊ทธ์ธ_์†Œ์…œ_API:
return .run { send in
let response = try await socialLogin.appleLogin()
await send(.async(.์• ํ”Œ๋กœ๊ทธ์ธ_API(response)))
}

case .๋กœ๊ทธ์ธ(let response):
switch response.provider {
case .apple:
return .run { send in await send(.inner(.์• ํ”Œ๋กœ๊ทธ์ธ(response))) }
case .google:
return .run { send in await send(.inner(.๊ตฌ๊ธ€๋กœ๊ทธ์ธ(response))) }
case .๊ตฌ๊ธ€๋กœ๊ทธ์ธ_์†Œ์…œ_API:
return .run { send in
let response = try await socialLogin.googleLogin()
await send(.async(.๊ตฌ๊ธ€๋กœ๊ทธ์ธ_API(response)))
}
}
}
Expand All @@ -210,19 +206,19 @@ private extension LoginFeature {
case .agreeToTerms(let delegate):
switch delegate {
case .pushRegisterNicknameView:
return .send(.inner(.pushRegisterNicknameView))
return .send(.inner(.๋‹‰๋„ค์ž„_๋“ฑ๋ก_ํ™”๋ฉด์ด๋™))
}
case .registerNickname(let delegate):
switch delegate {
case .pushSelectFieldView(let nickname):
state.nickName = nickname
return .send(.inner(.pushSelectFieldView(nickname: nickname)))
return .send(.inner(.๊ด€์‹ฌ๋ถ„์•ผ_์„ ํƒ_ํ™”๋ฉด์ด๋™(nickname: nickname)))
}
case .selectField(let delegate):
switch delegate {
case let .pushSignUpDoneView(interests):
state.interests = interests
return .send(.async(.ํšŒ์›๊ฐ€์ž…))
return .send(.async(.ํšŒ์›๊ฐ€์ž…_API))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Projects/Feature/FeatureLogin/Sources/Login/LoginView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ extension LoginView {

private var appleLoginButton: some View {
Button {
send(.appleLoginButtonTapped)
send(.์• ํ”Œ๋กœ๊ทธ์ธ_๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ)
} label: {
appleLoginButtonLabel
}
Expand Down Expand Up @@ -123,7 +123,7 @@ extension LoginView {

private var googleLoginButton: some View {
Button {
send(.googleLoginButtonTapped)
send(.๊ตฌ๊ธ€๋กœ๊ทธ์ธ_๋ฒ„ํŠผ_๋ˆŒ๋ €์„๋•Œ)
} label: {
googleLoginButtonLabel
}
Expand Down
Loading

0 comments on commit 423efee

Please sign in to comment.