Skip to content

Commit 2e8b089

Browse files
committed
fix tab not being refresh after login
1 parent 35ca766 commit 2e8b089

File tree

4 files changed

+55
-60
lines changed

4 files changed

+55
-60
lines changed

compose-ui/src/commonMain/kotlin/dev/dimension/flare/ui/presenter/HomeTabsPresenter.kt

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ import dev.dimension.flare.ui.presenter.home.NotificationBadgePresenter
2121
import kotlinx.collections.immutable.ImmutableList
2222
import kotlinx.collections.immutable.persistentListOf
2323
import kotlinx.collections.immutable.toImmutableList
24-
import kotlinx.coroutines.flow.catch
2524
import kotlinx.coroutines.flow.combine
26-
import kotlinx.coroutines.flow.distinctUntilChanged
2725
import kotlinx.coroutines.flow.distinctUntilChangedBy
2826
import org.koin.core.component.KoinComponent
2927
import org.koin.core.component.inject
@@ -58,56 +56,56 @@ public class HomeTabsPresenter :
5856

5957
private val settingsRepository by inject<SettingsRepository>()
6058
private val accountRepository by inject<AccountRepository>()
61-
private val activeAccountFlow by lazy {
62-
combine(
63-
activeAccountFlow(accountRepository),
64-
settingsRepository.tabSettings.distinctUntilChangedBy { it.secondaryItems },
65-
) { account, tabsState ->
66-
println("Active account changed: $account, tabsState: $tabsState")
67-
val secondary =
68-
tabsState.secondaryItems ?: TimelineTabItem.defaultSecondary(account)
69-
State.HomeTabState(
70-
primary =
71-
TimelineTabItem.default
72-
.map {
73-
HomeTabItem(it)
74-
}.toImmutableList(),
75-
secondary =
76-
secondary
77-
.map {
78-
HomeTabItem(it)
79-
}.toImmutableList(),
80-
extraProfileRoute =
81-
HomeTabItem(
82-
tabItem =
83-
ProfileTabItem(
84-
accountKey = account.accountKey,
85-
userKey = account.accountKey,
59+
private val tabsFlow by lazy {
60+
activeAccountFlow(accountRepository)
61+
.combine(
62+
settingsRepository.tabSettings.distinctUntilChangedBy { it.secondaryItems },
63+
) { account, tabsState ->
64+
println("Active account changed: $account, tabsState: $tabsState")
65+
if (account == null) {
66+
State.HomeTabState(
67+
primary =
68+
TimelineTabItem.guest
69+
.map {
70+
HomeTabItem(it)
71+
}.toImmutableList(),
72+
secondary = persistentListOf(),
73+
extraProfileRoute = null,
74+
secondaryIconOnly = true,
75+
)
76+
} else {
77+
val secondary =
78+
tabsState.secondaryItems ?: TimelineTabItem.defaultSecondary(account)
79+
State.HomeTabState(
80+
primary =
81+
TimelineTabItem.default
82+
.map {
83+
HomeTabItem(it)
84+
}.toImmutableList(),
85+
secondary =
86+
secondary
87+
.map {
88+
HomeTabItem(it)
89+
}.toImmutableList(),
90+
extraProfileRoute =
91+
HomeTabItem(
92+
tabItem =
93+
ProfileTabItem(
94+
accountKey = account.accountKey,
95+
userKey = account.accountKey,
96+
),
8697
),
87-
),
88-
secondaryIconOnly = tabsState.secondaryItems == null,
89-
)
90-
}.catch {
91-
emit(
92-
State.HomeTabState(
93-
primary =
94-
TimelineTabItem.guest
95-
.map {
96-
HomeTabItem(it)
97-
}.toImmutableList(),
98-
secondary = persistentListOf(),
99-
extraProfileRoute = null,
100-
secondaryIconOnly = true,
101-
),
102-
)
103-
}.distinctUntilChanged()
98+
secondaryIconOnly = tabsState.secondaryItems == null,
99+
)
100+
}
101+
}
104102
}
105103

106104
@Composable
107105
override fun body(): State {
108106
val tabs =
109-
remember(activeAccountFlow) {
110-
activeAccountFlow
107+
remember(tabsFlow) {
108+
tabsFlow
111109
}.collectAsUiState().value.map {
112110
it.copy(
113111
primary =

compose-ui/src/commonMain/kotlin/dev/dimension/flare/ui/presenter/HomeTimelineWithTabsPresenter.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import dev.dimension.flare.ui.presenter.home.UserState
1919
import dev.dimension.flare.ui.presenter.settings.AccountEventPresenter
2020
import kotlinx.collections.immutable.ImmutableList
2121
import kotlinx.collections.immutable.toImmutableList
22-
import kotlinx.coroutines.flow.distinctUntilChanged
2322
import kotlinx.coroutines.flow.distinctUntilChangedBy
2423
import kotlinx.coroutines.flow.map
2524
import org.koin.core.component.KoinComponent
@@ -35,6 +34,10 @@ public class HomeTimelineWithTabsPresenter(
3534
public val tabState: UiState<ImmutableList<TimelineTabItem>>
3635
}
3736

37+
init {
38+
println("HomeTimelineWithTabsPresenter: accountType=$accountType")
39+
}
40+
3841
private val tabsState by lazy {
3942
settingsRepository.tabSettings
4043
.distinctUntilChangedBy { it.mainTabs + it.enableMixedTimeline }
@@ -62,8 +65,7 @@ public class HomeTimelineWithTabsPresenter(
6265
)
6366
}
6467
}
65-
}.distinctUntilChanged()
66-
.map {
68+
}.map {
6769
it.toImmutableList()
6870
}
6971
}
@@ -143,10 +145,8 @@ public class HomeTimelineWithTabsPresenter(
143145
// }.toImmutableList()
144146
// }
145147

146-
return remember(accountState, tabs) {
147-
object : State, UserState by accountState {
148-
override val tabState = tabs
149-
}
148+
return object : State, UserState by accountState {
149+
override val tabState = tabs
150150
}
151151
}
152152
}

desktopApp/src/main/kotlin/dev/dimension/flare/App.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ import io.github.composefluent.component.Icon
8383
import io.github.composefluent.component.NavigationDefaults
8484
import io.github.composefluent.component.SubtleButton
8585
import io.github.composefluent.component.Text
86-
import io.ktor.http.Url
8786
import kotlinx.coroutines.launch
8887
import moe.tlaster.precompose.molecule.producePresenter
8988
import org.apache.commons.lang3.SystemUtils
@@ -98,7 +97,7 @@ internal fun WindowScope.FlareApp(onWindowRoute: (Route.WindowRoute) -> Unit) {
9897
val stackManager =
9998
rememberStackManager(
10099
startRoute = getRoute(tabs.primary.first().tabItem),
101-
key = tabs.all.size,
100+
key = tabs.all.joinToString { it.tabItem.key },
102101
topLevelRoutes = tabs.all.map { getRoute(it.tabItem) },
103102
)
104103

@@ -425,8 +424,6 @@ private class ProxyUriHandler(
425424
) : UriHandler {
426425
override fun openUri(uri: String) {
427426
if (uri.startsWith("flare://")) {
428-
val data = Url(uri)
429-
430427
Route.parse(uri)?.let {
431428
if (it is Route.WindowRoute) {
432429
onWindowRoute.invoke(it)

shared/src/commonMain/kotlin/dev/dimension/flare/data/repository/AccountRepository.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ internal fun accountServiceFlow(
222222
}
223223
}
224224

225-
public fun activeAccountFlow(repository: AccountRepository): Flow<UiAccount> =
225+
public fun activeAccountFlow(repository: AccountRepository): Flow<UiAccount?> =
226226
repository
227227
.activeAccount
228-
.map { it.takeSuccess() ?: throw NoActiveAccountException }
229-
.distinctUntilChangedBy { it.accountKey }
228+
.map { it.takeSuccess() }
229+
.distinctUntilChangedBy { it?.accountKey }
230230

231231
@Composable
232232
internal fun allAccountsPresenter(repository: AccountRepository): State<UiState<ImmutableList<UiAccount>>> =

0 commit comments

Comments
 (0)