fixing crash when switching from the invitations screen to the conversation directory and back to the profile
This commit is contained in:
parent
e5eb597369
commit
eff150aebc
|
@ -98,7 +98,17 @@ class HomeViewModel(
|
|||
fun changePage(page: Page) {
|
||||
state = when (val current = state) {
|
||||
Loading -> current
|
||||
is SignedIn -> current.copy(page = page)
|
||||
is SignedIn -> {
|
||||
when (page) {
|
||||
Page.Directory -> {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
Page.Profile -> profileViewModel.reset()
|
||||
}
|
||||
current.copy(page = page)
|
||||
}
|
||||
|
||||
SignedOut -> current
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,10 +7,10 @@ import androidx.compose.foundation.layout.*
|
|||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.CameraAlt
|
||||
import androidx.compose.material.icons.filled.Settings
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
|
@ -19,7 +19,6 @@ import androidx.compose.ui.platform.LocalContext
|
|||
import androidx.compose.ui.unit.dp
|
||||
import app.dapk.st.core.Lce
|
||||
import app.dapk.st.core.LifecycleEffect
|
||||
import app.dapk.st.core.StartObserving
|
||||
import app.dapk.st.core.components.CenteredLoading
|
||||
import app.dapk.st.design.components.*
|
||||
import app.dapk.st.matrix.sync.InviteMeta
|
||||
|
@ -43,6 +42,7 @@ fun ProfileScreen(viewModel: ProfileViewModel, onTopLevelBack: () -> Unit) {
|
|||
else -> viewModel.goTo(it)
|
||||
}
|
||||
}
|
||||
|
||||
Spider(currentPage = viewModel.state.page, onNavigate = onNavigate) {
|
||||
item(Page.Routes.profile) {
|
||||
ProfilePage(context, viewModel, it)
|
||||
|
@ -146,6 +146,7 @@ private fun Invitations(viewModel: ProfileViewModel, invitations: Page.Invitatio
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
is Lce.Error -> TODO()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,10 +102,6 @@ class ProfileViewModel(
|
|||
)
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
syncingJob?.cancel()
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private inline fun <reified S : Page> updatePageState(crossinline block: S.() -> S) {
|
||||
val page = state.page
|
||||
|
@ -114,6 +110,14 @@ class ProfileViewModel(
|
|||
updateState { copy(page = (page as SpiderPage<S>).copy(state = block(page.state))) }
|
||||
}
|
||||
|
||||
fun reset() {
|
||||
updateState { ProfileScreenState(SpiderPage(Page.Routes.profile, "Profile", null, Page.Profile(Lce.Loading()), hasToolbar = false)) }
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
syncingJob?.cancel()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun <S, VE, T> DapkViewModel<S, VE>.launchCatching(block: suspend () -> T): LaunchCatching<T> {
|
||||
|
|
Loading…
Reference in New Issue