Skip to content

feat(nutrition): persist ingredient search filters to localStorage#1211

Merged
rolandgeider merged 2 commits intowger-project:masterfrom
sputnik-mac:fix/persist-ingredient-search-filters
Mar 17, 2026
Merged

feat(nutrition): persist ingredient search filters to localStorage#1211
rolandgeider merged 2 commits intowger-project:masterfrom
sputnik-mac:fix/persist-ingredient-search-filters

Conversation

@sputnik-mac
Copy link
Copy Markdown
Contributor

Summary

Fixes #1210

The ingredient search filters (language, vegan, vegetarian) were reset on every page load. This PR saves them to localStorage and restores them on mount.

Changes

IngredientAutcompleter.tsx

  • Initialize languageFilter, filterVegan, and filterVegetarian from localStorage (with appropriate defaults if not set)
  • Add three useEffect hooks to persist each filter value to localStorage whenever it changes

Behavior

  • Users who prefer vegan/vegetarian filters will find them already checked when they return
  • The language filter preference is remembered across sessions
  • First-time users still get the sensible defaults (language-aware for the language filter, false for vegan/vegetarian)
  • The existing logic that resets current_englishcurrent when the UI language is English still works correctly

Testing

Manually verified:

  1. Set filters (e.g. vegan=true, language=all)
  2. Reload the page
  3. Filters are restored correctly

Save and restore languageFilter, filterVegan, and filterVegetarian
across page reloads using localStorage, so users who commonly search
for vegan/vegetarian items or prefer a specific language filter don't
need to re-select the same options every session.

Closes wger-project#1210

Signed-off-by: Sputnik-MAC <sputnik.mac.001@gmail.com>
@rolandgeider
Copy link
Copy Markdown
Member

thanks for the PR!! Could you perhaps add some simple tests that check that the values are saved to local storage?

@rolandgeider rolandgeider merged commit 85a5dbc into wger-project:master Mar 17, 2026
5 checks passed
@rolandgeider
Copy link
Copy Markdown
Member

merged thanks!

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.

Save ingredient search filters

2 participants