Refactor favorite button: wrap in form for better HTMX and AntiForgeryToken support
This commit is contained in:
@@ -1,25 +1,26 @@
|
|||||||
@model Francesco.Recipes.World.Models.BackendModels.Recipe.Recipe
|
@model Francesco.Recipes.World.Models.BackendModels.Recipe.Recipe
|
||||||
|
|
||||||
<button class="btn btn-link p-0"
|
<form hx-post="@Url.Action(Model.IsFavorite ? "RemoveFavorite" : "AddFavorite", "Recipe")"
|
||||||
style="width: 40px; height: 40px;"
|
hx-target="this"
|
||||||
hx-post="@Url.Action(Model.IsFavorite ? "RemoveFavorite" : "AddFavorite", "Recipe")"
|
hx-swap="outerHTML">
|
||||||
hx-vals='{"recipeId": "@Model.Id"}'
|
@Html.AntiForgeryToken()
|
||||||
hx-target="this"
|
<input type="hidden" name="recipeId" value="@Model.Id" />
|
||||||
hx-swap="outerHTML">
|
<button type="submit" class="btn btn-link p-0" style="width: 40px; height: 40px;">
|
||||||
@if (Model.IsFavorite)
|
@if (Model.IsFavorite)
|
||||||
{
|
{
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="#FFD700">
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="#FFD700">
|
||||||
<path d="M12 17.27L18.18 21 16.54 13.97
|
<path d="M12 17.27L18.18 21 16.54 13.97
|
||||||
22 9.24l-7.19-.62L12 2 9.19 8.62
|
22 9.24l-7.19-.62L12 2 9.19 8.62
|
||||||
2 9.24l5.46 4.73L5.82 21z" />
|
2 9.24l5.46 4.73L5.82 21z" />
|
||||||
</svg>
|
</svg>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#999" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#999" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
<path d="M12 17.27L18.18 21 16.54 13.97
|
<path d="M12 17.27L18.18 21 16.54 13.97
|
||||||
22 9.24l-7.19-.62L12 2 9.19 8.62
|
22 9.24l-7.19-.62L12 2 9.19 8.62
|
||||||
2 9.24l5.46 4.73L5.82 21z" />
|
2 9.24l5.46 4.73L5.82 21z" />
|
||||||
</svg>
|
</svg>
|
||||||
}
|
}
|
||||||
</button>
|
</button>
|
||||||
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user