Skip to content

Extract shared food dialog automation logic#31

Merged
milldr merged 2 commits into
milldr:mainfrom
NilsLeo:refactor/food-dialog-shared-logic
May 22, 2026
Merged

Extract shared food dialog automation logic#31
milldr merged 2 commits into
milldr:mainfrom
NilsLeo:refactor/food-dialog-shared-logic

Conversation

@NilsLeo

@NilsLeo NilsLeo commented May 21, 2026

Copy link
Copy Markdown
Contributor

Consolidates the repetitive "Add Food to Diary" dialog automation from quick-add, log-food, and add-custom-food into a shared buildFoodDialogCode() helper in src/kernel/food-dialog.ts.

The same ~200-line dialog flow (right-click meal, search, select result, set serving size, click "Add to Diary") appeared in 3 modules with minor variations. This refactor:

  • Creates configurable buildFoodDialogCode() with options for:
    • Variable names (foodName, mealLabel, servingCount, etc.)
    • Error message prefixes
    • Conditional serving size updates
    • Dialog dismissal verification
  • Reduces code duplication by ~500 lines
  • Improves maintainability for future dialog-related changes
  • Updates tests to verify shared logic behavior

No functional changes - all existing commands work identically.

🤖 Generated with Claude Code

NilsLeo and others added 2 commits May 21, 2026 13:51
Consolidates the repetitive "Add Food to Diary" dialog automation from
quick-add, log-food, and add-custom-food into a shared buildFoodDialogCode()
helper in src/kernel/food-dialog.ts.

The same ~200-line dialog flow (right-click meal, search, select result,
set serving size, click "Add to Diary") appeared in 3 modules with minor
variations. This refactor:

- Creates configurable buildFoodDialogCode() with options for:
  - Variable names (foodName, mealLabel, servingCount, etc.)
  - Error message prefixes
  - Conditional serving size updates
  - Dialog dismissal verification
- Reduces code duplication by ~500 lines
- Improves maintainability for future dialog-related changes
- Updates tests to verify shared logic behavior

No functional changes - all existing commands work identically.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Increase wait after saving custom food from 1s to 15s to allow indexing
- Increase wait after search results appear from 500ms to 2s
- Replace Playwright locator filter with page.evaluate() for reliable "Add to Diary" button clicking in GWT context

These changes ensure newly created custom foods are findable in search and that the Add to Diary button is reliably clicked.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@milldr

milldr commented May 22, 2026

Copy link
Copy Markdown
Owner

lgtm! ty

@milldr milldr merged commit 2cee015 into milldr:main May 22, 2026
3 checks passed
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.

2 participants