Skip to content
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

Autocomplete / onSubmit / QueryID #938

Closed
prestarocket opened this issue Apr 6, 2022 Discussed in #937 · 6 comments
Closed

Autocomplete / onSubmit / QueryID #938

prestarocket opened this issue Apr 6, 2022 Discussed in #937 · 6 comments

Comments

@prestarocket
Copy link

prestarocket commented Apr 6, 2022

Discussed in #937

Originally posted by prestarocket April 6, 2022
i use onSubmit event to redirect users to a new page with search results.
like :

onSubmit({ state }) {
                window.location.href = `${prestashop.urls.pages.search}?s=${state.query}`
            },

I can t find a way to pass QueryId in the new location.href.

@francoischalifour
Copy link
Member

Where's your QueryId coming from? Can you please provide a reproduction in this Autocomplete sandbox? Thanks

@prestarocket
Copy link
Author

@sarahdayan
Copy link
Member

sarahdayan commented Apr 6, 2022

Hey @prestarocket, what does the queryID you're mentioning referring to? Is it the Algolia queryID?

If yes, this information is available in the search response, but you need to enable clickAnalytics first in you getAlgoliaResults call. Than, you can use transformResponse to perform a side-effect once results are retrieved, and store the queryID in context. This will allow you to later access it from the state in onSubmit.

Here's a working example: https://codesandbox.io/s/vigorous-breeze-qvdtjo?file=/app.js

Does it work for you?

@alexbonhomme
Copy link

Hey!

Thx @sarahdayan for your reply!

Actually, we use fetchAlgoliaResults instead of getAlgoliaResults, so I've have kept your logic and called setContext in getItems instead.

It works very well 👌

See ya

@prestarocket
Copy link
Author

thx @sarahdayan !

@sarahdayan
Copy link
Member

@alexbonhomme I would recommend against using fetchAlgoliaResults, it's exported for internal usage but isn't part of the public API. We may change it in a breaking way in a minor or patch, which could break your implementation.

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

No branches or pull requests

4 participants