feat(templates): add error page and toast components

Add standalone error page template for graceful error display when the
main app fails. Includes inline CSS since error pages must work when
CSS fails to load. Add error toast component for displaying errors.
This commit is contained in:
2026-02-20 13:25:35 -05:00
parent 572f71218b
commit 79fcfa38f0
4 changed files with 234 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
// Code generated by templ - DO NOT EDIT.
// templ: version: v0.3.977
package templates
//lint:file-ignore SA4006 This context is only used if a nested component is present.
import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime"
func ErrorToast(message string) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
if templ_7745c5c3_Var1 == nil {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
if message != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<script>\n\t\t\tdocument.addEventListener('DOMContentLoaded', function() {\n\t\t\t\t// Show error toast with 8 second auto-dismiss\n\t\t\t\twindow.showToast.error('{ message }', 8000);\n\n\t\t\t\t// Add retry button to the toast\n\t\t\t\tsetTimeout(function() {\n\t\t\t\t\tconst toastContainer = document.getElementById('toast-container');\n\t\t\t\t\tif (toastContainer && toastContainer.lastElementChild) {\n\t\t\t\t\t\tconst toast = toastContainer.lastElementChild;\n\t\t\t\t\t\tconst retryBtn = document.createElement('button');\n\t\t\t\t\t\tretryBtn.className = 'ml-4 px-3 py-1 bg-white/20 hover:bg-white/30 rounded text-sm font-medium transition-colors';\n\t\t\t\t\t\tretryBtn.textContent = 'Retry';\n\t\t\t\t\t\tretryBtn.onclick = function() {\n\t\t\t\t\t\t\twindow.location.reload();\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\t// Insert before the close button\n\t\t\t\t\t\tconst closeBtn = toast.querySelector('.toast-close');\n\t\t\t\t\t\tif (closeBtn) {\n\t\t\t\t\t\t\tcloseBtn.parentElement.insertBefore(retryBtn, closeBtn);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\ttoast.appendChild(retryBtn);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}, 100);\n\t\t\t});\n\t\t</script>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
return nil
})
}
var _ = templruntime.GeneratedTemplate