Michael Thomson 6f7bcc9503
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/dryrun Pipeline was successful
ci/woodpecker/push/publish-tag Pipeline was successful
ci/woodpecker/push/publish-latest Pipeline was successful
postgres and such
2024-06-17 23:37:43 -04:00

24 lines
737 B
Plaintext

package partials
import "michaelthomson.dev/mthomson/go-todos-app/models"
import "fmt"
func todoId(todo models.Todo) string {
return "todo-" + todo.Id.String()
}
func patchUrl(todo models.Todo) string {
if todo.Done {
return string(templ.URL(fmt.Sprintf("/todos/%s/undone", todo.Id)))
}
return string(templ.URL(fmt.Sprintf("/todos/%s/done", todo.Id)))
}
templ Todo(todo models.Todo) {
<div id={ todoId(todo) }>
{ todo.Name }
<button hx-delete={ string(templ.URL(fmt.Sprintf("/todos/%s", todo.Id))) } hx-target={ "#" + todoId(todo) } hx-swap="delete">Delete</button>
<input type="checkbox" checked?={ todo.Done } hx-target={ "#" + todoId(todo) } hx-patch={ patchUrl(todo) } hx-swap="outerHTML" />
</div>
}