Skip to content

Commit 1fc2b81

Browse files
committed
refactor: fetch discovery platform from tweaks in HomeViewModel
- Update repository loading logic to retrieve the discovery platform preference from `tweaksRepository` instead of relying solely on the UI state. - Use `async`/`await` to fetch the platform preference from the repository concurrently during the loading process. - Ensure the discovery platform is persisted via `tweaksRepository` when a new platform is explicitly selected. - Add necessary import for `kotlinx.coroutines.async`.
1 parent d51eaa1 commit 1fc2b81

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

  • feature/home/presentation/src/commonMain/kotlin/zed/rainxch/home/presentation

feature/home/presentation/src/commonMain/kotlin/zed/rainxch/home/presentation/HomeViewModel.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import kotlinx.collections.immutable.persistentListOf
66
import kotlinx.collections.immutable.toImmutableList
77
import kotlinx.coroutines.CancellationException
88
import kotlinx.coroutines.Job
9+
import kotlinx.coroutines.async
910
import kotlinx.coroutines.channels.Channel
1011
import kotlinx.coroutines.flow.MutableStateFlow
1112
import kotlinx.coroutines.flow.SharingStarted
@@ -153,13 +154,18 @@ class HomeViewModel(
153154
}
154155

155156
val targetCategory = category ?: _state.value.currentCategory
156-
val targetPlatform = platform ?: _state.value.currentPlatform
157+
val targetPlatformDeffered =
158+
viewModelScope.async {
159+
tweaksRepository.getDiscoveryPlatform().first()
160+
}
157161
val targetTopic = if (topicExplicitlySet) topic else _state.value.selectedTopic
158162

159163
logger.debug("Loading repos: category=$targetCategory, topic=$targetTopic, page=$nextPageIndex, isInitial=$isInitial")
160164

161165
return viewModelScope
162166
.launch {
167+
val targetPlatform = platform ?: targetPlatformDeffered.await()
168+
163169
if (platform != null) {
164170
tweaksRepository.setDiscoveryPlatform(targetPlatform)
165171
}

0 commit comments

Comments
 (0)