diff --git a/composeApp/src/commonMain/kotlin/band/effective/office/elevator/ui/profile/mainProfile/MainProfileComponent.kt b/composeApp/src/commonMain/kotlin/band/effective/office/elevator/ui/profile/mainProfile/MainProfileComponent.kt index bc999704561264f70e92e5c345001153e9c17fc8..f59f0576c5c15dc510eddd12a9320a3db3ff2873 100644 --- a/composeApp/src/commonMain/kotlin/band/effective/office/elevator/ui/profile/mainProfile/MainProfileComponent.kt +++ b/composeApp/src/commonMain/kotlin/band/effective/office/elevator/ui/profile/mainProfile/MainProfileComponent.kt @@ -3,6 +3,7 @@ package band.effective.office.elevator.ui.profile.mainProfile import band.effective.office.elevator.ui.profile.mainProfile.store.ProfileStore import band.effective.office.elevator.ui.profile.mainProfile.store.ProfileStoreFactory import com.arkivanov.decompose.ComponentContext +import com.arkivanov.essenty.lifecycle.doOnStart import com.arkivanov.mvikotlin.core.instancekeeper.getStore import com.arkivanov.mvikotlin.core.store.StoreFactory import com.arkivanov.mvikotlin.extensions.coroutines.labels @@ -24,6 +25,12 @@ class MainProfileComponent( ).create() } + init { + lifecycle.doOnStart { + profileStore.accept(ProfileStore.Intent.FetchUserInfo) + } + } + @OptIn(ExperimentalCoroutinesApi::class) val user: StateFlow = profileStore.stateFlow diff --git a/composeApp/src/commonMain/kotlin/band/effective/office/elevator/ui/profile/mainProfile/store/ProfileStore.kt b/composeApp/src/commonMain/kotlin/band/effective/office/elevator/ui/profile/mainProfile/store/ProfileStore.kt index 9e0ec647922bab1d1ff64f1175adcdadc7d6f22a..7a4fe33360c58ff4347a18fcb620a8a8346ce1d7 100644 --- a/composeApp/src/commonMain/kotlin/band/effective/office/elevator/ui/profile/mainProfile/store/ProfileStore.kt +++ b/composeApp/src/commonMain/kotlin/band/effective/office/elevator/ui/profile/mainProfile/store/ProfileStore.kt @@ -7,6 +7,7 @@ interface ProfileStore : Store by storeFactory.create( name = "ProfileStore", initialState = State(user = User.defaultUser), - bootstrapper = coroutineBootstrapper { - dispatch(Action.FetchUserInfo) - }, executorFactory = ::ExecutorImpl, reducer = ReducerImpl ) {} - private sealed interface Action { - object FetchUserInfo : Action - } - private sealed interface Msg { data class ProfileData(val user: User) : Msg } private inner class ExecutorImpl : - CoroutineExecutor() { + CoroutineExecutor() { override fun executeIntent(intent: Intent, getState: () -> State) { when (intent) { is Intent.SignOutClicked -> doSignOut() + Intent.FetchUserInfo -> fetchUserInfo() } } - private fun doSignOut() { authorizationUseCase.logout() publish(Label.OnSignedOut) } - override fun executeAction(action: Action, getState: () -> State) { - when (action) { - Action.FetchUserInfo -> fetchUserInfo() - } - } - private fun fetchUserInfo() { scope.launch(Dispatchers.IO) { getUserUseCase.execute().collect { user ->