go-recipe-book/pkg/web/tpl/pages/IngredientsIndex.templ
Alessio 10cc9342b1
Some checks failed
Build / release (push) Blocked by required conditions
Build / build (push) Has been cancelled
Add beginning of web package
2024-11-18 16:25:39 -08:00

44 lines
1.1 KiB
Plaintext

package pages
import (
"fmt"
. "recipe_book/pkg/db"
)
templ IngredientsIndex(foods []Food) {
<h1>Ingredients</h1>
<dialog id="newIngredientDialog">
<h3>Create new ingredient</h3>
<form hx-post="/ingredients" hx-ext="json-enc" hx-target="body" hx-push-url="true">
<label for="name">Name</label>
<input name="name" />
<input type="submit" value="Create" />
</form>
<button onclick="newIngredientDialog.close()">Cancel</button>
</dialog>
<button class=".new-item-button" onclick="newIngredientDialog.showModal()">New Ingredient</button>
<table>
<thead>
<th>Name</th>
<th>Cals</th>
<th>Carbs</th>
<th>Protein</th>
<th>Fat</th>
<th>Sugar</th>
</thead>
<tbody>
for _, f := range foods {
<tr>
<td><a href={ templ.URL(fmt.Sprintf("/ingredients/%d", f.ID)) } hx-boost="true">{ f.Name }</a></td>
<td>{ fmt.Sprint(f.Cals) }</td>
<td>{ fmt.Sprint(f.Carbs) }</td>
<td>{ fmt.Sprint(f.Protein) }</td>
<td>{ fmt.Sprint(f.Fat) }</td>
<td>{ fmt.Sprint(f.Sugar) }</td>
</tr>
}
</tbody>
</table>
}