Monorepo for Tangled

appview: move template-specific constants to global funcmap

Constants those are mainly used to define a template shouldn't be
managed from http handlers. Define constant values in `const` funcmap so
we can easily access them without depending on template params.

This change will make more sense with following change `rusppvkn`

Signed-off-by: Seongmin Lee <git@boltless.me>

authored by

Seongmin Lee and committed by tangled.org fadf2b56 23fa27d4

+57 -116
+8 -9
appview/issues/issues.go
··· 129 129 } 130 130 131 131 rp.pages.RepoSingleIssue(w, pages.RepoSingleIssueParams{ 132 - LoggedInUser: user, 133 - RepoInfo: rp.repoResolver.GetRepoInfo(r, user), 134 - Issue: issue, 135 - CommentList: issue.CommentList(), 136 - Backlinks: backlinks, 137 - OrderedReactionKinds: models.OrderedReactionKinds, 138 - Reactions: reactionMap, 139 - UserReacted: userReactions, 140 - LabelDefs: defs, 132 + LoggedInUser: user, 133 + RepoInfo: rp.repoResolver.GetRepoInfo(r, user), 134 + Issue: issue, 135 + CommentList: issue.CommentList(), 136 + Backlinks: backlinks, 137 + Reactions: reactionMap, 138 + UserReacted: userReactions, 139 + LabelDefs: defs, 141 140 }) 142 141 } 143 142
-15
appview/knots/knots.go
··· 40 40 Knotstream *eventconsumer.Consumer 41 41 } 42 42 43 - type tab = map[string]any 44 - 45 - var ( 46 - knotsTabs []tab = []tab{ 47 - {"Name": "profile", "Icon": "user"}, 48 - {"Name": "keys", "Icon": "key"}, 49 - {"Name": "emails", "Icon": "mail"}, 50 - {"Name": "notifications", "Icon": "bell"}, 51 - {"Name": "knots", "Icon": "volleyball"}, 52 - {"Name": "spindles", "Icon": "spool"}, 53 - } 54 - ) 55 - 56 43 func (k *Knots) Router() http.Handler { 57 44 r := chi.NewRouter() 58 45 ··· 84 71 k.Pages.Knots(w, pages.KnotsParams{ 85 72 LoggedInUser: user, 86 73 Registrations: registrations, 87 - Tabs: knotsTabs, 88 74 Tab: "knots", 89 75 }) 90 76 } ··· 148 134 Members: members, 149 135 Repos: repoMap, 150 136 IsOwner: true, 151 - Tabs: knotsTabs, 152 137 Tab: "knots", 153 138 }) 154 139 }
+22
appview/pages/funcmap.go
··· 32 32 "tangled.org/core/crypto" 33 33 ) 34 34 35 + type tab map[string]string 36 + 35 37 func (p *Pages) funcMap() template.FuncMap { 36 38 return template.FuncMap{ 37 39 "split": func(s string) []string { ··· 423 425 } 424 426 } 425 427 return result 428 + }, 429 + // constant values used to define a template 430 + "const": func() map[string]any { 431 + return map[string]any{ 432 + "OrderedReactionKinds": models.OrderedReactionKinds, 433 + // would be great to have ordered maps right about now 434 + "UserSettingsTabs": []tab{ 435 + {"Name": "profile", "Icon": "user"}, 436 + {"Name": "keys", "Icon": "key"}, 437 + {"Name": "emails", "Icon": "mail"}, 438 + {"Name": "notifications", "Icon": "bell"}, 439 + {"Name": "knots", "Icon": "volleyball"}, 440 + {"Name": "spindles", "Icon": "spool"}, 441 + }, 442 + "RepoSettingsTabs": []tab{ 443 + {"Name": "general", "Icon": "sliders-horizontal"}, 444 + {"Name": "access", "Icon": "users"}, 445 + {"Name": "pipelines", "Icon": "layers-2"}, 446 + }, 447 + } 426 448 }, 427 449 } 428 450 }
+19 -35
appview/pages/pages.go
··· 338 338 339 339 type UserProfileSettingsParams struct { 340 340 LoggedInUser *oauth.MultiAccountUser 341 - Tabs []map[string]any 342 341 Tab string 343 342 } 344 343 ··· 377 376 type UserKeysSettingsParams struct { 378 377 LoggedInUser *oauth.MultiAccountUser 379 378 PubKeys []models.PublicKey 380 - Tabs []map[string]any 381 379 Tab string 382 380 } 383 381 ··· 388 386 type UserEmailsSettingsParams struct { 389 387 LoggedInUser *oauth.MultiAccountUser 390 388 Emails []models.Email 391 - Tabs []map[string]any 392 389 Tab string 393 390 } 394 391 ··· 399 396 type UserNotificationSettingsParams struct { 400 397 LoggedInUser *oauth.MultiAccountUser 401 398 Preferences *models.NotificationPreferences 402 - Tabs []map[string]any 403 399 Tab string 404 400 } 405 401 ··· 419 415 type KnotsParams struct { 420 416 LoggedInUser *oauth.MultiAccountUser 421 417 Registrations []models.Registration 422 - Tabs []map[string]any 423 418 Tab string 424 419 } 425 420 ··· 433 428 Members []string 434 429 Repos map[string][]models.Repo 435 430 IsOwner bool 436 - Tabs []map[string]any 437 431 Tab string 438 432 } 439 433 ··· 452 446 type SpindlesParams struct { 453 447 LoggedInUser *oauth.MultiAccountUser 454 448 Spindles []models.Spindle 455 - Tabs []map[string]any 456 449 Tab string 457 450 } 458 451 ··· 462 455 463 456 type SpindleListingParams struct { 464 457 models.Spindle 465 - Tabs []map[string]any 466 - Tab string 458 + Tab string 467 459 } 468 460 469 461 func (p *Pages) SpindleListing(w io.Writer, params SpindleListingParams) error { ··· 475 467 Spindle models.Spindle 476 468 Members []string 477 469 Repos map[string][]models.Repo 478 - Tabs []map[string]any 479 470 Tab string 480 471 } 481 472 ··· 886 877 SubscribedLabels map[string]struct{} 887 878 ShouldSubscribeAll bool 888 879 Active string 889 - Tabs []map[string]any 890 880 Tab string 891 881 Branches []types.Branch 892 882 } ··· 900 890 LoggedInUser *oauth.MultiAccountUser 901 891 RepoInfo repoinfo.RepoInfo 902 892 Active string 903 - Tabs []map[string]any 904 893 Tab string 905 894 Collaborators []Collaborator 906 895 } ··· 914 903 LoggedInUser *oauth.MultiAccountUser 915 904 RepoInfo repoinfo.RepoInfo 916 905 Active string 917 - Tabs []map[string]any 918 906 Tab string 919 907 Spindles []string 920 908 CurrentSpindle string ··· 952 940 Backlinks []models.RichReferenceLink 953 941 LabelDefs map[string]*models.LabelDefinition 954 942 955 - OrderedReactionKinds []models.ReactionKind 956 - Reactions map[models.ReactionKind]models.ReactionDisplayData 957 - UserReacted map[models.ReactionKind]bool 943 + Reactions map[models.ReactionKind]models.ReactionDisplayData 944 + UserReacted map[models.ReactionKind]bool 958 945 } 959 946 960 947 func (p *Pages) RepoSingleIssue(w io.Writer, params RepoSingleIssueParams) error { ··· 1115 1102 ActiveRound int 1116 1103 IsInterdiff bool 1117 1104 1118 - OrderedReactionKinds []models.ReactionKind 1119 - Reactions map[models.ReactionKind]models.ReactionDisplayData 1120 - UserReacted map[models.ReactionKind]bool 1105 + Reactions map[models.ReactionKind]models.ReactionDisplayData 1106 + UserReacted map[models.ReactionKind]bool 1121 1107 1122 1108 LabelDefs map[string]*models.LabelDefinition 1123 1109 } ··· 1128 1114 } 1129 1115 1130 1116 type RepoPullPatchParams struct { 1131 - LoggedInUser *oauth.MultiAccountUser 1132 - RepoInfo repoinfo.RepoInfo 1133 - Pull *models.Pull 1134 - Stack models.Stack 1135 - Diff *types.NiceDiff 1136 - Round int 1137 - Submission *models.PullSubmission 1138 - OrderedReactionKinds []models.ReactionKind 1139 - DiffOpts types.DiffOpts 1117 + LoggedInUser *oauth.MultiAccountUser 1118 + RepoInfo repoinfo.RepoInfo 1119 + Pull *models.Pull 1120 + Stack models.Stack 1121 + Diff *types.NiceDiff 1122 + Round int 1123 + Submission *models.PullSubmission 1124 + DiffOpts types.DiffOpts 1140 1125 } 1141 1126 1142 1127 // this name is a mouthful ··· 1145 1130 } 1146 1131 1147 1132 type RepoPullInterdiffParams struct { 1148 - LoggedInUser *oauth.MultiAccountUser 1149 - RepoInfo repoinfo.RepoInfo 1150 - Pull *models.Pull 1151 - Round int 1152 - Interdiff *patchutil.InterdiffResult 1153 - OrderedReactionKinds []models.ReactionKind 1154 - DiffOpts types.DiffOpts 1133 + LoggedInUser *oauth.MultiAccountUser 1134 + RepoInfo repoinfo.RepoInfo 1135 + Pull *models.Pull 1136 + Round int 1137 + Interdiff *patchutil.InterdiffResult 1138 + DiffOpts types.DiffOpts 1155 1139 } 1156 1140 1157 1141 // this name is a mouthful
+2 -2
appview/pages/templates/repo/issues/issue.html
··· 109 109 110 110 {{ define "issueReactions" }} 111 111 <div class="flex items-center gap-2"> 112 - {{ template "repo/fragments/reactionsPopUp" .OrderedReactionKinds }} 113 - {{ range $kind := .OrderedReactionKinds }} 112 + {{ template "repo/fragments/reactionsPopUp" const.OrderedReactionKinds }} 113 + {{ range $kind := const.OrderedReactionKinds }} 114 114 {{ $reactionData := index $.Reactions $kind }} 115 115 {{ 116 116 template "repo/fragments/reaction"
+1 -1
appview/pages/templates/repo/pulls/fragments/pullHeader.html
··· 63 63 </article> 64 64 {{ end }} 65 65 66 - {{ with .OrderedReactionKinds }} 66 + {{ with const.OrderedReactionKinds }} 67 67 <div class="flex items-center gap-2 mt-2"> 68 68 {{ template "repo/fragments/reactionsPopUp" . }} 69 69 {{ range $kind := . }}
+1 -2
appview/pages/templates/repo/settings/fragments/sidebar.html
··· 1 1 {{ define "repo/settings/fragments/sidebar" }} 2 2 {{ $active := .Tab }} 3 - {{ $tabs := .Tabs }} 4 3 <div class="sticky top-2 grid grid-cols-1 rounded border border-gray-200 dark:border-gray-700 divide-y divide-gray-200 dark:divide-gray-700 shadow-inner"> 5 4 {{ $activeTab := "bg-white dark:bg-gray-700 drop-shadow-sm" }} 6 5 {{ $inactiveTab := "bg-gray-100 dark:bg-gray-800" }} 7 - {{ range $tabs }} 6 + {{ range const.RepoSettingsTabs }} 8 7 <a href="/{{ $.RepoInfo.FullName }}/settings?tab={{.Name}}" class="no-underline hover:no-underline hover:bg-gray-100/25 hover:dark:bg-gray-700/25"> 9 8 <div class="flex gap-3 items-center p-2 {{ if eq .Name $active }} {{ $activeTab }} {{ else }} {{ $inactiveTab }} {{ end }}"> 10 9 {{ i .Icon "size-4" }}
+2 -3
appview/pages/templates/user/settings/fragments/sidebar.html
··· 1 1 {{ define "user/settings/fragments/sidebar" }} 2 2 {{ $active := .Tab }} 3 - {{ $tabs := .Tabs }} 4 3 <div class="sticky top-2 grid grid-cols-1 rounded border border-gray-200 dark:border-gray-700 divide-y divide-gray-200 dark:divide-gray-700 shadow-inner"> 5 4 {{ $activeTab := "bg-white dark:bg-gray-700 drop-shadow-sm" }} 6 5 {{ $inactiveTab := "bg-gray-100 dark:bg-gray-800" }} 7 - {{ range $tabs }} 6 + {{ range const.UserSettingsTabs }} 8 7 <a href="/settings/{{.Name}}" class="no-underline hover:no-underline hover:bg-gray-100/25 hover:dark:bg-gray-700/25"> 9 8 <div class="flex gap-3 items-center p-2 {{ if eq .Name $active }} {{ $activeTab }} {{ else }} {{ $inactiveTab }} {{ end }}"> 10 9 {{ i .Icon "size-4" }} ··· 13 12 </a> 14 13 {{ end }} 15 14 </div> 16 - {{ end }} 15 + {{ end }}
+2 -3
appview/pulls/pulls.go
··· 289 289 ActiveRound: roundIdInt, 290 290 IsInterdiff: interdiff, 291 291 292 - OrderedReactionKinds: models.OrderedReactionKinds, 293 - Reactions: reactionMap, 294 - UserReacted: userReactions, 292 + Reactions: reactionMap, 293 + UserReacted: userReactions, 295 294 296 295 LabelDefs: defs, 297 296 })
-14
appview/repo/settings.go
··· 22 22 indigoxrpc "github.com/bluesky-social/indigo/xrpc" 23 23 ) 24 24 25 - type tab = map[string]any 26 - 27 - var ( 28 - // would be great to have ordered maps right about now 29 - settingsTabs []tab = []tab{ 30 - {"Name": "general", "Icon": "sliders-horizontal"}, 31 - {"Name": "access", "Icon": "users"}, 32 - {"Name": "pipelines", "Icon": "layers-2"}, 33 - } 34 - ) 35 - 36 25 func (rp *Repo) SetDefaultBranch(w http.ResponseWriter, r *http.Request) { 37 26 l := rp.logger.With("handler", "SetDefaultBranch") 38 27 ··· 262 251 DefaultLabels: defaultLabels, 263 252 SubscribedLabels: subscribedLabels, 264 253 ShouldSubscribeAll: shouldSubscribeAll, 265 - Tabs: settingsTabs, 266 254 Tab: "general", 267 255 }) 268 256 } ··· 308 296 rp.pages.RepoAccessSettings(w, pages.RepoAccessSettingsParams{ 309 297 LoggedInUser: user, 310 298 RepoInfo: rp.repoResolver.GetRepoInfo(r, user), 311 - Tabs: settingsTabs, 312 299 Tab: "access", 313 300 Collaborators: collaborators, 314 301 }) ··· 369 356 rp.pages.RepoPipelineSettings(w, pages.RepoPipelineSettingsParams{ 370 357 LoggedInUser: user, 371 358 RepoInfo: rp.repoResolver.GetRepoInfo(r, user), 372 - Tabs: settingsTabs, 373 359 Tab: "pipelines", 374 360 Spindles: spindles, 375 361 CurrentSpindle: f.Spindle,
-17
appview/settings/settings.go
··· 35 35 Config *config.Config 36 36 } 37 37 38 - type tab = map[string]any 39 - 40 - var ( 41 - settingsTabs []tab = []tab{ 42 - {"Name": "profile", "Icon": "user"}, 43 - {"Name": "keys", "Icon": "key"}, 44 - {"Name": "emails", "Icon": "mail"}, 45 - {"Name": "notifications", "Icon": "bell"}, 46 - {"Name": "knots", "Icon": "volleyball"}, 47 - {"Name": "spindles", "Icon": "spool"}, 48 - } 49 - ) 50 - 51 38 func (s *Settings) Router() http.Handler { 52 39 r := chi.NewRouter() 53 40 ··· 85 72 86 73 s.Pages.UserProfileSettings(w, pages.UserProfileSettingsParams{ 87 74 LoggedInUser: user, 88 - Tabs: settingsTabs, 89 75 Tab: "profile", 90 76 }) 91 77 } ··· 104 90 s.Pages.UserNotificationSettings(w, pages.UserNotificationSettingsParams{ 105 91 LoggedInUser: user, 106 92 Preferences: prefs, 107 - Tabs: settingsTabs, 108 93 Tab: "notifications", 109 94 }) 110 95 } ··· 146 131 s.Pages.UserKeysSettings(w, pages.UserKeysSettingsParams{ 147 132 LoggedInUser: user, 148 133 PubKeys: pubKeys, 149 - Tabs: settingsTabs, 150 134 Tab: "keys", 151 135 }) 152 136 } ··· 161 145 s.Pages.UserEmailsSettings(w, pages.UserEmailsSettingsParams{ 162 146 LoggedInUser: user, 163 147 Emails: emails, 164 - Tabs: settingsTabs, 165 148 Tab: "emails", 166 149 }) 167 150 }
-15
appview/spindles/spindles.go
··· 39 39 Logger *slog.Logger 40 40 } 41 41 42 - type tab = map[string]any 43 - 44 - var ( 45 - spindlesTabs []tab = []tab{ 46 - {"Name": "profile", "Icon": "user"}, 47 - {"Name": "keys", "Icon": "key"}, 48 - {"Name": "emails", "Icon": "mail"}, 49 - {"Name": "notifications", "Icon": "bell"}, 50 - {"Name": "knots", "Icon": "volleyball"}, 51 - {"Name": "spindles", "Icon": "spool"}, 52 - } 53 - ) 54 - 55 42 func (s *Spindles) Router() http.Handler { 56 43 r := chi.NewRouter() 57 44 ··· 83 70 s.Pages.Spindles(w, pages.SpindlesParams{ 84 71 LoggedInUser: user, 85 72 Spindles: all, 86 - Tabs: spindlesTabs, 87 73 Tab: "spindles", 88 74 }) 89 75 } ··· 143 129 Spindle: spindle, 144 130 Members: members, 145 131 Repos: repoMap, 146 - Tabs: spindlesTabs, 147 132 Tab: "spindles", 148 133 }) 149 134 }