@@ -35,19 +35,19 @@ func (n ChangesNav) Render() []*html.Node { return []*html.Node{header} } // tabs renders the HTML nodes for <nav> element with tab header links. func (n ChangesNav) tabs() []*html.Node { selectedTabName := n.Query.Get(n.StateQueryKey) selectedTabName := n.selectedTabName() var ns []*html.Node for i, tab := range []struct { Name string // Tab name corresponds to its state filter query value. Component htmlg.Component }{ // Note: The routing logic (i.e., exact tab Name values) is duplicated with tabStateFilter. // Might want to try to factor it out into a common location (e.g., a route package or so). {Name: "", Component: OpenChangesTab{Count: n.OpenCount}}, {Name: "open", Component: OpenChangesTab{Count: n.OpenCount}}, {Name: "closed", Component: ClosedChangesTab{Count: n.ClosedCount}}, } { tabURL := (&url.URL{ Path: n.Path, RawQuery: n.rawQuery(tab.Name), @@ -68,14 +68,24 @@ func (n ChangesNav) tabs() []*html.Node { ns = append(ns, a) } return ns } const defaultTabName = "open" func (n ChangesNav) selectedTabName() string { vs := n.Query[n.StateQueryKey] if len(vs) == 0 { return defaultTabName } return vs[0] } // rawQuery returns the raw query for a link pointing to tabName. func (n ChangesNav) rawQuery(tabName string) string { q := n.Query if tabName == "" { if tabName == defaultTabName { q.Del(n.StateQueryKey) return q.Encode() } q.Set(n.StateQueryKey, tabName) return q.Encode()