-
-
Notifications
You must be signed in to change notification settings - Fork 467
search: update exploration logic and UI empty states #438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a61d618
9469214
a081208
14cda9a
b6829fc
62e0728
78c41f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,6 @@ import zed.rainxch.githubstore.core.presentation.res.failed_to_share_link | |
| import zed.rainxch.githubstore.core.presentation.res.link_copied_to_clipboard | ||
| import zed.rainxch.githubstore.core.presentation.res.no_github_link_in_clipboard | ||
| import zed.rainxch.githubstore.core.presentation.res.explore_error | ||
| import zed.rainxch.githubstore.core.presentation.res.no_repositories_found | ||
| import zed.rainxch.githubstore.core.presentation.res.search_failed | ||
| import zed.rainxch.search.presentation.mappers.toDomain | ||
| import zed.rainxch.search.presentation.utils.isEntirelyGithubUrls | ||
|
|
@@ -66,6 +65,8 @@ class SearchViewModel( | |
| private var explorePage = 1 | ||
| private var lastExploreQuery = "" | ||
|
|
||
| private val exploreLog = logger.withTag("SearchExplore") | ||
|
|
||
| companion object { | ||
| private const val MIN_QUERY_LENGTH = 3 | ||
| } | ||
|
|
@@ -295,7 +296,12 @@ class SearchViewModel( | |
| currentPage = 1 | ||
| explorePage = 1 | ||
| lastExploreQuery = query | ||
| _state.update { it.copy(exploreStatus = SearchState.ExploreStatus.IDLE) } | ||
| _state.update { | ||
| it.copy( | ||
| exploreStatus = SearchState.ExploreStatus.IDLE, | ||
| passthroughAttempted = null, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| currentSearchJob = | ||
|
|
@@ -312,6 +318,8 @@ class SearchViewModel( | |
| it.repositories | ||
| }, | ||
| totalCount = if (isInitial) null else it.totalCount, | ||
| passthroughAttempted = | ||
| if (isInitial) null else it.passthroughAttempted, | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -390,12 +398,8 @@ class SearchViewModel( | |
| repositories = allRepos, | ||
| hasMorePages = paginatedRepos.hasMore, | ||
| totalCount = allRepos.size, | ||
| errorMessage = | ||
| if (allRepos.isEmpty() && !paginatedRepos.hasMore) { | ||
| getString(Res.string.no_repositories_found) | ||
| } else { | ||
| null | ||
| }, | ||
| errorMessage = null, | ||
| passthroughAttempted = paginatedRepos.passthroughAttempted, | ||
| ) | ||
| } | ||
| } | ||
|
|
@@ -682,10 +686,27 @@ class SearchViewModel( | |
|
|
||
| private fun performExplore() { | ||
| val query = _state.value.query.trim() | ||
| if (query.isBlank() || _state.value.exploreStatus == SearchState.ExploreStatus.LOADING) return | ||
| val platformUi = _state.value.selectedSearchPlatform | ||
| val prevStatus = _state.value.exploreStatus | ||
|
|
||
| exploreLog.debug( | ||
| "click: query='$query' platform=$platformUi " + | ||
| "page=$explorePage lastQuery='$lastExploreQuery' status=$prevStatus", | ||
| ) | ||
|
|
||
| if (query.isBlank()) { | ||
| exploreLog.debug("skipped: query is blank") | ||
| return | ||
| } | ||
| if (prevStatus == SearchState.ExploreStatus.LOADING) { | ||
| exploreLog.debug("skipped: already LOADING") | ||
| return | ||
| } | ||
|
|
||
| // Reset page if query changed | ||
| if (query != lastExploreQuery) { | ||
| exploreLog.debug( | ||
| "query changed ('$lastExploreQuery' -> '$query'); resetting page to 1", | ||
| ) | ||
| explorePage = 1 | ||
| lastExploreQuery = query | ||
| } | ||
|
|
@@ -696,24 +717,40 @@ class SearchViewModel( | |
| try { | ||
| val exploreResult = searchRepository.exploreFromGithub( | ||
| query = query, | ||
| platform = _state.value.selectedSearchPlatform.toDomain(), | ||
| platform = platformUi.toDomain(), | ||
| page = explorePage, | ||
| ) | ||
| val existingCount = _state.value.repositories.size | ||
| exploreLog.debug( | ||
| "response: items=${exploreResult.repos.size} " + | ||
| "returnedPage=${exploreResult.page} hasMore=${exploreResult.hasMore} " + | ||
| "existingVisible=$existingCount", | ||
| ) | ||
|
|
||
| if (exploreResult.repos.isEmpty() || !exploreResult.hasMore) { | ||
| if (exploreResult.repos.isNotEmpty()) { | ||
| appendExploreResults(exploreResult.repos) | ||
| } | ||
| _state.update { it.copy(exploreStatus = SearchState.ExploreStatus.EXHAUSTED) } | ||
| } else { | ||
| val before = _state.value.repositories.size | ||
| if (exploreResult.repos.isNotEmpty()) { | ||
| appendExploreResults(exploreResult.repos) | ||
| } | ||
| val added = _state.value.repositories.size - before | ||
| val dupes = exploreResult.repos.size - added | ||
|
|
||
| if (exploreResult.hasMore) { | ||
| explorePage++ | ||
| exploreLog.debug( | ||
| "-> IDLE: appended=$added dupes=$dupes nextPage=$explorePage", | ||
| ) | ||
| _state.update { it.copy(exploreStatus = SearchState.ExploreStatus.IDLE) } | ||
| } else { | ||
| exploreLog.debug( | ||
| "-> EXHAUSTED: appended=$added dupes=$dupes " + | ||
| "rawItems=${exploreResult.repos.size}", | ||
| ) | ||
| _state.update { it.copy(exploreStatus = SearchState.ExploreStatus.EXHAUSTED) } | ||
| } | ||
|
Comment on lines
+730
to
749
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Edge case: empty If the backend returns Consider either capping consecutive empty-but-has-more responses (similar to 🤖 Prompt for AI Agents |
||
| } catch (e: CancellationException) { | ||
| throw e | ||
| } catch (e: Exception) { | ||
| logger.error("Explore failed: ${e.message}") | ||
| exploreLog.error("failed: ${e::class.simpleName}: ${e.message}", e) | ||
| _state.update { it.copy(exploreStatus = SearchState.ExploreStatus.IDLE) } | ||
| _events.send(SearchEvent.OnMessage(getString(Res.string.explore_error))) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider user-perceived delay for the 30s timeout.
The per-request timeout raises both
requestTimeoutMillisandsocketTimeoutMillisto 30s, which is 6× the client default of 5s. SincesearchExploreis only invoked from the user-triggeredexploreFromGithub→performExplore()flow (withgetOrThrow()and no retry), a slow/unreachable backend can keep the UI inExploreStatus.LOADINGfor up to 30 seconds with no way for the user to cancel from the UI. If the backend is expected to take this long, that's fine; otherwise consider tightening to ~10–15s and/or providing an explicit cancel affordance on the explore button.🤖 Prompt for AI Agents