mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 19:57:04 +05:30
refactor: hoist state out of UserProfile
Solves the issue of every pop of the backstack causing data to be re-fetched, but now has the issue of the data being stale for a few frames. Still better than the current state, so I'll take it.
This commit is contained in:
parent
5d65d1ea51
commit
0d3c08c10a
5 changed files with 76 additions and 34 deletions
|
@ -222,7 +222,6 @@ fun LobstersPostsScreen(
|
|||
) { dest ->
|
||||
UserProfile(
|
||||
username = dest.username,
|
||||
getProfile = viewModel::getUserProfile,
|
||||
contentPadding = contentPadding,
|
||||
openUserProfile = { clawBackStack.add(User(it)) },
|
||||
)
|
||||
|
|
|
@ -161,17 +161,6 @@ constructor(
|
|||
suspend fun getLinkMetadata(url: String) =
|
||||
withContext(ioDispatcher) { linkMetadataRepository.getLinkMetadata(url) }
|
||||
|
||||
suspend fun getUserProfile(username: String) =
|
||||
withContext(ioDispatcher) {
|
||||
when (val result = api.getUser(username)) {
|
||||
is Success -> result.value
|
||||
is Failure.NetworkFailure -> throw result.error
|
||||
is Failure.UnknownFailure -> throw result.error
|
||||
is Failure.HttpFailure -> throw result.toError()
|
||||
is Failure.ApiFailure -> throw IOException("API returned an invalid response")
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun importPosts(input: InputStream) = dataTransferRepository.importPosts(input)
|
||||
|
||||
suspend fun exportPostsAsJson(output: OutputStream) =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue