Files
nebula/handlers/routes.go

39 lines
1002 B
Go

package handlers
import (
"net/http"
"strconv"
"nebula/views"
)
func RegisterRoutes(mux *http.ServeMux) {
mux.HandleFunc("GET /", handleWelcome)
mux.HandleFunc("GET /welcome", handleWelcome)
mux.HandleFunc("GET /welcome/step/{step}", handleWelcomeStep)
}
// handleWelcome renders the full welcome page at step 1
func handleWelcome(w http.ResponseWriter, r *http.Request) {
views.WelcomePage(1).Render(r.Context(), w)
}
// handleWelcomeStep handles HTMX partial updates for step navigation
func handleWelcomeStep(w http.ResponseWriter, r *http.Request) {
stepStr := r.PathValue("step")
step, err := strconv.Atoi(stepStr)
if err != nil || step < 1 || step > 3 {
step = 1
}
// Check if this is an HTMX request
if r.Header.Get("HX-Request") == "true" {
// Return step content with OOB stepper update (HTMX 4 pattern)
views.WelcomeStepWithStepper(step).Render(r.Context(), w)
return
}
// Full page render for non-HTMX requests
views.WelcomePage(step).Render(r.Context(), w)
}