Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ fun MenuScreen() {

val navigator = LocalCodeNavigator.current

LaunchedEffect(viewModel) {
viewModel.eventFlow
.filterIsInstance<MenuScreenViewModel.Event.OnLoggedOutCompletely>()
.onEach {
navigator.hide()
navigator.replaceAll(AppRoute.Onboarding.Login()) }
.launchIn(this)
}

LaunchedEffect(viewModel) {
viewModel.eventFlow
.filterIsInstance<MenuScreenViewModel.Event.OpenScreen>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,3 @@ internal data object Labs : StaffMenuItem<MenuScreenViewModel.Event>() {
AppRoute.Menu.Lab
)
}

internal data object LogOut : FullMenuItem<MenuScreenViewModel.Event>() {
override val icon: Painter
@Composable get() = painterResource(R.drawable.ic_menu_logout)
override val name: String
@Composable get() = stringResource(R.string.action_logout)
override val action: MenuScreenViewModel.Event = MenuScreenViewModel.Event.OnLogOutClicked
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,35 +117,6 @@ internal fun MenuScreenContent(viewModel: MenuScreenViewModel) {
}
}
},
footer = {
CodeButton(
modifier = Modifier
.fillMaxWidth()
.padding(top = CodeTheme.dimens.grid.x3)
.padding(horizontal = CodeTheme.dimens.grid.x3),
onClick = { viewModel.dispatchEvent(Event.OnLogOutClicked) },
buttonState = ButtonState.Subtle,
) {
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(CodeTheme.dimens.grid.x1, Alignment.CenterHorizontally),
) {
Image(
painter = painterResource(R.drawable.ic_menu_logout),
colorFilter = ColorFilter.tint(CodeTheme.colors.textSecondary),
contentDescription = null,
)

Text(
modifier = Modifier.padding(start = CodeTheme.dimens.grid.x1),
text = stringResource(R.string.action_logout),
style = CodeTheme.typography.textMedium,
color = CodeTheme.colors.textSecondary,
)
}
}
},
contentPadding = PaddingValues(top = CodeTheme.dimens.grid.x3),
onItemClick = {
viewModel.dispatchEvent(it.action)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ private val FullMenuList = buildList {

@HiltViewModel
internal class MenuScreenViewModel @Inject constructor(
private val resources: ResourceHelper,
userManager: UserManager,
userFlags: UserFlagsCoordinator,
authManager: AuthManager,
Expand Down Expand Up @@ -81,8 +80,6 @@ internal class MenuScreenViewModel @Inject constructor(
data class OnStaffUserDetermined(val staff: Boolean) : Event
data class OpenScreen(val screen: AppRoute) : Event
data object OnSwitchAccountsClicked : Event
data object OnLogOutClicked : Event
data object OnLoggedOutCompletely : Event
data class OnSwitchAccountTo(val entropy: String): Event
}

Expand Down Expand Up @@ -149,33 +146,6 @@ internal class MenuScreenViewModel @Inject constructor(
onError = { },
onSuccess = { dispatchEvent(Event.OnSwitchAccountTo(it)) }
).launchIn(viewModelScope)

eventFlow
.filterIsInstance<Event.OnLogOutClicked>()
.onEach {
BottomBarManager.showAlert(
title = resources.getString(R.string.prompt_title_logout),
message = resources.getString(R.string.prompt_description_logout),
actions = listOf(
BottomBarAction(resources.getString(R.string.action_logout)) {
viewModelScope.launch {
delay(150) // wait for dismiss
authManager.logout()
.onSuccess {
dispatchEvent(Event.OnLoggedOutCompletely)
}
.onFailure {
BottomBarManager.showError(
title = resources.getString(R.string.error_title_failedToLogOut),
message = resources.getString(R.string.error_description_failedToLogOut),
)
}
}
},
),
showCancel = true,
)
}.launchIn(viewModelScope)
}

internal companion object {
Expand Down Expand Up @@ -248,10 +218,8 @@ internal class MenuScreenViewModel @Inject constructor(
}

Event.CheckForUpdate,
Event.OnLogOutClicked,
Event.OnSwitchAccountsClicked,
is Event.OpenScreen,
Event.OnLoggedOutCompletely,
is Event.OnSwitchAccountTo -> { state -> state }

is Event.OnFeatureFlagsUpdated -> { state ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ fun MyAccountScreen() {
MyAccountScreen(viewModel)
}

LaunchedEffect(viewModel) {
viewModel.eventFlow
.filterIsInstance<MyAccountScreenViewModel.Event.OnLoggedOutCompletely>()
.onEach {
navigator.hide()
navigator.replaceAll(AppRoute.Onboarding.Login()) }
.launchIn(this)
}

LaunchedEffect(viewModel) {
viewModel.eventFlow
.filterIsInstance<MyAccountScreenViewModel.Event.OnAccountDeleted>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ internal data object VerifyPhone : FullMenuItem<MyAccountScreenViewModel.Event>(
override val action: MyAccountScreenViewModel.Event = MyAccountScreenViewModel.Event.OnVerifyPhoneClicked
}

internal data object LogOut : FullMenuItem<MyAccountScreenViewModel.Event>() {
override val icon: Painter
@Composable get() = painterResource(R.drawable.ic_menu_logout)
override val name: String
@Composable get() = stringResource(R.string.action_logout)
override val action: MyAccountScreenViewModel.Event = MyAccountScreenViewModel.Event.OnLogOutClicked
}

internal data object DeleteAccount: FullMenuItem<MyAccountScreenViewModel.Event>() {
override val icon: Painter
@Composable get() = rememberVectorPainter(ImageVector.Delete)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ private val FullMenuList = buildList {
add(AccessKey)
add(VerifyPhone)
add(VerifyEmail)
add(LogOut)
add(DeleteAccount)
}

Expand Down Expand Up @@ -68,13 +69,15 @@ internal class MyAccountScreenViewModel @Inject constructor(
data class ToggleAccountInfo(val show: Boolean) : Event
data object OnAccessKeyClicked : Event
data object OnViewAccessKey : Event
data object OnVerifyEmailClicked: Event
data object OnVerifyPhoneClicked: Event
data object OnVerifyEmailClicked : Event
data object OnVerifyPhoneClicked : Event
data object OnDeleteAccountClicked : Event
data object OnAccountDeleted : Event
data object CopyPublicKey : Event
data object CopyAccountId : Event
data object CopyPushToken : Event
data object OnLogOutClicked : Event
data object OnLoggedOutCompletely : Event
}

init {
Expand Down Expand Up @@ -179,6 +182,33 @@ internal class MyAccountScreenViewModel @Inject constructor(
),
)
}.launchIn(viewModelScope)

eventFlow
.filterIsInstance<Event.OnLogOutClicked>()
.onEach {
BottomBarManager.showAlert(
title = resources.getString(R.string.prompt_title_logout),
message = resources.getString(R.string.prompt_description_logout),
actions = listOf(
BottomBarAction(resources.getString(R.string.action_logout)) {
viewModelScope.launch {
delay(150) // wait for dismiss
authManager.logout()
.onSuccess {
dispatchEvent(Event.OnLoggedOutCompletely)
}
.onFailure {
BottomBarManager.showError(
title = resources.getString(R.string.error_title_failedToLogOut),
message = resources.getString(R.string.error_description_failedToLogOut),
)
}
}
},
),
showCancel = true,
)
}.launchIn(viewModelScope)
}

internal companion object {
Expand All @@ -202,6 +232,8 @@ internal class MyAccountScreenViewModel @Inject constructor(
)
}

Event.OnLogOutClicked,
Event.OnLoggedOutCompletely,
Event.OnVerifyPhoneClicked,
Event.OnVerifyEmailClicked,
Event.OnViewAccessKey,
Expand All @@ -214,7 +246,10 @@ internal class MyAccountScreenViewModel @Inject constructor(
Event.OnAccessKeyClicked -> { state -> state }

is Event.OnBetaFeaturesUnlocked -> { state ->
state.copy(isBetaEnabled = event.unlocked, items = buildItemList(event.unlocked))
state.copy(
isBetaEnabled = event.unlocked,
items = buildItemList(event.unlocked)
)
}

is Event.ToggleAccountInfo -> { state ->
Expand Down
Loading