appview/pages: add dashboard to strings page #415

merged
opened by oppi.li targeting master from push-potvrpwlpwsl
Changed files
+58 -20
appview
pages
templates
strings
user
fragments
state
-1
appview/pages/pages.go
···
UserDid string
UserHandle string
FollowStatus db.FollowStatus
-
AvatarUri string
Followers int
Following int
+57
appview/pages/templates/strings/dashboard.html
···
+
{{ define "title" }}strings by {{ or .Card.UserHandle .Card.UserDid }}{{ end }}
+
+
{{ define "extrameta" }}
+
<meta property="og:title" content="{{ or .Card.UserHandle .Card.UserDid }}" />
+
<meta property="og:type" content="profile" />
+
<meta property="og:url" content="https://tangled.sh/{{ or .Card.UserHandle .Card.UserDid }}" />
+
<meta property="og:description" content="{{ or .Card.Profile.Description .Card.UserHandle .Card.UserDid }}" />
+
{{ end }}
+
+
+
{{ define "content" }}
+
<div class="grid grid-cols-1 md:grid-cols-11 gap-4">
+
<div class="md:col-span-3 order-1 md:order-1">
+
{{ template "user/fragments/profileCard" .Card }}
+
</div>
+
<div id="all-strings" class="md:col-span-8 order-2 md:order-2">
+
{{ block "allStrings" . }}{{ end }}
+
</div>
+
</div>
+
{{ end }}
+
+
{{ define "allStrings" }}
+
<p class="text-sm font-bold p-2 dark:text-white">ALL STRINGS</p>
+
<div id="strings" class="grid grid-cols-1 gap-4 mb-6">
+
{{ range .Strings }}
+
{{ template "singleString" (list $ .) }}
+
{{ else }}
+
<p class="px-6 dark:text-white">This user does not have any strings yet.</p>
+
{{ end }}
+
</div>
+
{{ end }}
+
+
{{ define "singleString" }}
+
{{ $root := index . 0 }}
+
{{ $s := index . 1 }}
+
<div class="py-4 px-6 drop-shadow-sm rounded bg-white dark:bg-gray-800">
+
<div class="font-medium dark:text-white flex gap-2 items-center">
+
<a href="/strings/{{ or $root.Card.UserHandle $root.Card.UserDid }}/{{ $s.Rkey }}">{{ $s.Filename }}</a>
+
</div>
+
{{ with $s.Description }}
+
<div class="text-gray-600 dark:text-gray-300 text-sm">
+
{{ . }}
+
</div>
+
{{ end }}
+
+
{{ $stat := $s.Stats }}
+
<div class="text-gray-400 pt-4 text-sm font-mono inline-flex gap-2 mt-auto">
+
<span>{{ $stat.LineCount }} line{{if ne $stat.LineCount 1}}s{{end}}</span>
+
<span class="select-none [&:before]:content-['·']"></span>
+
{{ with $s.Edited }}
+
<span>edited {{ template "repo/fragments/shortTimeAgo" . }}</span>
+
{{ else }}
+
{{ template "repo/fragments/shortTimeAgo" $s.Created }}
+
{{ end }}
+
</div>
+
</div>
+
{{ end }}
+1 -3
appview/pages/templates/user/fragments/profileCard.html
···
<div class="bg-white dark:bg-gray-800 px-6 py-4 rounded drop-shadow-sm max-h-fit">
<div class="grid grid-cols-3 md:grid-cols-1 gap-1 items-center">
<div id="avatar" class="col-span-1 flex justify-center items-center">
-
{{ if .AvatarUri }}
<div class="w-3/4 aspect-square relative">
-
<img class="absolute inset-0 w-full h-full object-cover rounded-full p-2" src="{{ .AvatarUri }}" />
+
<img class="absolute inset-0 w-full h-full object-cover rounded-full p-2" src="{{ fullAvatar .UserDid }}" />
</div>
-
{{ end }}
</div>
<div class="col-span-2">
<p title="{{ didOrHandle .UserDid .UserHandle }}"
-16
appview/state/profile.go
···
package state
import (
-
"crypto/hmac"
-
"crypto/sha256"
-
"encoding/hex"
"fmt"
"log"
"net/http"
···
log.Println("failed to get punchcard for did", "did", ident.DID.String(), "err", err)
}
-
profileAvatarUri := s.GetAvatarUri(ident.Handle.String())
s.pages.ProfilePage(w, pages.ProfilePageParams{
LoggedInUser: loggedInUser,
Repos: pinnedRepos,
···
Card: pages.ProfileCard{
UserDid: ident.DID.String(),
UserHandle: ident.Handle.String(),
-
AvatarUri: profileAvatarUri,
Profile: profile,
FollowStatus: followStatus,
Followers: followers,
···
log.Printf("getting follow stats repos for %s: %s", ident.DID.String(), err)
}
-
profileAvatarUri := s.GetAvatarUri(ident.Handle.String())
-
s.pages.ReposPage(w, pages.ReposPageParams{
LoggedInUser: loggedInUser,
Repos: repos,
···
Card: pages.ProfileCard{
UserDid: ident.DID.String(),
UserHandle: ident.Handle.String(),
-
AvatarUri: profileAvatarUri,
Profile: profile,
FollowStatus: followStatus,
Followers: followers,
···
})
}
-
func (s *State) GetAvatarUri(handle string) string {
-
secret := s.config.Avatar.SharedSecret
-
h := hmac.New(sha256.New, []byte(secret))
-
h.Write([]byte(handle))
-
signature := hex.EncodeToString(h.Sum(nil))
-
return fmt.Sprintf("%s/%s/%s", s.config.Avatar.Host, signature, handle)
-
}
-
func (s *State) UpdateProfileBio(w http.ResponseWriter, r *http.Request) {
user := s.oauth.GetUser(r)