Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2

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 boltless.me and committed by tangled.org fadf2b56 23fa27d4

+56 -115
+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 ··· 71 84 k.Pages.Knots(w, pages.KnotsParams{ 72 85 LoggedInUser: user, 73 86 Registrations: registrations, 74 - Tabs: knotsTabs, 75 87 Tab: "knots", 76 88 }) 77 89 } ··· 134 148 Members: members, 135 149 Repos: repoMap, 136 150 IsOwner: true, 137 - Tabs: knotsTabs, 138 151 Tab: "knots", 139 152 }) 140 153 }
+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 { ··· 425 423 } 426 424 } 427 425 return result 426 + }, 427 + // constant values used to define a template 428 + "const": func() map[string]any { 429 + return map[string]any{ 430 + "OrderedReactionKinds": models.OrderedReactionKinds, 431 + // would be great to have ordered maps right about now 432 + "UserSettingsTabs": []tab{ 433 + {"Name": "profile", "Icon": "user"}, 434 + {"Name": "keys", "Icon": "key"}, 435 + {"Name": "emails", "Icon": "mail"}, 436 + {"Name": "notifications", "Icon": "bell"}, 437 + {"Name": "knots", "Icon": "volleyball"}, 438 + {"Name": "spindles", "Icon": "spool"}, 439 + }, 440 + "RepoSettingsTabs": []tab{ 441 + {"Name": "general", "Icon": "sliders-horizontal"}, 442 + {"Name": "access", "Icon": "users"}, 443 + {"Name": "pipelines", "Icon": "layers-2"}, 444 + }, 445 + } 428 446 }, 429 447 } 430 448 }
+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 ··· 376 377 type UserKeysSettingsParams struct { 377 378 LoggedInUser *oauth.MultiAccountUser 378 379 PubKeys []models.PublicKey 379 - Tabs []map[string]any 380 380 Tab string 381 381 } 382 382 ··· 386 388 type UserEmailsSettingsParams struct { 387 389 LoggedInUser *oauth.MultiAccountUser 388 390 Emails []models.Email 389 - Tabs []map[string]any 390 391 Tab string 391 392 } 392 393 ··· 396 399 type UserNotificationSettingsParams struct { 397 400 LoggedInUser *oauth.MultiAccountUser 398 401 Preferences *models.NotificationPreferences 399 - Tabs []map[string]any 400 402 Tab string 401 403 } 402 404 ··· 415 419 type KnotsParams struct { 416 420 LoggedInUser *oauth.MultiAccountUser 417 421 Registrations []models.Registration 418 - Tabs []map[string]any 419 422 Tab string 420 423 } 421 424 ··· 428 433 Members []string 429 434 Repos map[string][]models.Repo 430 435 IsOwner bool 431 - Tabs []map[string]any 432 436 Tab string 433 437 } 434 438 ··· 446 452 type SpindlesParams struct { 447 453 LoggedInUser *oauth.MultiAccountUser 448 454 Spindles []models.Spindle 449 - Tabs []map[string]any 450 455 Tab string 451 456 } 452 457 ··· 455 462 456 463 type SpindleListingParams struct { 457 464 models.Spindle 458 - Tabs []map[string]any 459 - Tab string 465 + Tab string 460 466 } 461 467 462 468 func (p *Pages) SpindleListing(w io.Writer, params SpindleListingParams) error { ··· 467 475 Spindle models.Spindle 468 476 Members []string 469 477 Repos map[string][]models.Repo 470 - Tabs []map[string]any 471 478 Tab string 472 479 } 473 480 ··· 877 886 SubscribedLabels map[string]struct{} 878 887 ShouldSubscribeAll bool 879 888 Active string 880 - Tabs []map[string]any 881 889 Tab string 882 890 Branches []types.Branch 883 891 } ··· 890 900 LoggedInUser *oauth.MultiAccountUser 891 901 RepoInfo repoinfo.RepoInfo 892 902 Active string 893 - Tabs []map[string]any 894 903 Tab string 895 904 Collaborators []Collaborator 896 905 } ··· 903 914 LoggedInUser *oauth.MultiAccountUser 904 915 RepoInfo repoinfo.RepoInfo 905 916 Active string 906 - Tabs []map[string]any 907 917 Tab string 908 918 Spindles []string 909 919 CurrentSpindle string ··· 940 952 Backlinks []models.RichReferenceLink 941 953 LabelDefs map[string]*models.LabelDefinition 942 954 943 - OrderedReactionKinds []models.ReactionKind 944 - Reactions map[models.ReactionKind]models.ReactionDisplayData 945 - UserReacted map[models.ReactionKind]bool 955 + Reactions map[models.ReactionKind]models.ReactionDisplayData 956 + UserReacted map[models.ReactionKind]bool 946 957 } 947 958 948 959 func (p *Pages) RepoSingleIssue(w io.Writer, params RepoSingleIssueParams) error { ··· 1102 1115 ActiveRound int 1103 1116 IsInterdiff bool 1104 1117 1105 - OrderedReactionKinds []models.ReactionKind 1106 - Reactions map[models.ReactionKind]models.ReactionDisplayData 1107 - UserReacted map[models.ReactionKind]bool 1118 + Reactions map[models.ReactionKind]models.ReactionDisplayData 1119 + UserReacted map[models.ReactionKind]bool 1108 1120 1109 1121 LabelDefs map[string]*models.LabelDefinition 1110 1122 } ··· 1114 1128 } 1115 1129 1116 1130 type RepoPullPatchParams struct { 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 - OrderedReactionKinds []models.ReactionKind 1125 - DiffOpts types.DiffOpts 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 + DiffOpts types.DiffOpts 1126 1139 } 1127 1140 1128 1141 // this name is a mouthful ··· 1130 1145 } 1131 1146 1132 1147 type RepoPullInterdiffParams struct { 1133 - LoggedInUser *oauth.MultiAccountUser 1134 - RepoInfo repoinfo.RepoInfo 1135 - Pull *models.Pull 1136 - Round int 1137 - Interdiff *patchutil.InterdiffResult 1138 - OrderedReactionKinds []models.ReactionKind 1139 - DiffOpts types.DiffOpts 1148 + LoggedInUser *oauth.MultiAccountUser 1149 + RepoInfo repoinfo.RepoInfo 1150 + Pull *models.Pull 1151 + Round int 1152 + Interdiff *patchutil.InterdiffResult 1153 + DiffOpts types.DiffOpts 1140 1154 } 1141 1155 1142 1156 // 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" }}
+1 -2
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" }}
+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 ··· 251 262 DefaultLabels: defaultLabels, 252 263 SubscribedLabels: subscribedLabels, 253 264 ShouldSubscribeAll: shouldSubscribeAll, 254 - Tabs: settingsTabs, 255 265 Tab: "general", 256 266 }) 257 267 } ··· 296 308 rp.pages.RepoAccessSettings(w, pages.RepoAccessSettingsParams{ 297 309 LoggedInUser: user, 298 310 RepoInfo: rp.repoResolver.GetRepoInfo(r, user), 299 - Tabs: settingsTabs, 300 311 Tab: "access", 301 312 Collaborators: collaborators, 302 313 }) ··· 356 369 rp.pages.RepoPipelineSettings(w, pages.RepoPipelineSettingsParams{ 357 370 LoggedInUser: user, 358 371 RepoInfo: rp.repoResolver.GetRepoInfo(r, user), 359 - Tabs: settingsTabs, 360 372 Tab: "pipelines", 361 373 Spindles: spindles, 362 374 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 ··· 72 85 73 86 s.Pages.UserProfileSettings(w, pages.UserProfileSettingsParams{ 74 87 LoggedInUser: user, 75 - Tabs: settingsTabs, 76 88 Tab: "profile", 77 89 }) 78 90 } ··· 90 104 s.Pages.UserNotificationSettings(w, pages.UserNotificationSettingsParams{ 91 105 LoggedInUser: user, 92 106 Preferences: prefs, 93 - Tabs: settingsTabs, 94 107 Tab: "notifications", 95 108 }) 96 109 } ··· 131 146 s.Pages.UserKeysSettings(w, pages.UserKeysSettingsParams{ 132 147 LoggedInUser: user, 133 148 PubKeys: pubKeys, 134 - Tabs: settingsTabs, 135 149 Tab: "keys", 136 150 }) 137 151 } ··· 145 161 s.Pages.UserEmailsSettings(w, pages.UserEmailsSettingsParams{ 146 162 LoggedInUser: user, 147 163 Emails: emails, 148 - Tabs: settingsTabs, 149 164 Tab: "emails", 150 165 }) 151 166 }
-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 ··· 70 83 s.Pages.Spindles(w, pages.SpindlesParams{ 71 84 LoggedInUser: user, 72 85 Spindles: all, 73 - Tabs: spindlesTabs, 74 86 Tab: "spindles", 75 87 }) 76 88 } ··· 129 143 Spindle: spindle, 130 144 Members: members, 131 145 Repos: repoMap, 132 - Tabs: spindlesTabs, 133 146 Tab: "spindles", 134 147 }) 135 148 }