jargons.dev icon indicating copy to clipboard operation
jargons.dev copied to clipboard

Limit `$recentSearches` State to Hold a Maximum of 5 Entries

Open babblebey opened this issue 9 months ago • 0 comments

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

  1. Check the number of entries in the $recentSearches state.
  2. If the number of entries is 5 or more, remove the oldest entry.
  3. Add the new entry to the $recentSearches state.
  4. 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.

babblebey avatar May 24 '24 15:05 babblebey