mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-17 23:47:02 +05:30
app: tweak first load behavior
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
bd5647f4c7
commit
b7dc92d85a
1 changed files with 7 additions and 4 deletions
|
@ -24,16 +24,19 @@ class LobstersViewModel @ViewModelInject constructor(
|
|||
private val coroutineExceptionHandler = CoroutineExceptionHandler { _, throwable ->
|
||||
when (throwable) {
|
||||
// Swallow known network errors that can be recovered from.
|
||||
is UnknownHostException, is SocketTimeoutException -> {}
|
||||
is UnknownHostException, is SocketTimeoutException -> {
|
||||
if (_posts.value.isEmpty()) {
|
||||
viewModelScope.launch {
|
||||
dao.loadPosts().collectLatest { _posts.value = it }
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> throw throwable
|
||||
}
|
||||
}
|
||||
val posts: StateFlow<List<LobstersPost>> get() = _posts
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
dao.loadPosts().collectLatest { _posts.value = it }
|
||||
}
|
||||
getMorePostsInternal(true)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue