[web] Add to MessageSearchContext results related information
Summary:
issue: https://linear.app/comm/issue/ENG-4163/add-results-and-position-to-message-search-context
We want to remember the results the user has fetched until they change/clear the query. We want to be able to close and reopen the modal, and see those results.
We need to remember endReached so that when the user scrolls to the bottom, and they had already fetched all messages, they don't query the server again.
query was changed to getQuery because:
If the user searches for something, closes the modal and reopens it, we want to show them the results they have previously fetched. We only want the client to call the server, if the user presses the "Search" button, or scrolls to the bottom.
When the "Search" button is pressed, we first have to set the query via setQuery function provided by this context. Only once the query is set, we want to call the server. In class react we could pass a callback to setState, but we cannot
do it in functional react. So to be able to set the query and call the server with its correct value, we will keep the query in a ref. This allows us to change the query without having to wait for the next rerender. So for the calling code to
always have the current query, we need to give it a getter.
This solution was disscussed with @tomek.
Test Plan: Checked that the context state changes as expected when supplied functions are called
Reviewers: kamil, kuba, michal
Reviewed By: michal
Subscribers: ashoat, tomek
Differential Revision: https://phab.comm.dev/D8293