Skip to content

Commit

Permalink
refactor(auth): move AuthenticatedScreen from LoginWithEmailScreen.…
Browse files Browse the repository at this point in the history
…kt to RootAuthScreen.kt
  • Loading branch information
deepanchal committed Sep 4, 2023
1 parent 3cb729a commit c0f4c37
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,42 +246,3 @@ private fun LoginWithEmailScreen(
)
}
}

@Composable
internal fun AuthenticatedScreen(
authState: AuthenticationState,
closeAuthentication: () -> Unit = {},
viewModel: AuthenticationViewModel = hiltViewModel(),
) {
val translator = LocalAppTranslator.current

Text(
modifier = fillWidthPadded.testTag("authedProfileAccountInfo"),
text = translator("info.account_is")
.replace("{full_name}", authState.accountData.fullName)
.replace("{email_address}", authState.accountData.emailAddress),
)

val authErrorMessage by viewModel.errorMessage
ConditionalErrorMessage(authErrorMessage)

val isNotBusy by viewModel.isNotAuthenticating.collectAsStateWithLifecycle()

BusyButton(
modifier = fillWidthPadded.testTag("authedProfileLogoutBtn"),
onClick = viewModel::logout,
enabled = isNotBusy,
text = translator("actions.logout"),
indicateBusy = !isNotBusy,
)

LinkAction(
"actions.back",
modifier = Modifier
.listItemPadding()
.testTag("authedProfileDismissBtn"),
arrangement = Arrangement.Start,
enabled = isNotBusy,
action = closeAuthentication,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ import com.crisiscleanup.core.designsystem.theme.DayNightPreviews
import com.crisiscleanup.core.designsystem.theme.LocalFontStyles
import com.crisiscleanup.core.designsystem.theme.fillWidthPadded
import com.crisiscleanup.core.designsystem.theme.listItemModifier
import com.crisiscleanup.core.designsystem.theme.listItemPadding
import com.crisiscleanup.core.model.data.emptyAccountData
import com.crisiscleanup.core.ui.rememberCloseKeyboard
import com.crisiscleanup.core.ui.rememberIsKeyboardOpen
import com.crisiscleanup.core.ui.scrollFlingListener
import com.crisiscleanup.feature.authentication.AuthState
import com.crisiscleanup.feature.authentication.AuthenticationViewModel
import com.crisiscleanup.feature.authentication.R
import com.crisiscleanup.feature.authentication.RootAuthViewModel
import com.crisiscleanup.feature.authentication.model.AuthenticationState
Expand Down Expand Up @@ -192,6 +194,45 @@ internal fun RootAuthScreen(
}
}

@Composable
internal fun AuthenticatedScreen(
authState: AuthenticationState,
closeAuthentication: () -> Unit = {},
viewModel: AuthenticationViewModel = hiltViewModel(),
) {
val translator = LocalAppTranslator.current

Text(
modifier = fillWidthPadded.testTag("authedProfileAccountInfo"),
text = translator("info.account_is")
.replace("{full_name}", authState.accountData.fullName)
.replace("{email_address}", authState.accountData.emailAddress),
)

val authErrorMessage by viewModel.errorMessage
ConditionalErrorMessage(authErrorMessage)

val isNotBusy by viewModel.isNotAuthenticating.collectAsStateWithLifecycle()

BusyButton(
modifier = fillWidthPadded.testTag("authedProfileLogoutBtn"),
onClick = viewModel::logout,
enabled = isNotBusy,
text = translator("actions.logout"),
indicateBusy = !isNotBusy,
)

LinkAction(
"actions.back",
modifier = Modifier
.listItemPadding()
.testTag("authedProfileDismissBtn"),
arrangement = Arrangement.Start,
enabled = isNotBusy,
action = closeAuthentication,
)
}

@DayNightPreviews
@Composable
fun RootLoginScreenPreview() {
Expand Down

0 comments on commit c0f4c37

Please sign in to comment.