Skip to content

Commit

Permalink
fix favorite icon update (closes #477)
Browse files Browse the repository at this point in the history
  • Loading branch information
doerfli committed Jun 15, 2024
1 parent 8291d33 commit 693b27d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions app/javascript/controllers/recipe_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { Utils } from "../src/utils"

export default class extends Controller {
static targets = ["deleteButtons",
"imagelg", "imagebox", "imagefulllink"
]
"imagelg", "imagebox", "imagefulllink",
"favoriteicon",
];

delete() {
var url = this.data.get("url");
Expand Down Expand Up @@ -46,9 +47,11 @@ export default class extends Controller {
},
}).then(function json(response) {
return response.json()
}).then(function(data) {
Turbolinks.visit(data.redirect_url);
});
// toggle heart icon
var favoriteIcon = this.favoriteiconTarget;
favoriteIcon.classList.toggle("far");
favoriteIcon.classList.toggle("fas");
}

imageLgShow(event) {
Expand Down
4 changes: 2 additions & 2 deletions app/views/recipes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@
<div class="bottomactions">
<button class="button" data-action="click->recipe#favorite">
<% if @recipe.favorite %>
<i class="fas fa-heart"></i>
<i class="fas fa-heart" data-recipe-target="favoriteicon"></i>
<% else %>
<i class="far fa-heart"></i>
<i class="far fa-heart" data-recipe-target="favoriteicon"></i>
<% end %>
</button>
<a href="<%= edit_recipe_path @recipe %>">
Expand Down

0 comments on commit 693b27d

Please sign in to comment.