dmitri.shuralyov.com/app/changes/component

Rename {,Open,Closed}Issues{Nav,Tab} to {,Open,Closed}Changes{Nav,Tab}.

Improve naming consistency.
dmitshur committed 6 years ago commit 355a5c3f92690b2daa741388b73f381601a9598f
Showing partial commit. Full Commit
Collapse all
component/changes.go
@@ -12,28 +12,28 @@ import (
)

// Changes is a component that displays a page of changes,
// with a navigation bar on top.
type Changes struct {
	IssuesNav IssuesNav
	Filter    change.StateFilter
	Entries   []ChangeEntry
	ChangesNav ChangesNav
	Filter     change.StateFilter
	Entries    []ChangeEntry
}

func (i Changes) Render() []*html.Node {
	// TODO: Make this much nicer.
	// <div class="list-entry list-entry-border">
	// 	{{render .IssuesNav}}
	// 	{{render .ChangesNav}}
	// 	{{with .Entries}}{{range .}}
	// 		{{render .}}
	// 	{{end}}{{else}}
	// 		<div style="text-align: center; margin-top: 80px; margin-bottom: 80px;">There are no {{.Filter}} changes.</div>
	// 	{{end}}
	// </div>

	var ns []*html.Node
	ns = append(ns, i.IssuesNav.Render()...)
	ns = append(ns, i.ChangesNav.Render()...)
	for _, e := range i.Entries {
		ns = append(ns, e.Render()...)
	}
	if len(i.Entries) == 0 {
		// No changes with this filter. Let the user know via a blank slate.
component/tabs.go
@@ -8,21 +8,21 @@ import (
	"github.com/shurcooL/octiconssvg"
	"golang.org/x/net/html"
	"golang.org/x/net/html/atom"
)

// IssuesNav is a navigation component for displaying a header for a list of changes.
// ChangesNav is a navigation component for displaying a header for a list of changes.
// It contains tabs to switch between viewing open and closed changes.
type IssuesNav struct {
type ChangesNav struct {
	OpenCount     uint64     // Open changes count.
	ClosedCount   uint64     // Closed changes count.
	Path          string     // URL path of current page (needed to generate correct links).
	Query         url.Values // URL query of current page (needed to generate correct links).
	StateQueryKey string     // Name of query key for controlling change state filter. Constant, but provided externally.
}

func (n IssuesNav) Render() []*html.Node {
func (n ChangesNav) Render() []*html.Node {
	// TODO: Make this much nicer.
	// <header class="list-entry-header">
	// 	<nav>{{.Tabs}}</nav>
	// </header>
	nav := &html.Node{Type: html.ElementNode, Data: atom.Nav.String()}
@@ -34,21 +34,21 @@ func (n IssuesNav) Render() []*html.Node {
	}
	return []*html.Node{header}
}

// tabs renders the HTML nodes for <nav> element with tab header links.
func (n IssuesNav) tabs() []*html.Node {
func (n ChangesNav) tabs() []*html.Node {
	selectedTabName := n.Query.Get(n.StateQueryKey)
	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: OpenIssuesTab{Count: n.OpenCount}},
		{Name: "closed", Component: ClosedIssuesTab{Count: n.ClosedCount}},
		{Name: "", Component: OpenChangesTab{Count: n.OpenCount}},
		{Name: "closed", Component: ClosedChangesTab{Count: n.ClosedCount}},
	} {
		tabURL := (&url.URL{
			Path:     n.Path,
			RawQuery: n.rawQuery(tab.Name),
		}).String()
@@ -69,26 +69,26 @@ func (n IssuesNav) tabs() []*html.Node {
	}
	return ns
}

// rawQuery returns the raw query for a link pointing to tabName.
func (n IssuesNav) rawQuery(tabName string) string {
func (n ChangesNav) rawQuery(tabName string) string {
	q := n.Query
	if tabName == "" {
		q.Del(n.StateQueryKey)
		return q.Encode()
	}
	q.Set(n.StateQueryKey, tabName)
	return q.Encode()
}

// OpenIssuesTab is an "Open Issues Tab" component.
type OpenIssuesTab struct {
// OpenChangesTab is an "Open Changes Tab" component.
type OpenChangesTab struct {
	Count uint64 // Count of open changes.
}

func (t OpenIssuesTab) Render() []*html.Node {
func (t OpenChangesTab) Render() []*html.Node {
	// TODO: Make this much nicer.
	// <span style="margin-right: 4px;">{{octicon "git-pull-request"}}</span>
	// {{.Count}} Open
	icon := &html.Node{
		Type: html.ElementNode, Data: atom.Span.String(),
@@ -99,16 +99,16 @@ func (t OpenIssuesTab) Render() []*html.Node {
	}
	text := htmlg.Text(fmt.Sprintf("%d Open", t.Count))
	return []*html.Node{icon, text}
}

// ClosedIssuesTab is a "Closed Issues Tab" component.
type ClosedIssuesTab struct {
// ClosedChangesTab is a "Closed Changes Tab" component.
type ClosedChangesTab struct {
	Count uint64 // Count of closed changes.
}

func (t ClosedIssuesTab) Render() []*html.Node {
func (t ClosedChangesTab) Render() []*html.Node {
	// TODO: Make this much nicer.
	// <span style="margin-right: 4px;">{{octicon "check"}}</span>
	// {{.Count}} Closed
	icon := &html.Node{
		Type: html.ElementNode, Data: atom.Span.String(),