Skip to content

Commit

Permalink
TutorialPage의 LaunchedEffect 함수들 통합
Browse files Browse the repository at this point in the history
  • Loading branch information
plgafhd committed Oct 10, 2024
1 parent 7e0a5b4 commit 76c917c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ enum class SocialLoginType {
KAKAO,
GOOGLE,
}

fun SocialLoginType.getString(): String {
return when (this) {
SocialLoginType.FACEBOOK -> "페이스북"
SocialLoginType.GOOGLE -> "구글"
SocialLoginType.KAKAO -> "카카오"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ fun SocialLinkPage() {
is SocialLoginState.Initial -> {}
is SocialLoginState.InProgress -> {}
is SocialLoginState.Cancelled -> {
context.toast(context.getString(R.string.sign_in_facebook_failed_cancelled))
//context.toast(context.getString(R.string.sign_in_facebook_failed_cancelled))
socialLinkViewModel.updateFacebookLoginState(SocialLoginState.Initial)
}
is SocialLoginState.Failed -> {
context.toast(context.getString(R.string.sign_in_facebook_failed_unknown))
//context.toast(context.getString(R.string.sign_in_facebook_failed_unknown))
socialLinkViewModel.updateFacebookLoginState(SocialLoginState.Initial)
}
is SocialLoginState.Success -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.wafflestudio.snutt2.ui.SNUTTColors
import com.wafflestudio.snutt2.ui.SNUTTTypography
import com.wafflestudio.snutt2.ui.state.SocialLoginState
import com.wafflestudio.snutt2.ui.state.SocialLoginType
import com.wafflestudio.snutt2.ui.state.getString
import com.wafflestudio.snutt2.views.*
import com.wafflestudio.snutt2.views.logged_in.home.HomeViewModel
import com.wafflestudio.snutt2.views.logged_in.home.settings.SocialLinkViewModel
Expand Down Expand Up @@ -97,67 +98,34 @@ fun TutorialPage() {
}
}

LaunchedEffect(kakaoLoginState) {
when (kakaoLoginState) {
val socialLoginStateEffect: (SocialLoginType, SocialLoginState) -> Unit = { type, state ->
when (state) {
is SocialLoginState.Initial -> {}
is SocialLoginState.InProgress -> {}
is SocialLoginState.Cancelled -> {
context.toast(context.getString(R.string.sign_in_kakao_failed_cancelled))
socialLinkViewModel.updateKakaoLoginState(SocialLoginState.Initial)
context.toast(context.getString(R.string.social_signin_failed_cancelled, type.getString()))
socialLinkViewModel.updateSocialLoginState(type, SocialLoginState.Initial)
}
is SocialLoginState.Failed -> {
context.toast(context.getString(R.string.sign_in_kakao_failed_unknown))
socialLinkViewModel.updateKakaoLoginState(SocialLoginState.Initial)
context.toast(context.getString(R.string.social_signin_kakao_failed_unknown, type.getString()))
socialLinkViewModel.updateSocialLoginState(type, SocialLoginState.Initial)
}
is SocialLoginState.Success -> {
loginWithSocialAccessToken(
SocialLoginType.KAKAO,
(kakaoLoginState as SocialLoginState.Success).token
)
loginWithSocialAccessToken(type, state.token)
}
}
}

LaunchedEffect(googleLoginState) {
when (googleLoginState) {
is SocialLoginState.Initial -> {}
is SocialLoginState.InProgress -> {}
is SocialLoginState.Cancelled -> {
context.toast(context.getString(R.string.sign_in_sign_in_google_cancelled))
socialLinkViewModel.updateGoogleLoginState(SocialLoginState.Initial)
}
is SocialLoginState.Failed -> {
context.toast(context.getString(R.string.sign_in_sign_in_google_failed_unknown))
socialLinkViewModel.updateGoogleLoginState(SocialLoginState.Initial)
}
is SocialLoginState.Success -> {
loginWithSocialAccessToken(
SocialLoginType.GOOGLE,
(googleLoginState as SocialLoginState.Success).token
)
}
}
LaunchedEffect(facebookLoginState) {
socialLoginStateEffect(SocialLoginType.FACEBOOK, facebookLoginState)
}

LaunchedEffect(facebookLoginState) {
when (facebookLoginState) {
is SocialLoginState.Initial -> {}
is SocialLoginState.InProgress -> {}
is SocialLoginState.Cancelled -> {
context.toast(context.getString(R.string.sign_in_facebook_failed_cancelled))
socialLinkViewModel.updateFacebookLoginState(SocialLoginState.Initial)
}
is SocialLoginState.Failed -> {
context.toast(context.getString(R.string.sign_in_facebook_failed_unknown))
socialLinkViewModel.updateFacebookLoginState(SocialLoginState.Initial)
}
is SocialLoginState.Success -> {
loginWithSocialAccessToken(
SocialLoginType.FACEBOOK,
(facebookLoginState as SocialLoginState.Success).token
)
}
}
LaunchedEffect(kakaoLoginState) {
socialLoginStateEffect(SocialLoginType.KAKAO, kakaoLoginState)
}

LaunchedEffect(googleLoginState) {
socialLoginStateEffect(SocialLoginType.GOOGLE, googleLoginState)
}

Column(
Expand Down
8 changes: 2 additions & 6 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@
<string name="continue_with_sns_account">SNS 계정으로 계속하기</string>
<string name="sign_in_sign_in_facebook_button">페이스북으로 시작하기</string>
<string name="sign_in_sign_in_google_button">구글 계정으로 시작하기</string>
<string name="sign_in_sign_in_google_cancelled">구글 로그인이 취소되었습니다.</string>
<string name="sign_in_sign_in_google_failed_unknown">구글 로그인에 실패했습니다. 잠시 후 다시 시도해 주세요.</string>
<string name="social_link_title">SNS 계정 연동 및 해제</string>
<string name="social_link_account_already_using">이미 사용 중인 이메일입니다.\n%s 계정으로 시도해 보세요.</string>
<string name="social_link_kakao">카카오 계정 연동</string>
Expand All @@ -97,10 +95,8 @@
<string name="social_unlink_kakao">카카오 계정 연동 해제</string>
<string name="social_unlink_google">구글 계정 연동 해제</string>
<string name="social_unlink_facebook">페이스북 계정 연동 해제</string>
<string name="sign_in_kakao_failed_cancelled">카카오 로그인이 취소되었습니다.</string>
<string name="sign_in_kakao_failed_unknown">카카오 로그인에 실패했습니다. 잠시 후 다시 시도해 주세요.</string>
<string name="sign_in_facebook_failed_cancelled">페이스북 로그인이 취소되었습니다.</string>
<string name="sign_in_facebook_failed_unknown">페이스북 로그인에 실패했습니다. 잠시 후 다시 시도해 주세요.</string>
<string name="social_signin_failed_cancelled">%s 로그인이 취소되었습니다.</string>
<string name="social_signin_kakao_failed_unknown">%s 로그인에 실패했습니다. 잠시 후 다시 시도해 주세요.</string>

<!--licenses-->
<string name="settings_licenses_title">오픈소스 라이선스</string>
Expand Down

0 comments on commit 76c917c

Please sign in to comment.