Skip to content

Fetch games on search view mount and reset search state on input clear#3080

Merged
zurdi15 merged 2 commits intomasterfrom
feat/show-first-search
Mar 7, 2026
Merged

Fetch games on search view mount and reset search state on input clear#3080
zurdi15 merged 2 commits intomasterfrom
feat/show-first-search

Conversation

@zurdi15
Copy link
Copy Markdown
Member

@zurdi15 zurdi15 commented Mar 7, 2026

Description
Explain the changes or enhancements you are proposing with this pull request.
Trigger fetchRoms on search view mount and reset search state on input clear

Checklist
Please check all that apply.

  • I've tested the changes locally
  • I've updated relevant comments
  • I've assigned reviewers for this PR
  • I've added unit tests that cover the changes

Screenshots (if applicable)

@zurdi15 zurdi15 requested a review from gantoine March 7, 2026 15:48
@zurdi15 zurdi15 self-assigned this Mar 7, 2026
Copilot AI review requested due to automatic review settings March 7, 2026 15:48
@zurdi15 zurdi15 changed the title Trigger fetchRoms on search view mount and reset search state on input clear Fetch games on search view mount and reset search state on input clear Mar 7, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the gallery search flow so the Search view initiates a ROM fetch on mount, and clearing the search input triggers a search reset/update.

Changes:

  • Trigger an initial ROM fetch when Gallery/Search.vue mounts.
  • When clearing the search input, reset related search state and emit a filterRoms event to refresh results.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
frontend/src/views/Gallery/Search.vue Fetch ROMs on mount (currently uses await fetchRoms() in the mounted hook).
frontend/src/components/Gallery/AppBar/Search/SearchTextField.vue On clear, resets searchTerm, sets initialSearch, and emits filterRoms to refresh the gallery.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 128 to 131
onMounted(async () => {
scrolledToTop.value = true;
await fetchRoms();
});
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await fetchRoms() doesn't currently await the underlying request because fetchRoms() doesn't return the romsStore.fetchRoms() Promise (it returns void after attaching a .catch). Either remove the await here, or refactor fetchRoms() to return/await romsStore.fetchRoms() so callers (mounted hook, infinite scroll, LoadMoreBtn) can reliably wait for completion and handle errors consistently.

Copilot uses AI. Check for mistakes.

function clearInput() {
searchTerm.value = null;
initialSearch.value = true;
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clearInput() sets initialSearch.value = true, but Search.vue uses initialSearch to choose between the pre-search prompt (<EmptySearch /> when !initialSearch) and the post-search empty-results state (<EmptyGame /> when initialSearch). With this change, clearing the input will keep the UI in the post-search state; if the goal is to reset the search state on clear, initialSearch should likely be set back to false here.

Suggested change
initialSearch.value = true;
initialSearch.value = false;

Copilot uses AI. Check for mistakes.
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 7, 2026

Greptile Summary

This PR makes two focused improvements to the Search gallery view: it triggers fetchRoms() on Search.vue mount (so the gallery is populated immediately on navigation), and it fully resets search state (initialSearch = false + a filterRoms event emission) when the user clears the search input in SearchTextField.vue.

Key changes:

  • Search.vueonMounted now calls fetchRoms(), relying on the fact that the child SearchTextField.vue always runs its onMounted first (calling resetGallery() / romsStore.reset()), guaranteeing a clean state before the fetch fires.
  • SearchTextField.vueclearInput() now emits "filterRoms", null (as all other filter-change paths already do), which causes FilterDrawer/Base.vue's debounced onFilterChange to reset pagination and call romsStore.fetchRoms(false). It also explicitly sets initialSearch = false, ensuring the template correctly shows <EmptySearch> (rather than <EmptyGame>) when the search box is empty and no results are present.
  • Clearing the input no longer silently leaves the gallery in a stale state — the gallery now re-fetches with no search term, showing all available roms (or <EmptySearch> if there are none).

Confidence Score: 5/5

  • This PR is safe to merge — changes are minimal, well-scoped, and consistent with existing patterns in the codebase.
  • Both changes are small and follow established patterns. The mount-time fetch relies on Vue's guaranteed child-before-parent onMounted ordering, so romsStore.reset() always runs before the fetch. The clearInput additions match how every other filter-change path in the codebase works (emit filterRomsonFilterChange debounce → fetchRoms(false)). No new state paths, no risk of double-fetching (the null guard in SearchTextField.fetchRoms prevents the @update:model-value next-tick call from firing after clear). No regressions identified.
  • No files require special attention.

Sequence Diagram

sequenceDiagram
    participant User
    participant Search.vue
    participant SearchTextField.vue
    participant FilterDrawer
    participant romsStore

    Note over Search.vue, SearchTextField.vue: View Mount
    SearchTextField.vue->>romsStore: reset() [child onMounted first]
    Search.vue->>romsStore: fetchRoms() [parent onMounted after]
    romsStore-->>Search.vue: roms loaded

    Note over User, romsStore: User types in search box
    User->>SearchTextField.vue: keyup.enter / model-value update
    SearchTextField.vue->>SearchTextField.vue: fetchRoms() — sets initialSearch=true
    SearchTextField.vue->>FilterDrawer: emit("filterRoms", null)
    FilterDrawer->>romsStore: resetPagination() + fetchRoms(false)
    romsStore-->>Search.vue: filtered roms loaded

    Note over User, romsStore: User clears the input
    User->>SearchTextField.vue: click:clear → clearInput()
    SearchTextField.vue->>SearchTextField.vue: searchTerm=null, initialSearch=false
    SearchTextField.vue->>FilterDrawer: emit("filterRoms", null)
    FilterDrawer->>romsStore: resetPagination() + fetchRoms(false)
    romsStore-->>Search.vue: all roms (no filter) loaded
Loading

Last reviewed commit: ea2532f

Copy link
Copy Markdown
Member

@gantoine gantoine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good after bot issues are addressed/ignored

@zurdi15 zurdi15 merged commit 527a45d into master Mar 7, 2026
6 checks passed
@zurdi15 zurdi15 deleted the feat/show-first-search branch March 7, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants