Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meal plan with notes throws error #2

Closed
btoconnor opened this issue Mar 8, 2024 · 7 comments
Closed

Meal plan with notes throws error #2

btoconnor opened this issue Mar 8, 2024 · 7 comments
Labels
bug Something isn't working released

Comments

@btoconnor
Copy link
Contributor

Occasionally we make meal plans where some days just use the "Note" feature, rather than linking to a recipe. I created one on our current meal plan, and the MMM-MealieMenu module threw an error:

MMM-MealieMenu.js:279 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'name')
    at Class.formatMeals (MMM-MealieMenu.js:279:27)
    at Class.socketNotificationReceived (MMM-MealieMenu.js:172:49)
    at module.js:235:9
    at Socket.<anonymous> (socketclient.js:38:4)
    at Emitter.emit (index.mjs:136:20)
    at Socket.emitEvent (socket.js:498:20)
    at Socket.onevent (socket.js:485:18)
    at MMSocket.socket.onevent (socketclient.js:32:11)
    at Socket.onpacket (socket.js:455:22)
    at Emitter.emit (index.mjs:136:20)

It looks like this function is assuming all of the entries will be linked recipes.

These can be added in mealie by toggling the "Note Only" flag:
image

@btoconnor
Copy link
Contributor Author

It looks like this can be fixed by checking if meal.recipe exists before pulling in the name and the photo.

This diff makes it so there is no longer an error:

diff --git a/MMM-MealieMenu.js b/MMM-MealieMenu.js
index 2a5fac5..cc82c71 100644
--- a/MMM-MealieMenu.js
+++ b/MMM-MealieMenu.js
@@ -276,11 +276,11 @@ Module.register("MMM-MealieMenu", {
     const formatted = [];
     for (const meal of meals) {
       formatted.push({
-        name: meal.recipe.name,
+        name: meal.recipe ? meal.recipe.name : meal.title,
         rawDate: meal.date,
         date: moment(meal.date).format(this.config.dateFormat),
         meal: this.typeToMealDisplay(meal.entryType),
-        photoUrl: `${this.config.host}/api/media/recipes/${meal.recipe.id}/images/min-original.webp`,
+        photoUrl: meal.recipe ? `${this.config.host}/api/media/recipes/${meal.recipe.id}/images/min-original.webp` : '',
         isToday: today.isSame(meal.date),
         shouldFade: this.config.fadePriorEntries && today.isAfter(meal.date)
       });

However, I think it might be nice to have a default image in case the recipe or the note doesn't have a picture. I can open up a PR for this if you'd like, but wouldn't know what to do for the image.

@zanix
Copy link
Owner

zanix commented Mar 8, 2024

It looks like this function is assuming all of the entries will be linked recipes.

Yep, that is true. I have not used the "Note only" option in quite some time and I forgot it exists.

However, I think it might be nice to have a default image in case the recipe or the note doesn't have a picture. I can open up a PR for this if you'd like, but wouldn't know what to do for the image.

Maybe using the Mealie icon would work? I could also add a defaultImage option so it can be overridden. I also need to check if the meal.recipe.image field is blank when the recipe doesn't have an image. I would want to use a default image in those cases too.

@btoconnor
Copy link
Contributor Author

The Mealie icon makes sense to me - I only got a brief chance to look but it seemed like it was an SVG, at least on the meal plan page. Not sure if that's true and / or how easy that would be to pull into this project.

I took a quick look and tested the module with a recipe that doesn't have an image, and the module here with my hotfix shows a broken image (not too surprising):
image

BTW - thanks for releasing this module. I am in the process of migrating to MagicMirror, specifically so that I could get access to custom data for the Mealie meal plan. I thought I'd have to make the module myself, but this does exactly what I wanted.

@zanix
Copy link
Owner

zanix commented Mar 8, 2024

The Mealie icon makes sense to me - I only got a brief chance to look but it seemed like it was an SVG, at least on the meal plan page. Not sure if that's true and / or how easy that would be to pull into this project.

I'm planning on including a PNG version with an orange background and white icon, which is how it looks in the header of Mealie.

mealie

I will also add the defaultImage configuration option so it can be changed to anything else.

BTW - thanks for releasing this module. I am in the process of migrating to MagicMirror, specifically so that I could get access to custom data for the Mealie meal plan. I thought I'd have to make the module myself, but this does exactly what I wanted.

Thanks! I previously used Paprika and the MMM-PaprikaMenu module, but then I switched to Mealie and needed this module.

I should be able to update the code later today.
If you have any other suggestions for improving this module, let me know.

@zanix
Copy link
Owner

zanix commented Mar 9, 2024

The meal plan notes issue is fixed in fdfe249

I'll get the defaultImage setting added tomorrow.

@btoconnor
Copy link
Contributor Author

Fix works for me, thanks!

@zanix zanix added the bug Something isn't working label Mar 10, 2024
@zanix zanix closed this as completed in 131752e Mar 10, 2024
zanix added a commit that referenced this issue Mar 10, 2024
- Meal plan notes in the meal plan don't result in an error

Fixes #2
zanix added a commit that referenced this issue Mar 10, 2024
- Add default photo when a photo is not available for a meal plan
- Default photo is the Mealie icon
- Add `defaultPicture` option to change the image
- Add recipe description or meal note, default is hidden
- Add `showDescription` to toggle the description
- Wrap meal name to single line

Closes #2
zanix added a commit that referenced this issue Mar 10, 2024
- Add default photo when a photo is not available for a meal plan
- Default photo is the Mealie icon
- Add `defaultPicture` option to change the image
- Add recipe description or meal note, default is hidden
- Add `showDescription` to toggle the description
- Wrap meal name to single line

Closes #2
zanix added a commit that referenced this issue Mar 10, 2024
- Add default photo when a photo is not available for a meal plan
- Default photo is the Mealie icon
- Add `defaultPicture` option to change the image
- Add recipe description or meal note, default is hidden
- Add `showDescription` to toggle the description
- Wrap meal name to single line

Closes #2
zanix added a commit that referenced this issue Mar 10, 2024
- Add default photo when a photo is not available for a meal plan
- Default photo is the Mealie icon
- Add `defaultPicture` option to change the image
- Add recipe description or meal note, default is hidden
- Add `showDescription` to toggle the description
- Wrap meal name to single line

Closes #2
zanix added a commit that referenced this issue Mar 10, 2024
- Add default photo when a photo is not available for a meal plan
- Default photo is the Mealie icon
- Add `defaultPicture` option to change the image
- Add recipe description or meal note, default is hidden
- Add `showDescription` to toggle the description
- Wrap meal name to single line

Closes #2
github-actions bot pushed a commit that referenced this issue Mar 10, 2024
# [1.2.0](v1.1.1...v1.2.0) (2024-03-10)

### Features

* add default picture, add meal description, fix meal name wrap ([2b2983b](2b2983b)), closes [#2](#2)
Copy link

🎉 This issue has been resolved in version 1.2.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

No branches or pull requests

2 participants