diff --git a/front/server.go b/front/server.go index 8eb1aa5..b99ec8b 100644 --- a/front/server.go +++ b/front/server.go @@ -54,12 +54,11 @@ func NewHandler(params HandlerParams) http.Handler { func (h *handler) handleRoot(w http.ResponseWriter, r *http.Request) { body := hm.Terms{ - e.H2()(hm.Text("Welcome!")), e.A(a.Href(pathCreate))( hm.Text("Create event"), ), } - _ = h.writePage(w, body) + _ = h.writePage(w, "Welcome!", body) } var timeLabels = []string{ @@ -137,22 +136,22 @@ func (h *handler) handleVote(w http.ResponseWriter, r *http.Request) { latestDate: event.LatestDate, } body := hm.Terms{ - e.H2()(hm.Text(event.Name)), e.P()(hm.Text(event.Description)), voteForm(false, state), } - _ = h.writePage(w, body) + _ = h.writePage(w, event.Name, body) } func (h *handler) handleDoVote(w http.ResponseWriter, r *http.Request) { - // TODO use actual data + // TODO Consider redirecting to vote edit page once that exists. + + // TODO Use actual data. state := voteState{ name: "Suzie Q", earliestDate: time.Date(2006, time.May, 3, 0, 0, 0, 0, time.UTC), latestDate: time.Date(2006, time.May, 8, 0, 0, 0, 0, time.UTC), } body := hm.Terms{ - e.H2()(hm.Text("Billy's birthday party")), e.P()(hm.Text("At Billy's house. Bring presents. Eat cake.")), e.H3()(hm.Text("Thanks for voting!")), e.P()( @@ -162,12 +161,11 @@ func (h *handler) handleDoVote(w http.ResponseWriter, r *http.Request) { ), voteForm(true, state), } - _ = h.writePage(w, body) + _ = h.writePage(w, "Billy's birthday party", body) } func (h *handler) handleCreate(w http.ResponseWriter, r *http.Request) { body := hm.Terms{ - e.H2()(hm.Text("Create an event")), e.Form(a.Action(pathDoCreate), a.Method(http.MethodPost))( e.Label(a.For(fieldNameEventName))(hm.Text("Event name")), e.Input(a.Name(fieldNameEventName)), @@ -184,10 +182,11 @@ func (h *handler) handleCreate(w http.ResponseWriter, r *http.Request) { e.Input(a.Type("submit")), ), } - _ = h.writePage(w, body) + _ = h.writePage(w, "Create an event", body) } func (h *handler) handleDoCreate(w http.ResponseWriter, r *http.Request) { + // TODO consider redirecting to admin earliest, err := time.Parse(formDateLayout, r.FormValue(fieldNameEarliest)) if err != nil { fmt.Fprint(w, "bad earliest date") @@ -227,7 +226,6 @@ func (h *handler) handleDoCreate(w http.ResponseWriter, r *http.Request) { const dateDisplayFmt = "Monday, January 2, 2006" body := hm.Terms{ - e.H2()(hm.Text("Created event!")), e.P()( hm.Text("You can find it again at "), e.A(a.Href(adminURL))(hm.Text(adminURL)), @@ -251,7 +249,7 @@ func (h *handler) handleDoCreate(w http.ResponseWriter, r *http.Request) { e.H3()(hm.Text("Latest date")), hm.Text(latest.Format(dateDisplayFmt)), } - _ = h.writePage(w, body) + _ = h.writePage(w, "Created event", body) } func (h *handler) handleAdmin(w http.ResponseWriter, r *http.Request) { @@ -267,7 +265,6 @@ func (h *handler) handleAdmin(w http.ResponseWriter, r *http.Request) { } body := hm.Terms{ - e.H2()(hm.Text("Edit your event")), e.Form()( e.Label(a.For(fieldNameEventName))(hm.Text("Event name")), e.Input( @@ -299,21 +296,26 @@ func (h *handler) handleAdmin(w http.ResponseWriter, r *http.Request) { e.Input(a.Type("submit")), ), } - _ = h.writePage(w, body) + _ = h.writePage(w, "Edit your event", body) } func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { h.mux.ServeHTTP(w, r) } -func (h *handler) writePage(w io.Writer, contents hm.Term) error { +func (h *handler) writePage(w io.Writer, title string, contents hm.Term) error { + // TODO Need optional subtitles, and titles should be optional. + // Take a Page struct with title, subtitle, and contents. page := e.Html()( e.Head()( - e.Title()(hm.Text(h.title)), + e.Title()(hm.Text(h.title+" — "+title)), ), e.Body()( e.H1()(e.A(a.Href(h.baseURL+pathRoot))(hm.Text(h.title))), - e.Div()(contents), + e.Div()( + e.H2()(hm.Text(title)), + contents, + ), ), ) _, err := hm.WriteDocument(w, page)