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:
Harsh Shandilya 2025-05-26 19:02:37 +05:30
parent 5d65d1ea51
commit 0d3c08c10a
5 changed files with 76 additions and 34 deletions

View file

@ -222,7 +222,6 @@ fun LobstersPostsScreen(
) { dest ->
UserProfile(
username = dest.username,
getProfile = viewModel::getUserProfile,
contentPadding = contentPadding,
openUserProfile = { clawBackStack.add(User(it)) },
)

View file

@ -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) =