diff --git a/appview/issues/issues.go b/appview/issues/issues.go index 2ffeb8ac..9d35bb71 100644 --- a/appview/issues/issues.go +++ b/appview/issues/issues.go @@ -129,15 +129,14 @@ func (rp *Issues) RepoSingleIssue(w http.ResponseWriter, r *http.Request) { } rp.pages.RepoSingleIssue(w, pages.RepoSingleIssueParams{ - LoggedInUser: user, - RepoInfo: rp.repoResolver.GetRepoInfo(r, user), - Issue: issue, - CommentList: issue.CommentList(), - Backlinks: backlinks, - OrderedReactionKinds: models.OrderedReactionKinds, - Reactions: reactionMap, - UserReacted: userReactions, - LabelDefs: defs, + LoggedInUser: user, + RepoInfo: rp.repoResolver.GetRepoInfo(r, user), + Issue: issue, + CommentList: issue.CommentList(), + Backlinks: backlinks, + Reactions: reactionMap, + UserReacted: userReactions, + LabelDefs: defs, }) } diff --git a/appview/knots/knots.go b/appview/knots/knots.go index 6c3ae0e4..bd8e79dd 100644 --- a/appview/knots/knots.go +++ b/appview/knots/knots.go @@ -40,19 +40,6 @@ type Knots struct { Knotstream *eventconsumer.Consumer } -type tab = map[string]any - -var ( - knotsTabs []tab = []tab{ - {"Name": "profile", "Icon": "user"}, - {"Name": "keys", "Icon": "key"}, - {"Name": "emails", "Icon": "mail"}, - {"Name": "notifications", "Icon": "bell"}, - {"Name": "knots", "Icon": "volleyball"}, - {"Name": "spindles", "Icon": "spool"}, - } -) - func (k *Knots) Router() http.Handler { r := chi.NewRouter() @@ -84,7 +71,6 @@ func (k *Knots) knots(w http.ResponseWriter, r *http.Request) { k.Pages.Knots(w, pages.KnotsParams{ LoggedInUser: user, Registrations: registrations, - Tabs: knotsTabs, Tab: "knots", }) } @@ -148,7 +134,6 @@ func (k *Knots) dashboard(w http.ResponseWriter, r *http.Request) { Members: members, Repos: repoMap, IsOwner: true, - Tabs: knotsTabs, Tab: "knots", }) } diff --git a/appview/pages/funcmap.go b/appview/pages/funcmap.go index a65b76d6..87149d1c 100644 --- a/appview/pages/funcmap.go +++ b/appview/pages/funcmap.go @@ -32,6 +32,8 @@ import ( "tangled.org/core/crypto" ) +type tab map[string]string + func (p *Pages) funcMap() template.FuncMap { return template.FuncMap{ "split": func(s string) []string { @@ -424,6 +426,26 @@ func (p *Pages) funcMap() template.FuncMap { } return result }, + // constant values used to define a template + "const": func() map[string]any { + return map[string]any{ + "OrderedReactionKinds": models.OrderedReactionKinds, + // would be great to have ordered maps right about now + "UserSettingsTabs": []tab{ + {"Name": "profile", "Icon": "user"}, + {"Name": "keys", "Icon": "key"}, + {"Name": "emails", "Icon": "mail"}, + {"Name": "notifications", "Icon": "bell"}, + {"Name": "knots", "Icon": "volleyball"}, + {"Name": "spindles", "Icon": "spool"}, + }, + "RepoSettingsTabs": []tab{ + {"Name": "general", "Icon": "sliders-horizontal"}, + {"Name": "access", "Icon": "users"}, + {"Name": "pipelines", "Icon": "layers-2"}, + }, + } + }, } } diff --git a/appview/pages/pages.go b/appview/pages/pages.go index aa579bc5..19aa7bca 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -338,7 +338,6 @@ func (p *Pages) GoodFirstIssues(w io.Writer, params GoodFirstIssuesParams) error type UserProfileSettingsParams struct { LoggedInUser *oauth.MultiAccountUser - Tabs []map[string]any Tab string } @@ -377,7 +376,6 @@ func (p *Pages) NotificationCount(w io.Writer, params NotificationCountParams) e type UserKeysSettingsParams struct { LoggedInUser *oauth.MultiAccountUser PubKeys []models.PublicKey - Tabs []map[string]any Tab string } @@ -388,7 +386,6 @@ func (p *Pages) UserKeysSettings(w io.Writer, params UserKeysSettingsParams) err type UserEmailsSettingsParams struct { LoggedInUser *oauth.MultiAccountUser Emails []models.Email - Tabs []map[string]any Tab string } @@ -399,7 +396,6 @@ func (p *Pages) UserEmailsSettings(w io.Writer, params UserEmailsSettingsParams) type UserNotificationSettingsParams struct { LoggedInUser *oauth.MultiAccountUser Preferences *models.NotificationPreferences - Tabs []map[string]any Tab string } @@ -419,7 +415,6 @@ func (p *Pages) UpgradeBanner(w io.Writer, params UpgradeBannerParams) error { type KnotsParams struct { LoggedInUser *oauth.MultiAccountUser Registrations []models.Registration - Tabs []map[string]any Tab string } @@ -433,7 +428,6 @@ type KnotParams struct { Members []string Repos map[string][]models.Repo IsOwner bool - Tabs []map[string]any Tab string } @@ -452,7 +446,6 @@ func (p *Pages) KnotListing(w io.Writer, params KnotListingParams) error { type SpindlesParams struct { LoggedInUser *oauth.MultiAccountUser Spindles []models.Spindle - Tabs []map[string]any Tab string } @@ -462,8 +455,7 @@ func (p *Pages) Spindles(w io.Writer, params SpindlesParams) error { type SpindleListingParams struct { models.Spindle - Tabs []map[string]any - Tab string + Tab string } func (p *Pages) SpindleListing(w io.Writer, params SpindleListingParams) error { @@ -475,7 +467,6 @@ type SpindleDashboardParams struct { Spindle models.Spindle Members []string Repos map[string][]models.Repo - Tabs []map[string]any Tab string } @@ -886,7 +877,6 @@ type RepoGeneralSettingsParams struct { SubscribedLabels map[string]struct{} ShouldSubscribeAll bool Active string - Tabs []map[string]any Tab string Branches []types.Branch } @@ -900,7 +890,6 @@ type RepoAccessSettingsParams struct { LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Active string - Tabs []map[string]any Tab string Collaborators []Collaborator } @@ -914,7 +903,6 @@ type RepoPipelineSettingsParams struct { LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Active string - Tabs []map[string]any Tab string Spindles []string CurrentSpindle string @@ -952,9 +940,8 @@ type RepoSingleIssueParams struct { Backlinks []models.RichReferenceLink LabelDefs map[string]*models.LabelDefinition - OrderedReactionKinds []models.ReactionKind - Reactions map[models.ReactionKind]models.ReactionDisplayData - UserReacted map[models.ReactionKind]bool + Reactions map[models.ReactionKind]models.ReactionDisplayData + UserReacted map[models.ReactionKind]bool } func (p *Pages) RepoSingleIssue(w io.Writer, params RepoSingleIssueParams) error { @@ -1115,9 +1102,8 @@ type RepoSinglePullParams struct { ActiveRound int IsInterdiff bool - OrderedReactionKinds []models.ReactionKind - Reactions map[models.ReactionKind]models.ReactionDisplayData - UserReacted map[models.ReactionKind]bool + Reactions map[models.ReactionKind]models.ReactionDisplayData + UserReacted map[models.ReactionKind]bool LabelDefs map[string]*models.LabelDefinition } @@ -1128,15 +1114,14 @@ func (p *Pages) RepoSinglePull(w io.Writer, params RepoSinglePullParams) error { } type RepoPullPatchParams struct { - LoggedInUser *oauth.MultiAccountUser - RepoInfo repoinfo.RepoInfo - Pull *models.Pull - Stack models.Stack - Diff *types.NiceDiff - Round int - Submission *models.PullSubmission - OrderedReactionKinds []models.ReactionKind - DiffOpts types.DiffOpts + LoggedInUser *oauth.MultiAccountUser + RepoInfo repoinfo.RepoInfo + Pull *models.Pull + Stack models.Stack + Diff *types.NiceDiff + Round int + Submission *models.PullSubmission + DiffOpts types.DiffOpts } // this name is a mouthful @@ -1145,13 +1130,12 @@ func (p *Pages) RepoPullPatchPage(w io.Writer, params RepoPullPatchParams) error } type RepoPullInterdiffParams struct { - LoggedInUser *oauth.MultiAccountUser - RepoInfo repoinfo.RepoInfo - Pull *models.Pull - Round int - Interdiff *patchutil.InterdiffResult - OrderedReactionKinds []models.ReactionKind - DiffOpts types.DiffOpts + LoggedInUser *oauth.MultiAccountUser + RepoInfo repoinfo.RepoInfo + Pull *models.Pull + Round int + Interdiff *patchutil.InterdiffResult + DiffOpts types.DiffOpts } // this name is a mouthful diff --git a/appview/pages/templates/repo/issues/issue.html b/appview/pages/templates/repo/issues/issue.html index 8a1cd8a6..ccd9f2bd 100644 --- a/appview/pages/templates/repo/issues/issue.html +++ b/appview/pages/templates/repo/issues/issue.html @@ -109,8 +109,8 @@ {{ define "issueReactions" }}
- {{ template "repo/fragments/reactionsPopUp" .OrderedReactionKinds }} - {{ range $kind := .OrderedReactionKinds }} + {{ template "repo/fragments/reactionsPopUp" const.OrderedReactionKinds }} + {{ range $kind := const.OrderedReactionKinds }} {{ $reactionData := index $.Reactions $kind }} {{ template "repo/fragments/reaction" diff --git a/appview/pages/templates/repo/pulls/fragments/pullHeader.html b/appview/pages/templates/repo/pulls/fragments/pullHeader.html index 3f153ee0..7d2c0eae 100644 --- a/appview/pages/templates/repo/pulls/fragments/pullHeader.html +++ b/appview/pages/templates/repo/pulls/fragments/pullHeader.html @@ -63,7 +63,7 @@ {{ end }} - {{ with .OrderedReactionKinds }} + {{ with const.OrderedReactionKinds }}
{{ template "repo/fragments/reactionsPopUp" . }} {{ range $kind := . }} diff --git a/appview/pages/templates/repo/settings/fragments/sidebar.html b/appview/pages/templates/repo/settings/fragments/sidebar.html index 90bbf957..d22a1319 100644 --- a/appview/pages/templates/repo/settings/fragments/sidebar.html +++ b/appview/pages/templates/repo/settings/fragments/sidebar.html @@ -1,10 +1,9 @@ {{ define "repo/settings/fragments/sidebar" }} {{ $active := .Tab }} - {{ $tabs := .Tabs }}
{{ $activeTab := "bg-white dark:bg-gray-700 drop-shadow-sm" }} {{ $inactiveTab := "bg-gray-100 dark:bg-gray-800" }} - {{ range $tabs }} + {{ range const.RepoSettingsTabs }}
{{ i .Icon "size-4" }} diff --git a/appview/pages/templates/user/settings/fragments/sidebar.html b/appview/pages/templates/user/settings/fragments/sidebar.html index d5a39600..2b781d4c 100644 --- a/appview/pages/templates/user/settings/fragments/sidebar.html +++ b/appview/pages/templates/user/settings/fragments/sidebar.html @@ -1,10 +1,9 @@ {{ define "user/settings/fragments/sidebar" }} {{ $active := .Tab }} - {{ $tabs := .Tabs }}
{{ $activeTab := "bg-white dark:bg-gray-700 drop-shadow-sm" }} {{ $inactiveTab := "bg-gray-100 dark:bg-gray-800" }} - {{ range $tabs }} + {{ range const.UserSettingsTabs }} -{{ end }} \ No newline at end of file +{{ end }} diff --git a/appview/pulls/pulls.go b/appview/pulls/pulls.go index 3bbee643..25c06632 100644 --- a/appview/pulls/pulls.go +++ b/appview/pulls/pulls.go @@ -289,9 +289,8 @@ func (s *Pulls) repoPullHelper(w http.ResponseWriter, r *http.Request, interdiff ActiveRound: roundIdInt, IsInterdiff: interdiff, - OrderedReactionKinds: models.OrderedReactionKinds, - Reactions: reactionMap, - UserReacted: userReactions, + Reactions: reactionMap, + UserReacted: userReactions, LabelDefs: defs, }) diff --git a/appview/repo/settings.go b/appview/repo/settings.go index 863cd76e..1b82f8f3 100644 --- a/appview/repo/settings.go +++ b/appview/repo/settings.go @@ -22,17 +22,6 @@ import ( indigoxrpc "github.com/bluesky-social/indigo/xrpc" ) -type tab = map[string]any - -var ( - // would be great to have ordered maps right about now - settingsTabs []tab = []tab{ - {"Name": "general", "Icon": "sliders-horizontal"}, - {"Name": "access", "Icon": "users"}, - {"Name": "pipelines", "Icon": "layers-2"}, - } -) - func (rp *Repo) SetDefaultBranch(w http.ResponseWriter, r *http.Request) { l := rp.logger.With("handler", "SetDefaultBranch") @@ -262,7 +251,6 @@ func (rp *Repo) generalSettings(w http.ResponseWriter, r *http.Request) { DefaultLabels: defaultLabels, SubscribedLabels: subscribedLabels, ShouldSubscribeAll: shouldSubscribeAll, - Tabs: settingsTabs, Tab: "general", }) } @@ -308,7 +296,6 @@ func (rp *Repo) accessSettings(w http.ResponseWriter, r *http.Request) { rp.pages.RepoAccessSettings(w, pages.RepoAccessSettingsParams{ LoggedInUser: user, RepoInfo: rp.repoResolver.GetRepoInfo(r, user), - Tabs: settingsTabs, Tab: "access", Collaborators: collaborators, }) @@ -369,7 +356,6 @@ func (rp *Repo) pipelineSettings(w http.ResponseWriter, r *http.Request) { rp.pages.RepoPipelineSettings(w, pages.RepoPipelineSettingsParams{ LoggedInUser: user, RepoInfo: rp.repoResolver.GetRepoInfo(r, user), - Tabs: settingsTabs, Tab: "pipelines", Spindles: spindles, CurrentSpindle: f.Spindle, diff --git a/appview/settings/settings.go b/appview/settings/settings.go index 2a337e8b..cbe783e0 100644 --- a/appview/settings/settings.go +++ b/appview/settings/settings.go @@ -35,19 +35,6 @@ type Settings struct { Config *config.Config } -type tab = map[string]any - -var ( - settingsTabs []tab = []tab{ - {"Name": "profile", "Icon": "user"}, - {"Name": "keys", "Icon": "key"}, - {"Name": "emails", "Icon": "mail"}, - {"Name": "notifications", "Icon": "bell"}, - {"Name": "knots", "Icon": "volleyball"}, - {"Name": "spindles", "Icon": "spool"}, - } -) - func (s *Settings) Router() http.Handler { r := chi.NewRouter() @@ -85,7 +72,6 @@ func (s *Settings) profileSettings(w http.ResponseWriter, r *http.Request) { s.Pages.UserProfileSettings(w, pages.UserProfileSettingsParams{ LoggedInUser: user, - Tabs: settingsTabs, Tab: "profile", }) } @@ -104,7 +90,6 @@ func (s *Settings) notificationsSettings(w http.ResponseWriter, r *http.Request) s.Pages.UserNotificationSettings(w, pages.UserNotificationSettingsParams{ LoggedInUser: user, Preferences: prefs, - Tabs: settingsTabs, Tab: "notifications", }) } @@ -146,7 +131,6 @@ func (s *Settings) keysSettings(w http.ResponseWriter, r *http.Request) { s.Pages.UserKeysSettings(w, pages.UserKeysSettingsParams{ LoggedInUser: user, PubKeys: pubKeys, - Tabs: settingsTabs, Tab: "keys", }) } @@ -161,7 +145,6 @@ func (s *Settings) emailsSettings(w http.ResponseWriter, r *http.Request) { s.Pages.UserEmailsSettings(w, pages.UserEmailsSettingsParams{ LoggedInUser: user, Emails: emails, - Tabs: settingsTabs, Tab: "emails", }) } diff --git a/appview/spindles/spindles.go b/appview/spindles/spindles.go index 729e58d1..5e27f2d6 100644 --- a/appview/spindles/spindles.go +++ b/appview/spindles/spindles.go @@ -39,19 +39,6 @@ type Spindles struct { Logger *slog.Logger } -type tab = map[string]any - -var ( - spindlesTabs []tab = []tab{ - {"Name": "profile", "Icon": "user"}, - {"Name": "keys", "Icon": "key"}, - {"Name": "emails", "Icon": "mail"}, - {"Name": "notifications", "Icon": "bell"}, - {"Name": "knots", "Icon": "volleyball"}, - {"Name": "spindles", "Icon": "spool"}, - } -) - func (s *Spindles) Router() http.Handler { r := chi.NewRouter() @@ -83,7 +70,6 @@ func (s *Spindles) spindles(w http.ResponseWriter, r *http.Request) { s.Pages.Spindles(w, pages.SpindlesParams{ LoggedInUser: user, Spindles: all, - Tabs: spindlesTabs, Tab: "spindles", }) } @@ -143,7 +129,6 @@ func (s *Spindles) dashboard(w http.ResponseWriter, r *http.Request) { Spindle: spindle, Members: members, Repos: repoMap, - Tabs: spindlesTabs, Tab: "spindles", }) }