Monorepo for Tangled

appview/profile: show dummy profile when no tangled profile

authored by lewis.moe and committed by tangled.org f569d2be b0d4690d

+40 -6
+1 -3
appview/db/profile.go
··· 360 360 did, 361 361 ).Scan(&avatar, &profile.Description, &includeBluesky, &profile.Location, &pronouns) 362 362 if err == sql.ErrNoRows { 363 - profile := models.Profile{} 364 - profile.Did = did 365 - return &profile, nil 363 + return nil, nil 366 364 } 367 365 368 366 if err != nil {
+2 -2
appview/oauth/handler.go
··· 199 199 did := sessData.AccountDID.String() 200 200 l := o.Logger.With("did", did) 201 201 202 - _, err := db.GetProfile(o.Db, did) 203 - if err == nil { 202 + profile, _ := db.GetProfile(o.Db, did) 203 + if profile != nil { 204 204 l.Debug("profile already exists in DB") 205 205 return 206 206 }
+1
appview/pages/pages.go
··· 523 523 524 524 type ProfileCard struct { 525 525 UserDid string 526 + HasProfile bool 526 527 FollowStatus models.FollowStatus 527 528 Punchcard *models.Punchcard 528 529 Profile *models.Profile
+13
appview/pages/templates/layouts/profilebase.html
··· 18 18 {{ end }} 19 19 20 20 {{ define "content" }} 21 + {{ if not .Card.HasProfile }} 22 + <section class="bg-white dark:bg-gray-800 px-2 py-6 md:p-6 rounded w-full dark:text-white drop-shadow-sm"> 23 + <div class="flex items-center gap-6 p-4"> 24 + <img class="w-28 h-28 shrink-0 object-cover rounded-full" src="{{ profileAvatarUrl .Card.Profile "" }}" /> 25 + <div> 26 + <p class="text-lg font-bold">{{ resolve .Card.UserDid }}</p> 27 + <p class="text-gray-700 dark:text-gray-300 mt-2">This user hasn't joined Tangled yet.</p> 28 + <p class="text-sm text-gray-500 dark:text-gray-400 mt-1">Let them know we're waiting for them!</p> 29 + </div> 30 + </div> 31 + </section> 32 + {{ else }} 21 33 {{ template "profileTabs" . }} 22 34 <section class="bg-white dark:bg-gray-800 px-2 py-6 md:p-6 rounded w-full dark:text-white drop-shadow-sm"> 23 35 <div class="grid grid-cols-1 md:grid-cols-11 gap-4"> ··· 35 47 {{ block "profileContent" . }} {{ end }} 36 48 </div> 37 49 </section> 50 + {{ end }} 38 51 {{ end }} 39 52 40 53 {{ define "profileTabs" }}
+22
appview/state/profile.go
··· 58 58 return nil, fmt.Errorf("failed to get profile: %w", err) 59 59 } 60 60 61 + hasProfile := profile != nil 62 + if !hasProfile { 63 + profile = &models.Profile{Did: did} 64 + } 65 + 61 66 repoCount, err := db.CountRepos(s.db, orm.FilterEq("did", did)) 62 67 if err != nil { 63 68 return nil, fmt.Errorf("failed to get repo count: %w", err) ··· 98 103 99 104 return &pages.ProfileCard{ 100 105 UserDid: did, 106 + HasProfile: hasProfile, 101 107 Profile: profile, 102 108 FollowStatus: followStatus, 103 109 Stats: pages.ProfileStats{ ··· 533 539 if err != nil { 534 540 log.Printf("getting profile data for %s: %s", user.Active.Did, err) 535 541 } 542 + if profile == nil { 543 + profile = &models.Profile{Did: user.Active.Did} 544 + } 536 545 537 546 profile.Description = r.FormValue("description") 538 547 profile.IncludeBluesky = r.FormValue("includeBluesky") == "on" ··· 575 584 profile, err := db.GetProfile(s.db, user.Active.Did) 576 585 if err != nil { 577 586 log.Printf("getting profile data for %s: %s", user.Active.Did, err) 587 + } 588 + if profile == nil { 589 + profile = &models.Profile{Did: user.Active.Did} 578 590 } 579 591 580 592 i := 0 ··· 676 688 if err != nil { 677 689 log.Printf("getting profile data for %s: %s", user.Active.Did, err) 678 690 } 691 + if profile == nil { 692 + profile = &models.Profile{Did: user.Active.Did} 693 + } 679 694 680 695 s.pages.EditBioFragment(w, pages.EditBioParams{ 681 696 LoggedInUser: user, ··· 689 704 profile, err := db.GetProfile(s.db, user.Active.Did) 690 705 if err != nil { 691 706 log.Printf("getting profile data for %s: %s", user.Active.Did, err) 707 + } 708 + if profile == nil { 709 + profile = &models.Profile{Did: user.Active.Did} 692 710 } 693 711 694 712 repos, err := db.GetRepos(s.db, 0, orm.FilterEq("did", user.Active.Did)) ··· 816 834 profile, err := db.GetProfile(s.db, user.Did) 817 835 if err != nil { 818 836 l.Warn("getting profile data from DB", "err", err) 837 + } 838 + if profile == nil { 819 839 profile = &models.Profile{Did: user.Did} 820 840 } 821 841 profile.Avatar = uploadBlobResp.Blob.Ref.String() ··· 892 912 profile, err := db.GetProfile(s.db, user.Did) 893 913 if err != nil { 894 914 l.Warn("getting profile data from DB", "err", err) 915 + } 916 + if profile == nil { 895 917 profile = &models.Profile{Did: user.Did} 896 918 } 897 919 profile.Avatar = ""
+1 -1
appview/state/state.go
··· 126 126 wrapper, 127 127 false, 128 128 129 - // in-memory filter is inapplicalble to appview so 129 + // in-memory filter is inapplicable to appview so 130 130 // we'll never log dids anyway. 131 131 false, 132 132 )