dmitri.shuralyov.com/app/changes

Display number of commits in tabnav.
dmitshur committed 7 years ago commit 70a9efcb9fd80d118d1b34bda59029cb27fa7312
Showing partial commit. Full Commit
Collapse all
main.go
@@ -459,11 +459,14 @@ func (s state) Tabnav(selected string) template.HTML {
				Content:  iconText{Icon: octiconssvg.CommentDiscussion, Text: "Discussion"},
				URL:      fmt.Sprintf("%s/%d", s.BaseURI, s.IssueID),
				Selected: selected == "Discussion",
			},
			{
				Content:  iconText{Icon: octiconssvg.GitCommit, Text: "Commits"},
				Content: contentCounter{
					Content: iconText{Icon: octiconssvg.GitCommit, Text: "Commits"},
					Count:   s.Change.Commits,
				},
				URL:      fmt.Sprintf("%s/%d/commits", s.BaseURI, s.IssueID),
				Selected: selected == "Commits",
			},
			{
				Content:  iconText{Icon: octiconssvg.Diff, Text: "Files"},
xxx.go
@@ -56,10 +56,22 @@ func (t tab) Render() []*html.Node {
	}
	htmlg.AppendChildren(a, t.Content.Render()...)
	return []*html.Node{a}
}

type contentCounter struct {
	Content htmlg.Component
	Count   int
}

func (cc contentCounter) Render() []*html.Node {
	var ns []*html.Node
	ns = append(ns, cc.Content.Render()...)
	ns = append(ns, htmlg.SpanClass("counter", htmlg.Text(fmt.Sprint(cc.Count))))
	return ns
}

// iconText is an icon with text on the right.
// Icon must be not nil.
type iconText struct {
	Icon func() *html.Node // Must be not nil.
	Text string