dmitri.shuralyov.com/app/changes

Add common.State parameter to BodyTop function.

This helps it render contextual information,
e.g., that depends on the current ChangeID.

Pass it directly rather than via a context value because this is
simpler and can be easily done since this is an unfrozen API.

Related to https://github.com/shurcooL/issuesapp/commit/e746af07544c3c630e745be0872f267cb1cec21e.
dmitshur committed 6 years ago commit 53c36d040fb401864f46823156802282401d6662
Showing partial commit. Full Commit
Collapse all
main.go
@@ -95,11 +95,11 @@ type Options struct {

	HeadPre, HeadPost template.HTML
	BodyPre           string // An html/template definition of "body-pre" template.

	// BodyTop provides components to include on top of <body> of page rendered for req. It can be nil.
	BodyTop func(req *http.Request) ([]htmlg.Component, error)
	BodyTop func(*http.Request, common.State) ([]htmlg.Component, error)
}

// handler handles all requests to changesapp. It acts like a request multiplexer,
// choosing from various endpoints and parsing the repository ID from URL.
type handler struct {
@@ -509,11 +509,11 @@ func (h *handler) state(req *http.Request, changeID uint64) (state, error) {
		},
	}
	b.HeadPre = h.HeadPre
	b.HeadPost = h.HeadPost
	if h.BodyTop != nil {
		c, err := h.BodyTop(req)
		c, err := h.BodyTop(req, b.State)
		if err != nil {
			return state{}, err
		}
		var buf bytes.Buffer
		err = htmlg.RenderComponents(&buf, c...)