diff --git a/internal/handlers/dashboard.go b/internal/handlers/dashboard.go index 7d0a626..895cb0f 100644 --- a/internal/handlers/dashboard.go +++ b/internal/handlers/dashboard.go @@ -2,10 +2,29 @@ package handlers import ( "html/template" + "log" "net/http" ) func DashboardHandler(w http.ResponseWriter, r *http.Request) { - tmpl := template.Must(template.ParseFiles("templates/layout.html", "templates/dashboard.html")) - tmpl.Execute(w, nil) + tmpl, err := template.ParseFiles( + "templates/layout.html", + "templates/dashboard.html", + "templates/partials/invoice_search.html", + "templates/partials/invoice_search_results.html", + ) + if err != nil { + log.Printf("Template parsing error: %v", err) + http.Error(w, "Internal Server Error", http.StatusInternalServerError) + return + } + + data := struct{}{} // Empty struct as data + + err = tmpl.ExecuteTemplate(w, "layout.html", data) + if err != nil { + log.Printf("Template execution error: %v", err) + http.Error(w, "Internal Server Error", http.StatusInternalServerError) + return + } } diff --git a/internal/handlers/jobs.go b/internal/handlers/jobs.go index b8aa276..6a08fc0 100644 --- a/internal/handlers/jobs.go +++ b/internal/handlers/jobs.go @@ -6,16 +6,18 @@ import ( ) func JobsHandler(w http.ResponseWriter, r *http.Request) { + jobs := []string{"Job 1", "Job 2", "Job 3"} // Replace with actual data fetching + if r.Header.Get("HX-Request") == "true" { - // This is an HTMX request, return only the jobs partial - tmpl := template.Must(template.ParseFiles("templates/partials/jobs.html")) - jobs := []string{"Job 1", "Job 2", "Job 3"} // Replace with actual data fetching - tmpl.Execute(w, jobs) + // This is an HTMX request, return the jobs content wrapped in the content template + tmpl := template.Must(template.ParseFiles("templates/layout.html", "templates/partials/jobs.html")) + tmpl.ExecuteTemplate(w, "content", map[string]interface{}{ + "Title": "Jobs", + "Jobs": jobs, + }) } else { // This is a full page request tmpl := template.Must(template.ParseFiles("templates/layout.html", "templates/partials/jobs.html")) - jobs := []string{"Job 1", "Job 2", "Job 3"} // Replace with actual data fetching - tmpl.Execute(w, map[string]interface{}{ "Title": "Jobs", "Jobs": jobs, diff --git a/templates/dashboard.html b/templates/dashboard.html index 3ab71ba..9ba99e6 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -4,12 +4,12 @@