Files
nebula/handlers/routes.go

41 lines
1.0 KiB
Go
Raw Normal View History

package handlers
import (
"net/http"
"strconv"
"nebula/views"
)
// RegisterRoutes sets up all HTTP routes for the application
func RegisterRoutes(mux *http.ServeMux) {
// Welcome page routes
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 only the step content fragment
views.WelcomeStepContent(step).Render(r.Context(), w)
return
}
// Full page render for non-HTMX requests
views.WelcomePage(step).Render(r.Context(), w)
}