parent
7a8c8ed88d
commit
58470e2dcd
|
@ -1 +1 @@
|
|||
Subproject commit cdf3e1bffba4b69dd8f752c6cc7588b0e89a17af
|
||||
Subproject commit 9017fe3963754199db7c2525ba38a3265ef5701d
|
|
@ -8,14 +8,21 @@ android {
|
|||
|
||||
dependencies {
|
||||
implementation "chat-engine:chat-engine"
|
||||
implementation 'screen-state:screen-android'
|
||||
implementation project(":features:directory")
|
||||
implementation project(":features:login")
|
||||
implementation project(":features:settings")
|
||||
implementation project(":features:profile")
|
||||
implementation project(":domains:android:compose-core")
|
||||
implementation project(':domains:store')
|
||||
implementation 'screen-state:screen-android'
|
||||
implementation project(":core")
|
||||
implementation project(":design-library")
|
||||
implementation libs.compose.coil
|
||||
|
||||
kotlinTest(it)
|
||||
|
||||
testImplementation 'screen-state:state-test'
|
||||
testImplementation 'chat-engine:chat-engine-test'
|
||||
androidImportFixturesWorkaround(project, project(":core"))
|
||||
androidImportFixturesWorkaround(project, project(":domains:android:stub"))
|
||||
}
|
|
@ -5,7 +5,7 @@ import app.dapk.st.core.ProvidableModule
|
|||
import app.dapk.st.directory.DirectoryModule
|
||||
import app.dapk.st.domain.StoreModule
|
||||
import app.dapk.st.engine.ChatEngine
|
||||
import app.dapk.st.home.state.createHomeReducer
|
||||
import app.dapk.st.home.state.homeReducer
|
||||
import app.dapk.st.login.LoginModule
|
||||
import app.dapk.st.profile.ProfileModule
|
||||
import app.dapk.st.state.State
|
||||
|
@ -39,7 +39,7 @@ class HomeModule(
|
|||
}
|
||||
|
||||
private fun homeReducerFactory(eventEmitter: suspend (Any) -> Unit) =
|
||||
createHomeReducer(chatEngine, storeModule.cacheCleaner(), betaVersionUpgradeUseCase, JobBag(), eventEmitter)
|
||||
homeReducer(chatEngine, storeModule.cacheCleaner(), betaVersionUpgradeUseCase, JobBag(), eventEmitter)
|
||||
}
|
||||
|
||||
typealias DynamicState = State<DynamicReducers, Any>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package app.dapk.st.home.state
|
||||
|
||||
import app.dapk.st.engine.Me
|
||||
import app.dapk.st.home.state.HomeScreenState.Page
|
||||
import app.dapk.state.Action
|
||||
|
||||
|
@ -12,7 +13,9 @@ sealed interface HomeAction : Action {
|
|||
object LoggedIn : HomeAction
|
||||
|
||||
data class ChangePage(val page: Page) : HomeAction
|
||||
data class ChangePageSideEffect(val page: Page) : HomeAction
|
||||
data class UpdateInvitesCount(val invitesCount: Int) : HomeAction
|
||||
data class UpdateToSignedIn(val me: Me) : HomeAction
|
||||
data class UpdateState(val state: HomeScreenState) : HomeAction
|
||||
object InitialHome : HomeAction
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import app.dapk.state.*
|
|||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
|
||||
fun createHomeReducer(
|
||||
fun homeReducer(
|
||||
chatEngine: ChatEngine,
|
||||
cacheCleaner: StoreCleaner,
|
||||
betaVersionUpgradeUseCase: BetaVersionUpgradeUseCase,
|
||||
|
@ -25,6 +25,15 @@ fun createHomeReducer(
|
|||
action.state
|
||||
},
|
||||
|
||||
change(HomeAction.UpdateToSignedIn::class) { action, state ->
|
||||
val me = action.me
|
||||
when (state) {
|
||||
HomeScreenState.Loading -> HomeScreenState.SignedIn(HomeScreenState.Page.Directory, me, invites = 0)
|
||||
is HomeScreenState.SignedIn -> state.copy(me = me, invites = state.invites)
|
||||
HomeScreenState.SignedOut -> HomeScreenState.SignedIn(HomeScreenState.Page.Directory, me, invites = 0)
|
||||
}
|
||||
},
|
||||
|
||||
change(HomeAction.UpdateInvitesCount::class) { action, state ->
|
||||
when (state) {
|
||||
HomeScreenState.Loading -> state
|
||||
|
@ -37,7 +46,6 @@ fun createHomeReducer(
|
|||
if (chatEngine.isSignedIn()) {
|
||||
eventEmitter.invoke(HomeEvent.OnShowContent)
|
||||
dispatch(HomeAction.InitialHome)
|
||||
listenForInviteChanges(chatEngine, jobBag)
|
||||
} else {
|
||||
dispatch(HomeAction.UpdateState(HomeScreenState.SignedOut))
|
||||
}
|
||||
|
@ -45,18 +53,26 @@ fun createHomeReducer(
|
|||
|
||||
async(HomeAction.InitialHome::class) {
|
||||
val me = chatEngine.me(forceRefresh = false)
|
||||
val nextState = when (val current = getState()) {
|
||||
HomeScreenState.Loading -> HomeScreenState.SignedIn(HomeScreenState.Page.Directory, me, invites = 0)
|
||||
is HomeScreenState.SignedIn -> current.copy(me = me, invites = current.invites)
|
||||
HomeScreenState.SignedOut -> HomeScreenState.SignedIn(HomeScreenState.Page.Directory, me, invites = 0)
|
||||
}
|
||||
dispatch(HomeAction.UpdateState(nextState))
|
||||
dispatch(HomeAction.UpdateToSignedIn(me))
|
||||
listenForInviteChanges(chatEngine, jobBag)
|
||||
},
|
||||
|
||||
async(HomeAction.LoggedIn::class) {
|
||||
dispatch(HomeAction.InitialHome)
|
||||
eventEmitter.invoke(HomeEvent.OnShowContent)
|
||||
listenForInviteChanges(chatEngine, jobBag)
|
||||
},
|
||||
|
||||
async(HomeAction.ChangePageSideEffect::class) { action ->
|
||||
when (action.page) {
|
||||
HomeScreenState.Page.Directory -> {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
HomeScreenState.Page.Profile -> {
|
||||
dispatch(ComponentLifecycle.OnGone)
|
||||
dispatch(ProfileAction.Reset)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
multi(HomeAction.ChangePage::class) { action ->
|
||||
|
@ -64,38 +80,30 @@ fun createHomeReducer(
|
|||
when (state) {
|
||||
is HomeScreenState.SignedIn -> when (action.page) {
|
||||
state.page -> state
|
||||
else -> state.copy(page = action.page).also {
|
||||
async {
|
||||
when (action.page) {
|
||||
HomeScreenState.Page.Directory -> {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
HomeScreenState.Page.Profile -> {
|
||||
dispatch(ComponentLifecycle.OnGone)
|
||||
dispatch(ProfileAction.Reset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> state.copy(page = action.page)
|
||||
}
|
||||
|
||||
HomeScreenState.Loading -> state
|
||||
HomeScreenState.SignedOut -> state
|
||||
}
|
||||
}
|
||||
async {
|
||||
val state = getState()
|
||||
if (state is HomeScreenState.SignedIn && state.page != action.page) {
|
||||
dispatch(HomeAction.ChangePageSideEffect(action.page))
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async(HomeAction.ScrollToTop::class) {
|
||||
dispatch(DirectorySideEffect.ScrollToTop)
|
||||
},
|
||||
|
||||
|
||||
sideEffect(HomeAction.ClearCache::class) { _, _ ->
|
||||
cacheCleaner.cleanCache(removeCredentials = false)
|
||||
betaVersionUpgradeUseCase.notifyUpgraded()
|
||||
eventEmitter.invoke(HomeEvent.Relaunch)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
@ -144,7 +144,6 @@ internal fun settingsReducer(
|
|||
}
|
||||
|
||||
Ignored -> {
|
||||
nothing()
|
||||
}
|
||||
|
||||
ToggleDynamicTheme -> async {
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 9abb6b4418f451d81f09c4ba2b26f2b1ffd19f55
|
||||
Subproject commit d596949ac2b923b02da55ddd78e2e26dc46af82a
|
Loading…
Reference in New Issue