jargons.dev
jargons.dev copied to clipboard
Limit `$recentSearches` State to Hold a Maximum of 5 Entries
Currently, the $recentSearches
state holds all the recent searches without any limit. To improve user experience and ensure that the list of recent searches remains manageable, we need to limit the $recentSearches
state to hold a maximum of 5 entries. When a new word is added and the limit is reached, the oldest entry should be removed to make space for the new one.
Current Implementation
The current implementation does not limit the number of recent searches stored. It can be found at https://github.com/devjargons/jargons.dev/blob/main/src/lib/stores/search.js
Task
Modify the $addToRecentSearchesFn
function to ensure that the $recentSearches
state holds a maximum of 5 entries. If the limit is reached, remove the oldest entry before adding a new one.
Implementation Steps
- Check the number of entries in the
$recentSearches
state. - If the number of entries is 5 or more, remove the oldest entry.
- Add the new entry to the
$recentSearches
state. - Update the local storage with the modified state.
Acceptance Criteria
- The
$recentSearches
state should hold a maximum of 5 entries. - When a new entry is added and the limit is reached, the oldest entry should be removed.
- The local storage should be updated accordingly.
Additional Information
- This enhancement will be implemented in the
lib/stores/search.js
file where the$addToRecentSearchesFn
function is defined.