-
Notifications
You must be signed in to change notification settings - Fork 189
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
[issue 1630] Triggering search via URL #1657
Conversation
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.
Thanks for starting on this. A few things:
- update the title of your PR so it addresses both the issue number and also provides a sentence about what it fixes. See other PRs for examples
- the logic for managing this state needs to be fixed. In the original Gatsby version we do this:
// We synchronize the `text` and `filter` values to the URL's query string
// via `textParam` and `filterParam`. The <SearchBar> UI uses our internal
// state values, and the <SearchResults> only update on page load or when
// the user submits the form.
const [textParam = '', setTextParam] = useQueryParam('text', StringParam);
const [filterParam = 'post', setFilterParam] = useQueryParam('filter', StringParam);
// We manage the state of `text` and `filter` internally, and update URL on
// form submit only. These are used in the <SearchBar>, and the user can change them.
const [text, setText] = useState(textParam);
const [filter, setFilter] = useState(filterParam);
// Form was submitted, so go ahead and sync to URL, (re)triggering search.
function onSubmitHandler(event) {
event.preventDefault();
setTextParam(text);
setFilterParam(filter);
}
The "state" of the filter/text params doesn't need to be in React, it's in the URL. We just need to read it out, and use it as a local variable. So we should be pulling this from router.query
and syncing it back when we do router.push(...)
the new URL (which will update the state on the URL).
Thank you. I just wasn't sure to use |
We have to use the next |
Welcome! Please also add a description and add which issue this fixes under "Issue This PR Addresses" (you can simply say |
@humphd I have followed your request, searching through URL is now working. |
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.
Awesome. Testing this with https://deploy-preview-1657--telescope-next.netlify.app/search?text=react&filter=post I notice that it works if you do it in the app, but try copy/pasting that URL into a new window, and the initial values being passed down to the input box on props aren't being set on first render.
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.
@DukeManh You're going to need to rebase this. Please do so ASAP so we can get this merged in.
Issue This PR Addresses
Fixes #1630
Type of Change
Description
Checklist