evansloan / collectionlog.net

MIT License
17 stars 5 forks source link

feat(Header): introduce check in typeahead cache before navigating #54

Closed Napokue closed 1 year ago

Napokue commented 1 year ago

As discussed in #53 a possible way to prevent a user to navigate to a collection log that does not exist.

Napokue commented 1 year ago

Thank you for pointing that out.

It was a little too ambitious of me to think that such a naïve implementation would suffice. I have revisited it and also used your feedback to come up with another, more complex solution that will solve the issue and even minimize the API requests more.

What I did come up with was to introduce the following:

Please let me know what you think of this implementation and if it is something we want.

Napokue commented 1 year ago

Great, thanks for pointing out those two points.

One character name search - Should probably fix

Agreed, I was not aware of one character users. Only checked a-z. Will do a little testing for this, but should not be a problem to change.

Typeahead cache doesn't reset if selecting all characters in search box and immediately typing a new username

Good point! I have not considered that usecase. Is not too hard to fix, we could probably implement a check that checks if the first character of the "new" search query is equal to the first character of the old search query.

Napokue commented 1 year ago

After coming back after a couple of days I was able to view this issue from another perspective and simplified my initial rather complex proposal with a much (in my opinion) better implementation.

I also took the time to optimize the filterTypeahead function, it will not filter through the whole cache now to only get the first 5 results. Worst case scenario, it will iterate through the whole cache if the last 5 elements are matching the filter.