From 24822eb5bed5fb637d0f44fc40d7c448c2bc1e62 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Tue, 26 Aug 2025 20:31:36 +0100 Subject: [PATCH] appview/pages: rework profile overview page to use tabs model Change-Id: nzqnkmzrkyxuuplozvtoltwvrzskzmvn Signed-off-by: oppiliappan --- appview/db/profile.go | 14 ++ appview/db/punchcard.go | 8 +- appview/pages/pages.go | 37 +++-- .../templates/user/fragments/editBio.html | 2 +- .../templates/user/fragments/profileCard.html | 2 - .../user/{profile.html => overview.html} | 134 +++++------------- 6 files changed, 84 insertions(+), 113 deletions(-) rename appview/pages/templates/user/{profile.html => overview.html} (64%) diff --git a/appview/db/profile.go b/appview/db/profile.go index 894d890b..7de3bfa5 100644 --- a/appview/db/profile.go +++ b/appview/db/profile.go @@ -22,6 +22,20 @@ type ProfileTimeline struct { ByMonth []ByMonth } +func (p *ProfileTimeline) IsEmpty() bool { + if p == nil { + return true + } + + for _, m := range p.ByMonth { + if !m.IsEmpty() { + return false + } + } + + return true +} + type ByMonth struct { RepoEvents []RepoEvent IssueEvents IssueEvents diff --git a/appview/db/punchcard.go b/appview/db/punchcard.go index 62a386ee..91dde121 100644 --- a/appview/db/punchcard.go +++ b/appview/db/punchcard.go @@ -29,8 +29,8 @@ type Punchcard struct { Punches []Punch } -func MakePunchcard(e Execer, filters ...filter) (Punchcard, error) { - punchcard := Punchcard{} +func MakePunchcard(e Execer, filters ...filter) (*Punchcard, error) { + punchcard := &Punchcard{} now := time.Now() startOfYear := time.Date(now.Year(), 1, 1, 0, 0, 0, 0, time.UTC) endOfYear := time.Date(now.Year(), 12, 31, 0, 0, 0, 0, time.UTC) @@ -63,7 +63,7 @@ func MakePunchcard(e Execer, filters ...filter) (Punchcard, error) { rows, err := e.Query(query, args...) if err != nil { - return punchcard, err + return nil, err } defer rows.Close() @@ -72,7 +72,7 @@ func MakePunchcard(e Execer, filters ...filter) (Punchcard, error) { var date string var count sql.NullInt64 if err := rows.Scan(&date, &count); err != nil { - return punchcard, err + return nil, err } punch.Date, err = time.Parse(time.DateOnly, date) diff --git a/appview/pages/pages.go b/appview/pages/pages.go index e9abc83f..f43d007c 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -409,21 +409,40 @@ func (p *Pages) ForkRepo(w io.Writer, params ForkRepoParams) error { return p.execute("repo/fork", w, params) } -type ProfileHomePageParams struct { - LoggedInUser *oauth.User - Repos []db.Repo - CollaboratingRepos []db.Repo - ProfileTimeline *db.ProfileTimeline - Card ProfileCard - Punchcard db.Punchcard -} - type ProfileCard struct { UserDid string UserHandle string FollowStatus db.FollowStatus FollowersCount int FollowingCount int + Punchcard *db.Punchcard + Profile *db.Profile + Active string +} + +func (p *ProfileCard) GetTabs() [][]string { + tabs := [][]string{ + {"overview", "overview", "square-chart-gantt"}, + {"repos", "repos", "book-marked"}, + {"starred", "starred", "star"}, + } + + return tabs +} + +type ProfileOverviewParams struct { + LoggedInUser *oauth.User + Repos []db.Repo + CollaboratingRepos []db.Repo + ProfileTimeline *db.ProfileTimeline + Card *ProfileCard + Active string +} + +func (p *Pages) ProfileOverview(w io.Writer, params ProfileOverviewParams) error { + params.Active = "overview" + return p.executeProfile("user/overview", w, params) +} Profile *db.Profile } diff --git a/appview/pages/templates/user/fragments/editBio.html b/appview/pages/templates/user/fragments/editBio.html index 042acd94..7c2730c6 100644 --- a/appview/pages/templates/user/fragments/editBio.html +++ b/appview/pages/templates/user/fragments/editBio.html @@ -13,7 +13,7 @@ diff --git a/appview/pages/templates/user/fragments/profileCard.html b/appview/pages/templates/user/fragments/profileCard.html index ced8fd1c..eae96f60 100644 --- a/appview/pages/templates/user/fragments/profileCard.html +++ b/appview/pages/templates/user/fragments/profileCard.html @@ -1,6 +1,5 @@ {{ define "user/fragments/profileCard" }} {{ $userIdent := didOrHandle .UserDid .UserHandle }} -
@@ -85,7 +84,6 @@
-
{{ end }} {{ define "followerFollowing" }} diff --git a/appview/pages/templates/user/profile.html b/appview/pages/templates/user/overview.html similarity index 64% rename from appview/pages/templates/user/profile.html rename to appview/pages/templates/user/overview.html index 7696aab8..0ba7b3b4 100644 --- a/appview/pages/templates/user/profile.html +++ b/appview/pages/templates/user/overview.html @@ -1,65 +1,45 @@ {{ define "title" }}{{ or .Card.UserHandle .Card.UserDid }}{{ end }} -{{ define "extrameta" }} - - - - -{{ end }} - -{{ define "content" }} -
-
-
- {{ template "user/fragments/profileCard" .Card }} - {{ block "punchcard" .Punchcard }} {{ end }} -
-
-
-
- {{ block "ownRepos" . }}{{ end }} - {{ block "collaboratingRepos" . }}{{ end }} -
-
-
- {{ block "profileTimeline" . }}{{ end }} +{{ define "profileContent" }} +
+
+ {{ block "ownRepos" . }}{{ end }} + {{ block "collaboratingRepos" . }}{{ end }}
-
+
+
+ {{ block "profileTimeline" . }}{{ end }} +
{{ end }} {{ define "profileTimeline" }} -

ACTIVITY

+

ACTIVITY

+ {{ if .ProfileTimeline.IsEmpty }} +

This user does not have any activity yet.

+ {{ end }} + {{ with .ProfileTimeline }} {{ range $idx, $byMonth := .ByMonth }} {{ with $byMonth }} -
- {{ if eq $idx 0 }} - - {{ else }} - {{ $s := "s" }} - {{ if eq $idx 1 }} - {{ $s = "" }} - {{ end }} -

{{$idx}} month{{$s}} ago

- {{ end }} + {{ if not .IsEmpty }} +
+

+ {{ if eq $idx 0 }} + this month + {{ else }} + {{$idx}} month{{if ne $idx 1}}s{{end}} ago + {{ end }} +

- {{ if .IsEmpty }} -
- No activity for this month -
- {{ else }} -
- {{ block "repoEvents" .RepoEvents }} {{ end }} - {{ block "issueEvents" .IssueEvents }} {{ end }} - {{ block "pullEvents" .PullEvents }} {{ end }} +
+ {{ block "repoEvents" .RepoEvents }} {{ end }} + {{ block "issueEvents" .IssueEvents }} {{ end }} + {{ block "pullEvents" .PullEvents }} {{ end }} +
{{ end }} -
- {{ end }} - {{ else }} -

This user does not have any activity yet.

{{ end }} {{ end }}
@@ -232,30 +212,28 @@ {{ define "ownRepos" }}
-
+
PINNED REPOS - - view all {{ i "chevron-right" "w-4 h-4" }} - {{ if and .LoggedInUser (eq .LoggedInUser.Did .Card.UserDid) }} - {{ end }}
{{ range .Repos }} +
{{ template "user/fragments/repoCard" (list $ . false) }} +
{{ else }} -

This user does not have any repos yet.

+

This user does not have any pinned repos.

{{ end }}
@@ -264,10 +242,12 @@ {{ define "collaboratingRepos" }} {{ if gt (len .CollaboratingRepos) 0 }}
-

COLLABORATING ON

+

COLLABORATING ON

{{ range .CollaboratingRepos }} +
{{ template "user/fragments/repoCard" (list $ . true) }} +
{{ else }}

This user is not collaborating.

{{ end }} @@ -276,43 +256,3 @@ {{ end }} {{ end }} -{{ define "punchcard" }} - {{ $now := now }} -
-

- PUNCHCARD - - {{ .Total | int64 | commaFmt }} commits - -

-
-
- {{ range .Punches }} - {{ $count := .Count }} - {{ $theme := "bg-gray-200 dark:bg-gray-700 size-[4px]" }} - {{ if lt $count 1 }} - {{ $theme = "bg-gray-200 dark:bg-gray-700 size-[4px]" }} - {{ else if lt $count 2 }} - {{ $theme = "bg-green-200 dark:bg-green-900 size-[5px]" }} - {{ else if lt $count 4 }} - {{ $theme = "bg-green-300 dark:bg-green-800 size-[5px]" }} - {{ else if lt $count 8 }} - {{ $theme = "bg-green-400 dark:bg-green-700 size-[6px]" }} - {{ else }} - {{ $theme = "bg-green-500 dark:bg-green-600 size-[7px]" }} - {{ end }} - - {{ if .Date.After $now }} - {{ $theme = "border border-gray-200 dark:border-gray-700 size-[4px]" }} - {{ end }} -
-
-
-
- {{ end }} -
-
-
-{{ end }} -- 2.43.0