mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-11 13:29:12 +00:00
* refactor: move database, navigator scripts to state package * feat: add Schema config for dwn * test: add unit tests for InitializeDatabase * feat: use templated index.html for the DWN frontend * feat: introduce templ generation for templ * chore(deps): update devbox.json to use latest packages * chore: update devbox to use bun * feat: introduce dwn config generation * feat: add motr.mjs for vault management * refactor: move front end from to (alert) * feat: implement devbox integration and devbox-based process management * feat: embed motr.mjs script for offline demo * refactor: embed motr.mjs data in embed.go * chore: update workflows to use actions/checkout@v4 * refactor: move process-compose.yaml to deploy directory * refactor: remove unnecessary JSON conversion
42 lines
879 B
Go
42 lines
879 B
Go
package islands
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/a-h/templ"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
func echoFormResponse(c echo.Context, cmp templ.Component, state FormState) error {
|
|
// Create a buffer to store the rendered HTML
|
|
buf := &bytes.Buffer{}
|
|
// Render the component to the buffer
|
|
err := cmp.Render(c.Request().Context(), buf)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Set the content type
|
|
c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)
|
|
c.Response().Header().Set("X-Status", string(state))
|
|
|
|
// Write the buffered content to the response
|
|
_, err = c.Response().Write(buf.Bytes())
|
|
return err
|
|
}
|
|
|
|
type FormState string
|
|
|
|
const (
|
|
InitialForm FormState = "initial"
|
|
ErrorForm FormState = "error"
|
|
SuccessForm FormState = "success"
|
|
WarningForm FormState = "warning"
|
|
)
|
|
|
|
type Form struct {
|
|
State FormState
|
|
Title string
|
|
Description string
|
|
}
|