Merge remote-tracking branch 'origin/main' into LPM-48
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/web/components"
|
||||
@@ -13,15 +14,27 @@ import (
|
||||
type ValidationFeedback = models.ValidationFeedback
|
||||
|
||||
var taskFeedback ValidationFeedback
|
||||
var submitChan chan<- struct{}
|
||||
|
||||
func SetTaskFeedback(feedback ValidationFeedback) {
|
||||
taskFeedback = feedback
|
||||
}
|
||||
|
||||
func SetSubmitChan(ch chan<- struct{}) {
|
||||
submitChan = ch
|
||||
}
|
||||
|
||||
func HandleTaskStatus(w http.ResponseWriter, r *http.Request) {
|
||||
submitChan <- struct{}{}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
hx := HTMX(r)
|
||||
if hx.IsHxRequest() {
|
||||
hx.WriteString(`<a hx-get="/status/modal" hx-target="#modal-container" hx-swap="innerHTML">` + taskFeedback.Message + `</a>`)
|
||||
hx.WriteString(`
|
||||
<div id="status" type="button" hx-get="/status" hx-target="#status" hx-swap="outerHTML">
|
||||
<button class="btn btn-error btn-sm" hx-get="/status/modal" hx-target="#modal-container" hx-swap="innerHTML">` + taskFeedback.Message + `</button>
|
||||
</div>`)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -30,6 +43,7 @@ func HandleTaskStatus(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func HandleTaskStatusModal(w http.ResponseWriter, r *http.Request) {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
err := components.Modal(components.ModalProps{
|
||||
ID: "task-status-modal",
|
||||
Title: "Task Status",
|
||||
@@ -46,9 +60,12 @@ func feedbackList(feedback ValidationFeedback) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, w io.Writer) error {
|
||||
for _, check := range feedback.Checks {
|
||||
if !check.Valid {
|
||||
io.WriteString(w, `<p class="my-2 text-red-500">`+check.Message+`</p>`)
|
||||
io.WriteString(w, `<p class="my-2 text-sm">`+"❌ "+check.Message+`</p>`)
|
||||
} else {
|
||||
io.WriteString(w, `<p class="my-2 text-sm">`+"✅ "+check.Message+`</p>`)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user