Monorepo for Tangled

appview/profile: show dummy profile when no tangled profile

+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" ··· 580 589 profile, err := db.GetProfile(s.db, user.Active.Did) 581 590 if err != nil { 582 591 log.Printf("getting profile data for %s: %s", user.Active.Did, err) 592 + } 593 + if profile == nil { 594 + profile = &models.Profile{Did: user.Active.Did} 583 595 } 584 596 585 597 i := 0 ··· 681 693 if err != nil { 682 694 log.Printf("getting profile data for %s: %s", user.Active.Did, err) 683 695 } 696 + if profile == nil { 697 + profile = &models.Profile{Did: user.Active.Did} 698 + } 684 699 685 700 s.pages.EditBioFragment(w, pages.EditBioParams{ 686 701 LoggedInUser: user, ··· 694 709 profile, err := db.GetProfile(s.db, user.Active.Did) 695 710 if err != nil { 696 711 log.Printf("getting profile data for %s: %s", user.Active.Did, err) 712 + } 713 + if profile == nil { 714 + profile = &models.Profile{Did: user.Active.Did} 697 715 } 698 716 699 717 repos, err := db.GetRepos(s.db, 0, orm.FilterEq("did", user.Active.Did)) ··· 821 839 profile, err := db.GetProfile(s.db, user.Did) 822 840 if err != nil { 823 841 l.Warn("getting profile data from DB", "err", err) 842 + } 843 + if profile == nil { 824 844 profile = &models.Profile{Did: user.Did} 825 845 } 826 846 profile.Avatar = uploadBlobResp.Blob.Ref.String() ··· 897 917 profile, err := db.GetProfile(s.db, user.Did) 898 918 if err != nil { 899 919 l.Warn("getting profile data from DB", "err", err) 920 + } 921 + if profile == nil { 900 922 profile = &models.Profile{Did: user.Did} 901 923 } 902 924 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 )