postgres and such
This commit is contained in:
@@ -1,14 +1,23 @@
|
||||
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={ "/todos/" + todo.Id.String() } hx-target={ "#" + todoId(todo) } hx-swap="delete">Delete</button>
|
||||
<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>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user