Skip to content

Commit 765b682

Browse files
committed
feat(menu): move logout action from menu to my account screen
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 3349b44 commit 765b682

7 files changed

Lines changed: 55 additions & 81 deletions

File tree

apps/flipcash/features/menu/src/main/kotlin/com/flipcash/app/menu/MenuScreen.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ fun MenuScreen() {
1919

2020
val navigator = LocalCodeNavigator.current
2121

22-
LaunchedEffect(viewModel) {
23-
viewModel.eventFlow
24-
.filterIsInstance<MenuScreenViewModel.Event.OnLoggedOutCompletely>()
25-
.onEach {
26-
navigator.hide()
27-
navigator.replaceAll(AppRoute.Onboarding.Login()) }
28-
.launchIn(this)
29-
}
30-
3122
LaunchedEffect(viewModel) {
3223
viewModel.eventFlow
3324
.filterIsInstance<MenuScreenViewModel.Event.OpenScreen>()

apps/flipcash/features/menu/src/main/kotlin/com/flipcash/app/menu/internal/MenuItems.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,3 @@ internal data object Labs : StaffMenuItem<MenuScreenViewModel.Event>() {
7575
AppRoute.Menu.Lab
7676
)
7777
}
78-
79-
internal data object LogOut : FullMenuItem<MenuScreenViewModel.Event>() {
80-
override val icon: Painter
81-
@Composable get() = painterResource(R.drawable.ic_menu_logout)
82-
override val name: String
83-
@Composable get() = stringResource(R.string.action_logout)
84-
override val action: MenuScreenViewModel.Event = MenuScreenViewModel.Event.OnLogOutClicked
85-
}

apps/flipcash/features/menu/src/main/kotlin/com/flipcash/app/menu/internal/MenuScreenContent.kt

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -117,35 +117,6 @@ internal fun MenuScreenContent(viewModel: MenuScreenViewModel) {
117117
}
118118
}
119119
},
120-
footer = {
121-
CodeButton(
122-
modifier = Modifier
123-
.fillMaxWidth()
124-
.padding(top = CodeTheme.dimens.grid.x3)
125-
.padding(horizontal = CodeTheme.dimens.grid.x3),
126-
onClick = { viewModel.dispatchEvent(Event.OnLogOutClicked) },
127-
buttonState = ButtonState.Subtle,
128-
) {
129-
Row(
130-
modifier = Modifier.fillMaxWidth(),
131-
verticalAlignment = Alignment.CenterVertically,
132-
horizontalArrangement = Arrangement.spacedBy(CodeTheme.dimens.grid.x1, Alignment.CenterHorizontally),
133-
) {
134-
Image(
135-
painter = painterResource(R.drawable.ic_menu_logout),
136-
colorFilter = ColorFilter.tint(CodeTheme.colors.textSecondary),
137-
contentDescription = null,
138-
)
139-
140-
Text(
141-
modifier = Modifier.padding(start = CodeTheme.dimens.grid.x1),
142-
text = stringResource(R.string.action_logout),
143-
style = CodeTheme.typography.textMedium,
144-
color = CodeTheme.colors.textSecondary,
145-
)
146-
}
147-
}
148-
},
149120
contentPadding = PaddingValues(top = CodeTheme.dimens.grid.x3),
150121
onItemClick = {
151122
viewModel.dispatchEvent(it.action)

apps/flipcash/features/menu/src/main/kotlin/com/flipcash/app/menu/internal/MenuScreenViewModel.kt

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ private val FullMenuList = buildList {
4646

4747
@HiltViewModel
4848
internal class MenuScreenViewModel @Inject constructor(
49-
private val resources: ResourceHelper,
5049
userManager: UserManager,
5150
userFlags: UserFlagsCoordinator,
5251
authManager: AuthManager,
@@ -81,8 +80,6 @@ internal class MenuScreenViewModel @Inject constructor(
8180
data class OnStaffUserDetermined(val staff: Boolean) : Event
8281
data class OpenScreen(val screen: AppRoute) : Event
8382
data object OnSwitchAccountsClicked : Event
84-
data object OnLogOutClicked : Event
85-
data object OnLoggedOutCompletely : Event
8683
data class OnSwitchAccountTo(val entropy: String): Event
8784
}
8885

@@ -149,33 +146,6 @@ internal class MenuScreenViewModel @Inject constructor(
149146
onError = { },
150147
onSuccess = { dispatchEvent(Event.OnSwitchAccountTo(it)) }
151148
).launchIn(viewModelScope)
152-
153-
eventFlow
154-
.filterIsInstance<Event.OnLogOutClicked>()
155-
.onEach {
156-
BottomBarManager.showAlert(
157-
title = resources.getString(R.string.prompt_title_logout),
158-
message = resources.getString(R.string.prompt_description_logout),
159-
actions = listOf(
160-
BottomBarAction(resources.getString(R.string.action_logout)) {
161-
viewModelScope.launch {
162-
delay(150) // wait for dismiss
163-
authManager.logout()
164-
.onSuccess {
165-
dispatchEvent(Event.OnLoggedOutCompletely)
166-
}
167-
.onFailure {
168-
BottomBarManager.showError(
169-
title = resources.getString(R.string.error_title_failedToLogOut),
170-
message = resources.getString(R.string.error_description_failedToLogOut),
171-
)
172-
}
173-
}
174-
},
175-
),
176-
showCancel = true,
177-
)
178-
}.launchIn(viewModelScope)
179149
}
180150

181151
internal companion object {
@@ -248,10 +218,8 @@ internal class MenuScreenViewModel @Inject constructor(
248218
}
249219

250220
Event.CheckForUpdate,
251-
Event.OnLogOutClicked,
252221
Event.OnSwitchAccountsClicked,
253222
is Event.OpenScreen,
254-
Event.OnLoggedOutCompletely,
255223
is Event.OnSwitchAccountTo -> { state -> state }
256224

257225
is Event.OnFeatureFlagsUpdated -> { state ->

apps/flipcash/features/myaccount/src/main/kotlin/com/flipcash/app/myaccount/MyAccountScreen.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ fun MyAccountScreen() {
4949
MyAccountScreen(viewModel)
5050
}
5151

52+
LaunchedEffect(viewModel) {
53+
viewModel.eventFlow
54+
.filterIsInstance<MyAccountScreenViewModel.Event.OnLoggedOutCompletely>()
55+
.onEach {
56+
navigator.hide()
57+
navigator.replaceAll(AppRoute.Onboarding.Login()) }
58+
.launchIn(this)
59+
}
60+
5261
LaunchedEffect(viewModel) {
5362
viewModel.eventFlow
5463
.filterIsInstance<MyAccountScreenViewModel.Event.OnAccountDeleted>()

apps/flipcash/features/myaccount/src/main/kotlin/com/flipcash/app/myaccount/internal/MyAccountMenuItems.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ internal data object VerifyPhone : FullMenuItem<MyAccountScreenViewModel.Event>(
3737
override val action: MyAccountScreenViewModel.Event = MyAccountScreenViewModel.Event.OnVerifyPhoneClicked
3838
}
3939

40+
internal data object LogOut : FullMenuItem<MyAccountScreenViewModel.Event>() {
41+
override val icon: Painter
42+
@Composable get() = painterResource(R.drawable.ic_menu_logout)
43+
override val name: String
44+
@Composable get() = stringResource(R.string.action_logout)
45+
override val action: MyAccountScreenViewModel.Event = MyAccountScreenViewModel.Event.OnLogOutClicked
46+
}
47+
4048
internal data object DeleteAccount: FullMenuItem<MyAccountScreenViewModel.Event>() {
4149
override val icon: Painter
4250
@Composable get() = rememberVectorPainter(ImageVector.Delete)

apps/flipcash/features/myaccount/src/main/kotlin/com/flipcash/app/myaccount/internal/MyAccountScreenViewModel.kt

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ private val FullMenuList = buildList {
3131
add(AccessKey)
3232
add(VerifyPhone)
3333
add(VerifyEmail)
34+
add(LogOut)
3435
add(DeleteAccount)
3536
}
3637

@@ -68,13 +69,15 @@ internal class MyAccountScreenViewModel @Inject constructor(
6869
data class ToggleAccountInfo(val show: Boolean) : Event
6970
data object OnAccessKeyClicked : Event
7071
data object OnViewAccessKey : Event
71-
data object OnVerifyEmailClicked: Event
72-
data object OnVerifyPhoneClicked: Event
72+
data object OnVerifyEmailClicked : Event
73+
data object OnVerifyPhoneClicked : Event
7374
data object OnDeleteAccountClicked : Event
7475
data object OnAccountDeleted : Event
7576
data object CopyPublicKey : Event
7677
data object CopyAccountId : Event
7778
data object CopyPushToken : Event
79+
data object OnLogOutClicked : Event
80+
data object OnLoggedOutCompletely : Event
7881
}
7982

8083
init {
@@ -179,6 +182,33 @@ internal class MyAccountScreenViewModel @Inject constructor(
179182
),
180183
)
181184
}.launchIn(viewModelScope)
185+
186+
eventFlow
187+
.filterIsInstance<Event.OnLogOutClicked>()
188+
.onEach {
189+
BottomBarManager.showAlert(
190+
title = resources.getString(R.string.prompt_title_logout),
191+
message = resources.getString(R.string.prompt_description_logout),
192+
actions = listOf(
193+
BottomBarAction(resources.getString(R.string.action_logout)) {
194+
viewModelScope.launch {
195+
delay(150) // wait for dismiss
196+
authManager.logout()
197+
.onSuccess {
198+
dispatchEvent(Event.OnLoggedOutCompletely)
199+
}
200+
.onFailure {
201+
BottomBarManager.showError(
202+
title = resources.getString(R.string.error_title_failedToLogOut),
203+
message = resources.getString(R.string.error_description_failedToLogOut),
204+
)
205+
}
206+
}
207+
},
208+
),
209+
showCancel = true,
210+
)
211+
}.launchIn(viewModelScope)
182212
}
183213

184214
internal companion object {
@@ -202,6 +232,8 @@ internal class MyAccountScreenViewModel @Inject constructor(
202232
)
203233
}
204234

235+
Event.OnLogOutClicked,
236+
Event.OnLoggedOutCompletely,
205237
Event.OnVerifyPhoneClicked,
206238
Event.OnVerifyEmailClicked,
207239
Event.OnViewAccessKey,
@@ -214,7 +246,10 @@ internal class MyAccountScreenViewModel @Inject constructor(
214246
Event.OnAccessKeyClicked -> { state -> state }
215247

216248
is Event.OnBetaFeaturesUnlocked -> { state ->
217-
state.copy(isBetaEnabled = event.unlocked, items = buildItemList(event.unlocked))
249+
state.copy(
250+
isBetaEnabled = event.unlocked,
251+
items = buildItemList(event.unlocked)
252+
)
218253
}
219254

220255
is Event.ToggleAccountInfo -> { state ->

0 commit comments

Comments
 (0)