Monorepo for Tangled tangled.org

appview/state: handle empty vanity stat kinds

allows removing vanity stat kinds

Signed-off-by: oppiliappan <me@oppi.li>

oppi.li 5e5769e2 a82cd010

verified
+30 -10
+2
appview/db/profile.go
··· 453 case models.VanityStatStarCount: 454 query = `select count(id) from stars where subject_at like 'at://' || ? || '%'` 455 args = append(args, did) 456 default: 457 return 0, fmt.Errorf("invalid vanity stat kind: %s", stat) 458 }
··· 453 case models.VanityStatStarCount: 454 query = `select count(id) from stars where subject_at like 'at://' || ? || '%'` 455 args = append(args, did) 456 + case models.VanityStatNone: 457 + return 0, nil 458 default: 459 return 0, fmt.Errorf("invalid vanity stat kind: %s", stat) 460 }
+1 -1
appview/ingester.go
··· 317 var stats [2]models.VanityStat 318 for i, s := range record.Stats { 319 if i < 2 { 320 - stats[i].Kind = models.VanityStatKind(s) 321 } 322 } 323
··· 317 var stats [2]models.VanityStat 318 for i, s := range record.Stats { 319 if i < 2 { 320 + stats[i].Kind = models.ParseVanityStatKind(s) 321 } 322 } 323
+24 -1
appview/models/profile.go
··· 60 VanityStatClosedIssueCount VanityStatKind = "closed-issue-count" 61 VanityStatRepositoryCount VanityStatKind = "repository-count" 62 VanityStatStarCount VanityStatKind = "star-count" 63 ) 64 65 func (v VanityStatKind) String() string { 66 switch v { 67 case VanityStatMergedPRCount: ··· 78 return "Repositories" 79 case VanityStatStarCount: 80 return "Stars Received" 81 } 82 - return "" 83 } 84 85 type VanityStat struct {
··· 60 VanityStatClosedIssueCount VanityStatKind = "closed-issue-count" 61 VanityStatRepositoryCount VanityStatKind = "repository-count" 62 VanityStatStarCount VanityStatKind = "star-count" 63 + VanityStatNone VanityStatKind = "" 64 ) 65 66 + func ParseVanityStatKind(s string) VanityStatKind { 67 + switch s { 68 + case "merged-pull-request-count": 69 + return VanityStatMergedPRCount 70 + case "closed-pull-request-count": 71 + return VanityStatClosedPRCount 72 + case "open-pull-request-count": 73 + return VanityStatOpenPRCount 74 + case "open-issue-count": 75 + return VanityStatOpenIssueCount 76 + case "closed-issue-count": 77 + return VanityStatClosedIssueCount 78 + case "repository-count": 79 + return VanityStatRepositoryCount 80 + case "star-count": 81 + return VanityStatStarCount 82 + default: 83 + return VanityStatNone 84 + } 85 + } 86 + 87 func (v VanityStatKind) String() string { 88 switch v { 89 case VanityStatMergedPRCount: ··· 100 return "Repositories" 101 case VanityStatStarCount: 102 return "Stars Received" 103 + default: 104 + return "" 105 } 106 } 107 108 type VanityStat struct {
+1 -1
appview/pages/templates/user/fragments/editBio.html
··· 110 {{ $id := index . 0 }} 111 {{ $stat := index . 1 }} 112 <select class="stat-group w-full p-1 border border-gray-200 bg-white dark:bg-gray-800 dark:text-white dark:border-gray-700 text-sm" id="stat{{$id}}" name="stat{{$id}}"> 113 - <option value="">choose stat</option> 114 {{ $stats := assoc 115 "merged-pull-request-count" "Merged PR Count" 116 "closed-pull-request-count" "Closed PR Count"
··· 110 {{ $id := index . 0 }} 111 {{ $stat := index . 1 }} 112 <select class="stat-group w-full p-1 border border-gray-200 bg-white dark:bg-gray-800 dark:text-white dark:border-gray-700 text-sm" id="stat{{$id}}" name="stat{{$id}}"> 113 + <option value="">Choose Stat</option> 114 {{ $stats := assoc 115 "merged-pull-request-count" "Merged PR Count" 116 "closed-pull-request-count" "Closed PR Count"
+2 -7
appview/state/profile.go
··· 550 stat0 := r.FormValue("stat0") 551 stat1 := r.FormValue("stat1") 552 553 - if stat0 != "" { 554 - profile.Stats[0].Kind = models.VanityStatKind(stat0) 555 - } 556 - 557 - if stat1 != "" { 558 - profile.Stats[1].Kind = models.VanityStatKind(stat1) 559 - } 560 561 if err := db.ValidateProfile(s.db, profile); err != nil { 562 log.Println("invalid profile", err)
··· 550 stat0 := r.FormValue("stat0") 551 stat1 := r.FormValue("stat1") 552 553 + profile.Stats[0].Kind = models.ParseVanityStatKind(stat0) 554 + profile.Stats[1].Kind = models.ParseVanityStatKind(stat1) 555 556 if err := db.ValidateProfile(s.db, profile); err != nil { 557 log.Println("invalid profile", err)