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

Improve Search Functionality #172

Merged
merged 24 commits into from
May 24, 2022

Conversation

TiagooGomess
Copy link
Contributor

@TiagooGomess TiagooGomess commented Feb 11, 2022

2022-02-14.19-15-39.mp4

Closes #79

@TiagooGomess TiagooGomess added this to the MVP milestone Feb 11, 2022
@TiagooGomess TiagooGomess self-assigned this Feb 11, 2022
@TiagooGomess TiagooGomess force-pushed the feature/improve-search-functionality branch 3 times, most recently from 6127cb8 to 7c6dd69 Compare February 14, 2022 18:36
@TiagooGomess TiagooGomess force-pushed the feature/improve-search-functionality branch from 5428133 to 5ba7b6c Compare February 22, 2022 19:38
@TiagooGomess TiagooGomess force-pushed the feature/improve-search-functionality branch from 6cc22a6 to 879a332 Compare March 24, 2022 19:30
@TiagooGomess
Copy link
Contributor Author

The only thing missing is the implementation of new tests.

Copy link
Collaborator

@imnotteixeira imnotteixeira left a comment

Choose a reason for hiding this comment

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

I still have to review the whole system (the refetching and all) just checked some high level stuff

@TiagooGomess TiagooGomess force-pushed the feature/improve-search-functionality branch 3 times, most recently from ed7664d to c12ecd1 Compare March 26, 2022 19:39
Comment on lines +25 to +37
// The "search" and "loadMoreOffers" functions do not share the same state;
// When we run "setHasMoreOffers(false)" on the "loadMoreOffers" function,
// the "search" function does not know that the "hasMoreOffers" variable has changed;
// In the same way, when we run "setHasMoreOffers(true) on the "search" function,
// the "loadMoreOffers" function does not know that the "hasMoreOffers" variable has changed;
// Then, when the "loadMoreOffers" function is executed after a previous execution where the
// "hasMoreOffers" variable became "false", the state of this variable is still false, which
// prevents the fetching of new offers.
// Knowing that, I needed a way to set the "hasMoreOffers" variable to "true" when the previous fact
// happens: setting the "hasMoreOffers" to true when the "queryToken" (which is stored in redux) changes
useEffect(() => {
setHasMoreOffers(true);
}, [searchQueryToken]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@imnotteixeira I found out that we have a bug when we fetch all the offers of a search and then do another search. What do you think of this way to solve that?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have a solution, but I'm not sure you're going to like it...

Maybe it's time to go full-hook and ditch redux for search functionality.

The main idea is: the HomePage Controller (might need to create it) will start storing the search state by calling the search hook. The search hook will be modified to hold the state and export the setters of each filter and the search value etc. Then it will expose the search and loadMore functions, as it does currently. It will additionally hold the results array, and errors and loading state, etc... like the redux state currently has.

Then SearchArea and SearchResultsWidget components can both access the HomePage context which will have these methods/data accessible, and most importantly common to both. There can only be 1 search at any given time, which is what we want. Components that currently use the redux state for search can easily call useContext(HomePageContext) and retrieve whatever they need, no need to pass props around, no connect components to redux.

I'm not sure if we will only ever have the search on the homepage. Maybe some day we will want to keep the search state while the student goes through other pages (viewing offers, adding them to his personal track-list, dunno) and keep the results in a sort-of cart that they can quickly get back to. But for now this is good enough, no need to handle the context above for it to be accessed in other pages.

Copy link
Contributor Author

@TiagooGomess TiagooGomess Mar 28, 2022

Choose a reason for hiding this comment

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

I think it's a good solution

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@imnotteixeira That refactoring will take some time, mainly due to all the changes in the tests. What do you think of leaving this as it is now (because it works) and opening an issue for that?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@imnotteixeira I found out that we have a bug when we fetch all the offers of a search and then do another search. What do you think of this way to solve that?

Then is this a bug or not?

In any case, we should migrate in the future. Search is the next big system still not using hooks/context. Migrating will probably make it simpler. Create the issue and link it here please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was a bug, but I solved it using that useEffect, which uses the searchQueryToken from redux.

@TiagooGomess TiagooGomess force-pushed the feature/improve-search-functionality branch 2 times, most recently from 4dcd572 to cbf11ee Compare March 28, 2022 18:33
@TiagooGomess TiagooGomess linked an issue Apr 1, 2022 that may be closed by this pull request
@imnotteixeira
Copy link
Collaborator

Beware that search service is being changed here #217. Make sure the changes are migrated to this PR as well. Rebases can sometimes hide these changes and the merging goes wrong.

@TiagooGomess TiagooGomess force-pushed the feature/improve-search-functionality branch from cbf11ee to 1255f0f Compare April 6, 2022 18:01
@TiagooGomess TiagooGomess force-pushed the feature/improve-search-functionality branch 5 times, most recently from 892e91e to dc7e8ce Compare April 13, 2022 14:11
@TiagooGomess TiagooGomess force-pushed the feature/improve-search-functionality branch from 98405dd to ecb6b42 Compare April 20, 2022 20:15
@imnotteixeira imnotteixeira removed their request for review May 3, 2022 21:15
@DoStini DoStini requested a review from monkin77 May 11, 2022 16:09
Copy link
Contributor

@monkin77 monkin77 left a comment

Choose a reason for hiding this comment

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

Apart from the problem that was discussed and will be solved in another issue, this looks great! I don't have my PC to run this locally but from the video and code review it's 💯.

@TiagooGomess
Copy link
Contributor Author

@imnotteixeira Sorry to bother you, but since you requested changes in this PR, we need your review so that this PR is ready for merging.

Copy link
Collaborator

@imnotteixeira imnotteixeira left a comment

Choose a reason for hiding this comment

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

I can't really review currently, so I'll approve since there is already another approval to avoid blocking

@TiagooGomess TiagooGomess merged commit 0458ebc into develop May 24, 2022
@TiagooGomess TiagooGomess deleted the feature/improve-search-functionality branch May 24, 2022 18:23
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.

Migrate HomePage state from redux to hooks/context Improve search functionality
3 participants