change web and status command to use callback

This commit is contained in:
Robin Olsen
2026-03-04 22:45:31 +01:00
parent cc6c4ea7cb
commit ae81e52f0d
3 changed files with 11 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
package components package components
templ Status() { templ Status() {
<div hx-get="/status" hx-trigger="load, every 1s" hx-target="#status" hx-swap="innerHTML"> <div hx-get="/status" hx-trigger="load, click" hx-target="#status" hx-swap="innerHTML">
<div id="status"></div> <div id="status"></div>
</div> </div>
} }

View File

@@ -29,7 +29,7 @@ func Status() templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent templ_7745c5c3_Var1 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<div hx-get=\"/status\" hx-trigger=\"load, every 1s\" hx-target=\"#status\" hx-swap=\"innerHTML\"><div id=\"status\"></div></div>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<div hx-get=\"/status\" hx-trigger=\"load, click\" hx-target=\"#status\" hx-swap=\"innerHTML\"><div id=\"status\"></div></div>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }

View File

@@ -22,6 +22,7 @@ type ValidationFeedback = models.ValidationFeedback
type Web struct { type Web struct {
feedbackChan chan ValidationFeedback feedbackChan chan ValidationFeedback
quitChan chan bool quitChan chan bool
submitChan chan<- struct{}
} }
func New() *Web { func New() *Web {
@@ -72,6 +73,10 @@ func (w *Web) Run(ctx context.Context, config Config) error {
}() }()
} }
if w.submitChan != nil {
handler.SetSubmitChan(w.submitChan)
}
select { select {
case <-w.quitChan: case <-w.quitChan:
fmt.Println("Task completed! Shutting down server...") fmt.Println("Task completed! Shutting down server...")
@@ -89,3 +94,7 @@ func (w *Web) SetChannels(feedbackChan chan ValidationFeedback, quitChan chan bo
w.feedbackChan = feedbackChan w.feedbackChan = feedbackChan
w.quitChan = quitChan w.quitChan = quitChan
} }
func (w *Web) SetSubmitChan(submitChan chan<- struct{}) {
w.submitChan = submitChan
}