Monorepo for Tangled

appview/pages: split star button to include starrers link

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

pdewey.com e984df66 3c41bb79

verified
+38 -20
+1
appview/pages/pages.go
··· 676 676 SubjectAt syntax.ATURI 677 677 StarCount int 678 678 HxSwapOob bool 679 + StarsHref string 679 680 } 680 681 681 682 func (p *Pages) StarBtnFragment(w io.Writer, params StarBtnFragmentParams) error {
+31 -19
appview/pages/templates/fragments/starBtn.html
··· 1 1 {{ define "fragments/starBtn" }} 2 2 {{/* NOTE: this fragment is always replaced with hx-swap-oob */}} 3 - <button 3 + <div 4 4 id="starBtn" 5 - class="btn disabled:opacity-50 disabled:cursor-not-allowed flex gap-2 items-center group" 5 + class="flex w-full items-stretch overflow-hidden rounded border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 shadow-sm" 6 6 data-star-subject-at="{{ .SubjectAt }}" 7 - {{ if .IsStarred }} 8 - hx-delete="/star?subject={{ .SubjectAt }}&countHint={{ .StarCount }}" 9 - {{ else }} 10 - hx-post="/star?subject={{ .SubjectAt }}&countHint={{ .StarCount }}" 11 - {{ end }} 12 7 {{ if .HxSwapOob }}hx-swap-oob='outerHTML:#starBtn[data-star-subject-at="{{ .SubjectAt }}"]'{{ end }} 13 - 14 - hx-trigger="click" 15 - hx-disabled-elt="#starBtn" 16 8 > 17 - {{ if .IsStarred }} 18 - {{ i "star" "w-4 h-4 fill-current inline group-[.htmx-request]:hidden" }} 19 - {{ else }} 20 - {{ i "star" "w-4 h-4 inline group-[.htmx-request]:hidden" }} 9 + <button 10 + class="flex flex-1 justify-center gap-2 items-center px-2 group disabled:opacity-50 disabled:cursor-not-allowed hover:bg-gray-50 dark:hover:bg-gray-700" 11 + {{ if .IsStarred }} 12 + hx-delete="/star?subject={{ .SubjectAt }}&countHint={{ .StarCount }}&starsHref={{ .StarsHref }}" 13 + {{ else }} 14 + hx-post="/star?subject={{ .SubjectAt }}&countHint={{ .StarCount }}&starsHref={{ .StarsHref }}" 15 + {{ end }} 16 + hx-trigger="click" 17 + hx-disabled-elt="this" 18 + > 19 + {{ if .IsStarred }} 20 + {{ i "star" "w-4 h-4 fill-current inline group-[.htmx-request]:hidden" }} 21 + {{ else }} 22 + {{ i "star" "w-4 h-4 inline group-[.htmx-request]:hidden" }} 23 + {{ end }} 24 + {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }} 25 + <span class="text-sm"> 26 + {{ .StarCount }} 27 + </span> 28 + </button> 29 + {{ if .StarsHref }} 30 + <a 31 + href="{{ .StarsHref }}" 32 + class="flex items-center px-2 no-underline hover:no-underline border-l border-gray-200 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-700" 33 + title="Starred by" 34 + > 35 + {{ i "users" "w-3 h-3" }} 36 + </a> 21 37 {{ end }} 22 - {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }} 23 - <span class="text-sm"> 24 - {{ .StarCount }} 25 - </span> 26 - </button> 38 + </div> 27 39 {{ end }}
+2 -1
appview/pages/templates/layouts/repobase.html
··· 115 115 {{ template "fragments/starBtn" 116 116 (dict "SubjectAt" .RepoInfo.RepoAt 117 117 "IsStarred" .RepoInfo.IsStarred 118 - "StarCount" .RepoInfo.Stats.StarCount) }} 118 + "StarCount" .RepoInfo.Stats.StarCount 119 + "StarsHref" (printf "/%s/stars" .RepoInfo.FullName)) }} 119 120 <a 120 121 class="btn text-sm no-underline hover:no-underline flex items-center gap-2 group" 121 122 hx-boost="true"
+4
appview/state/star.go
··· 30 30 return 31 31 } 32 32 33 + starsHref := r.URL.Query().Get("starsHref") 34 + 33 35 client, err := s.oauth.AuthorizedClient(r) 34 36 if err != nil { 35 37 log.Println("failed to authorize client", err) ··· 79 81 IsStarred: true, 80 82 SubjectAt: subjectUri, 81 83 StarCount: starCount, 84 + StarsHref: starsHref, 82 85 }) 83 86 84 87 return ··· 119 122 IsStarred: false, 120 123 SubjectAt: subjectUri, 121 124 StarCount: starCount, 125 + StarsHref: starsHref, 122 126 }) 123 127 124 128 return