mirror of
https://github.com/samsonjs/retrogit.git
synced 2026-03-25 09:25:49 +00:00
Reduce code duplication for rendering of flash messages.
This commit is contained in:
parent
8aa6b897e2
commit
a52ea5d09c
5 changed files with 17 additions and 20 deletions
|
|
@ -204,7 +204,10 @@ type Template struct {
|
|||
*template.Template
|
||||
}
|
||||
|
||||
func (t *Template) Render(w io.Writer, data interface{}) *AppError {
|
||||
func (t *Template) Render(w io.Writer, data map[string]interface{}, state ...*AppSignedInState) *AppError {
|
||||
if len(state) > 0 {
|
||||
data["Flashes"] = state[0].Flashes()
|
||||
}
|
||||
err := t.Execute(w, data)
|
||||
if err != nil {
|
||||
return &AppError{
|
||||
|
|
|
|||
|
|
@ -144,17 +144,18 @@ func indexHandler(w http.ResponseWriter, r *http.Request) *AppError {
|
|||
"RepositoryCount": repositoryCount,
|
||||
"EmailAddress": emailAddress,
|
||||
}
|
||||
flashes := session.Flashes()
|
||||
if len(flashes) > 0 {
|
||||
session.Save(r, w)
|
||||
}
|
||||
var data = map[string]interface{}{
|
||||
"User": user,
|
||||
"SettingsSummary": settingsSummary,
|
||||
"DetectTimezone": !account.HasTimezoneSet,
|
||||
"Flashes": flashes,
|
||||
}
|
||||
return templates["index"].Render(w, data)
|
||||
return templates["index"].Render(w, data, &AppSignedInState{
|
||||
Account: account,
|
||||
GitHubClient: githubClient,
|
||||
session: session,
|
||||
responseWriter: w,
|
||||
request: r,
|
||||
})
|
||||
}
|
||||
|
||||
func signInHandler(w http.ResponseWriter, r *http.Request) *AppError {
|
||||
|
|
@ -196,7 +197,7 @@ func viewDigestHandler(w http.ResponseWriter, r *http.Request, state *AppSignedI
|
|||
var data = map[string]interface{}{
|
||||
"Digest": digest,
|
||||
}
|
||||
return templates["digest-page"].Render(w, data)
|
||||
return templates["digest-page"].Render(w, data, state)
|
||||
}
|
||||
|
||||
func sendDigestHandler(w http.ResponseWriter, r *http.Request, state *AppSignedInState) *AppError {
|
||||
|
|
@ -360,8 +361,6 @@ func settingsHandler(w http.ResponseWriter, r *http.Request, state *AppSignedInS
|
|||
return GitHubFetchError(err, "emails")
|
||||
}
|
||||
|
||||
flashes := state.Flashes()
|
||||
|
||||
var data = map[string]interface{}{
|
||||
"Account": state.Account,
|
||||
"User": user,
|
||||
|
|
@ -369,9 +368,8 @@ func settingsHandler(w http.ResponseWriter, r *http.Request, state *AppSignedInS
|
|||
"Repos": repos,
|
||||
"EmailAddresses": emailAddresses,
|
||||
"AccountEmailAddress": accountEmailAddress,
|
||||
"Flashes": flashes,
|
||||
}
|
||||
return templates["settings"].Render(w, data)
|
||||
return templates["settings"].Render(w, data, state)
|
||||
}
|
||||
|
||||
func saveSettingsHandler(w http.ResponseWriter, r *http.Request, state *AppSignedInState) *AppError {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@
|
|||
<div class="body">
|
||||
<h1>{{template "title" .}}</h1>
|
||||
|
||||
{{range .Flashes}}
|
||||
{{template "flash" .}}
|
||||
{{end}}
|
||||
|
||||
{{template "body" .}}
|
||||
</div>
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -2,10 +2,6 @@
|
|||
|
||||
{{define "body"}}
|
||||
|
||||
{{range .Flashes}}
|
||||
{{template "flash" .}}
|
||||
{{end}}
|
||||
|
||||
<div class="blurb">
|
||||
You're signed in as
|
||||
{{template "user" .User}}
|
||||
|
|
|
|||
|
|
@ -15,10 +15,6 @@
|
|||
|
||||
<script src="/static/settings.js"></script>
|
||||
|
||||
{{range .Flashes}}
|
||||
{{template "flash" .}}
|
||||
{{end}}
|
||||
|
||||
<form method="POST" action="{{routeUrl "save-settings"}}">
|
||||
|
||||
<div class="setting">
|
||||
|
|
|
|||
Loading…
Reference in a new issue