lots of changes and reducing dependency imports
This commit is contained in:
@@ -68,7 +68,7 @@ func ListIssues(w http.ResponseWriter, r *http.Request) {
|
||||
app := App(r)
|
||||
hx := HTMX(r)
|
||||
|
||||
issues, err := app.Issues.AllIssues(r.Context())
|
||||
issues, err := app.Issues.SearchIssues(r.Context(), "", models.IssueFilter{})
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to retrieve issues", http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -1,29 +1,55 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/web/components"
|
||||
"github.com/a-h/templ"
|
||||
"github.com/donseba/go-htmx"
|
||||
)
|
||||
|
||||
var taskFeedback task.ValidationFeedback
|
||||
type ValidationFeedback = models.ValidationFeedback
|
||||
|
||||
func SetTaskFeedback(feedback task.ValidationFeedback) {
|
||||
var taskFeedback ValidationFeedback
|
||||
|
||||
func SetTaskFeedback(feedback ValidationFeedback) {
|
||||
taskFeedback = feedback
|
||||
}
|
||||
|
||||
func HandleTaskStatus(w http.ResponseWriter, r *http.Request) {
|
||||
hx := HTMX(r)
|
||||
|
||||
if hx.IsHxRequest() {
|
||||
if taskFeedback.Success {
|
||||
hx.WriteString("<div>Task completed successfully!</div>")
|
||||
} else {
|
||||
hx.WriteString("<div>" + taskFeedback.Message + "</div>")
|
||||
}
|
||||
hx.WriteString(`<a hx-get="/status/modal" hx-target="#modal-container" hx-swap="innerHTML">` + taskFeedback.Message + `</a>`)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
hx.WriteJSON(taskFeedback)
|
||||
}
|
||||
|
||||
func HandleTaskStatusModal(w http.ResponseWriter, r *http.Request) {
|
||||
err := components.Modal(components.ModalProps{
|
||||
ID: "task-status-modal",
|
||||
Title: "Task Status",
|
||||
Content: feedbackList(HTMX(r), taskFeedback),
|
||||
Open: true,
|
||||
}).Render(r.Context(), w)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func feedbackList(hx *htmx.Handler, feedback ValidationFeedback) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, w io.Writer) error {
|
||||
for _, check := range feedback.Checks {
|
||||
if !check.Valid {
|
||||
hx.WriteString(`<p class="my-2 text-red-500">` + check.Message + `</p>`)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user