db, handlers, and interfaces
This commit is contained in:
@@ -1,20 +1,22 @@
|
||||
package pages
|
||||
|
||||
import "michaelthomson.dev/mthomson/go-todos-app/templates/shared"
|
||||
import "michaelthomson.dev/mthomson/go-todos-app/db"
|
||||
import "michaelthomson.dev/mthomson/go-todos-app/templates/partials"
|
||||
import "michaelthomson.dev/mthomson/go-todos-app/models"
|
||||
|
||||
templ Home(todos []db.Todo) {
|
||||
templ Home(todos []models.Todo) {
|
||||
@shared.Page("Todos") {
|
||||
<div class="text-xl">Todos</div>
|
||||
<form hx-post="/todos" hx-target="#todos" hx-swap="beforeend">
|
||||
<input name="name" type="text" />
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
<div id="todos">
|
||||
<div class="flex content-center items-center flex-col">
|
||||
<h1 class="text-3xl">Todos</h1>
|
||||
<form hx-post="/todos" hx-target="#todos" hx-swap="beforeend">
|
||||
<input name="name" type="text" class="border border-black" />
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
<div id="todos">
|
||||
for _, todo := range todos {
|
||||
@partials.Todo(todo)
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@ import "io"
|
||||
import "bytes"
|
||||
|
||||
import "michaelthomson.dev/mthomson/go-todos-app/templates/shared"
|
||||
import "michaelthomson.dev/mthomson/go-todos-app/db"
|
||||
import "michaelthomson.dev/mthomson/go-todos-app/templates/partials"
|
||||
import "michaelthomson.dev/mthomson/go-todos-app/models"
|
||||
|
||||
func Home(todos []db.Todo) templ.Component {
|
||||
func Home(todos []models.Todo) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
@@ -33,7 +33,7 @@ func Home(todos []db.Todo) templ.Component {
|
||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"text-xl\">Todos</div><form hx-post=\"/todos\" hx-target=\"#todos\" hx-swap=\"beforeend\"><input name=\"name\" type=\"text\"> <button type=\"submit\">Submit</button></form><div id=\"todos\">")
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"flex content-center items-center flex-col\"><h1 class=\"text-3xl\">Todos</h1><form hx-post=\"/todos\" hx-target=\"#todos\" hx-swap=\"beforeend\"><input name=\"name\" type=\"text\" class=\"border border-black\"> <button type=\"submit\">Submit</button></form><div id=\"todos\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
@@ -43,7 +43,7 @@ func Home(todos []db.Todo) templ.Component {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div>")
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div></div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package partials
|
||||
|
||||
import "michaelthomson.dev/mthomson/go-todos-app/db"
|
||||
import "michaelthomson.dev/mthomson/go-todos-app/models"
|
||||
|
||||
func todoId(todo db.Todo) string {
|
||||
func todoId(todo models.Todo) string {
|
||||
return "todo-" + todo.Id.String()
|
||||
}
|
||||
|
||||
templ Todo(todo db.Todo) {
|
||||
templ Todo(todo models.Todo) {
|
||||
<div id={ todoId(todo) }>
|
||||
{ todo.Id.String() }: { todo.Name }
|
||||
{ todo.Name }
|
||||
<button hx-delete={ "/todos/" + todo.Id.String() } hx-target={ "#" + todoId(todo) } hx-swap="delete">Delete</button>
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ import "context"
|
||||
import "io"
|
||||
import "bytes"
|
||||
|
||||
import "michaelthomson.dev/mthomson/go-todos-app/db"
|
||||
import "michaelthomson.dev/mthomson/go-todos-app/models"
|
||||
|
||||
func todoId(todo db.Todo) string {
|
||||
func todoId(todo models.Todo) string {
|
||||
return "todo-" + todo.Id.String()
|
||||
}
|
||||
|
||||
func Todo(todo db.Todo) templ.Component {
|
||||
func Todo(todo models.Todo) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
@@ -47,37 +47,24 @@ func Todo(todo db.Todo) templ.Component {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var3 string
|
||||
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(todo.Id.String())
|
||||
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(todo.Name)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/partials/todo.templ`, Line: 11, Col: 22}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/partials/todo.templ`, Line: 11, Col: 15}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(": ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var4 string
|
||||
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(todo.Name)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/partials/todo.templ`, Line: 11, Col: 37}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" <button hx-delete=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var5 string
|
||||
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs("/todos/" + todo.Id.String())
|
||||
var templ_7745c5c3_Var4 string
|
||||
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs("/todos/" + todo.Id.String())
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/partials/todo.templ`, Line: 12, Col: 52}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
@@ -85,12 +72,12 @@ func Todo(todo db.Todo) templ.Component {
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var6 string
|
||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs("#" + todoId(todo))
|
||||
var templ_7745c5c3_Var5 string
|
||||
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs("#" + todoId(todo))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/partials/todo.templ`, Line: 12, Col: 85}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user