Monorepo for Tangled
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview: add "starred-by" page at /{user}/{repo}/stars

Signed-off-by: Patrick Dewey <p@pdewey.com>

+67
+13
appview/pages/pages.go
··· 688 688 IsStarred bool 689 689 SubjectAt syntax.ATURI 690 690 StarCount int 691 + RepoName string 691 692 HxSwapOob bool 692 693 } 693 694 ··· 1416 1417 1417 1418 func (p *Pages) EditLabelPanel(w io.Writer, params EditLabelPanelParams) error { 1418 1419 return p.executePlain("repo/fragments/editLabelPanel", w, params) 1420 + } 1421 + 1422 + type RepoStarsParams struct { 1423 + LoggedInUser *oauth.MultiAccountUser 1424 + RepoInfo repoinfo.RepoInfo 1425 + Active string 1426 + Starrers []models.Star 1427 + } 1428 + 1429 + func (p *Pages) RepoStars(w io.Writer, params RepoStarsParams) error { 1430 + params.Active = "overview" 1431 + return p.executeRepo("repo/stars", w, params) 1419 1432 } 1420 1433 1421 1434 type PipelinesParams struct {
+24
appview/pages/templates/repo/stars.html
··· 1 + {{ define "title" }}stars · {{ .RepoInfo.FullName }}{{ end }} 2 + {{ define "repoContent" }} 3 + <div class="flex flex-col gap-4"> 4 + <h2 class="text-sm uppercase font-bold">Starred by</h2> 5 + <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4"> 6 + {{ range .Starrers }} 7 + {{ $handle := resolve .Did }} 8 + <div class="border border-gray-200 dark:border-gray-700 rounded p-4"> 9 + <div class="flex items-center gap-3"> 10 + {{ template "user/fragments/picLink" (list .Did "size-10") }} 11 + <div class="flex-1 min-w-0"> 12 + <a href="/{{ $handle }}" class="block truncate">{{ $handle }}</a> 13 + <p class="text-sm text-gray-500 dark:text-gray-400"> 14 + starred {{ .Created | relTimeFmt }} 15 + </p> 16 + </div> 17 + </div> 18 + </div> 19 + {{ else }} 20 + <p class="text-gray-500 dark:text-gray-400 col-span-3">No stars yet.</p> 21 + {{ end }} 22 + </div> 23 + </div> 24 + {{ end }}
+23
appview/repo/repo.go
··· 1201 1201 } 1202 1202 } 1203 1203 1204 + func (rp *Repo) Stars(w http.ResponseWriter, r *http.Request) { 1205 + l := rp.logger.With("handler", "Stars") 1206 + 1207 + user := rp.oauth.GetMultiAccountUser(r) 1208 + f, err := rp.repoResolver.Resolve(r) 1209 + if err != nil { 1210 + l.Error("failed to resolve source repo", "err", err) 1211 + return 1212 + } 1213 + 1214 + starrers, err := db.GetStars(rp.db, f.RepoAt()) 1215 + if err != nil { 1216 + l.Error("failed to fetch starrers", "err", err, "repoAt", f.RepoAt()) 1217 + return 1218 + } 1219 + 1220 + rp.pages.RepoStars(w, pages.RepoStarsParams{ 1221 + LoggedInUser: user, 1222 + RepoInfo: rp.repoResolver.GetRepoInfo(r, user), 1223 + Starrers: starrers, 1224 + }) 1225 + } 1226 + 1204 1227 // this is used to rollback changes made to the PDS 1205 1228 // 1206 1229 // it is a no-op if the provided ATURI is empty
+2
appview/repo/router.go
··· 45 45 // a file path 46 46 r.Get("/archive/{ref}", rp.DownloadArchive) 47 47 48 + r.Get("/stars", rp.Stars) 49 + 48 50 r.Route("/fork", func(r chi.Router) { 49 51 r.Use(middleware.AuthMiddleware(rp.oauth)) 50 52 r.Get("/", rp.ForkRepo)
+5
appview/state/star.go
··· 36 36 return 37 37 } 38 38 39 + repoName := r.URL.Query().Get("repoName") 40 + 39 41 switch r.Method { 40 42 case http.MethodPost: 41 43 createdAt := time.Now().Format(time.RFC3339) ··· 79 81 IsStarred: true, 80 82 SubjectAt: subjectUri, 81 83 StarCount: starCount, 84 + RepoName: repoName, 82 85 }) 83 86 84 87 return ··· 119 122 IsStarred: false, 120 123 SubjectAt: subjectUri, 121 124 StarCount: starCount, 125 + RepoName: repoName, 122 126 }) 123 127 124 128 return 125 129 } 126 130 127 131 } 132 +