Monorepo for Tangled tangled.org

appview: repo: better support for empty repos

empty repo template now shows a list of other branches if available

authored by oppi.li and committed by Tangled 50655c66 f11d9cdf

Changed files
+52 -40
appview
pages
state
+1 -2
appview/pages/pages.go
··· 612 612 RepoInfo repoinfo.RepoInfo 613 613 Collaborators []Collaborator 614 614 Active string 615 - Branches []string 616 - DefaultBranch string 615 + Branches []types.Branch 617 616 // TODO: use repoinfo.roles 618 617 IsCollaboratorInviteAllowed bool 619 618 }
+21 -3
appview/pages/templates/repo/empty.html
··· 6 6 {{ end }} 7 7 8 8 {{ define "repoContent" }} 9 - <main> 9 + <main> 10 + {{ if gt (len .BranchesTrunc) 0 }} 11 + <div class="flex flex-col items-center"> 10 12 <p class="text-center pt-5 text-gray-400 dark:text-gray-500"> 11 - This is an empty repository. Push some commits here. 13 + This branch is empty. Other branches in this repository are populated: 12 14 </p> 13 - </main> 15 + <div class="mt-4 grid grid-cols-1 divide-y divide-gray-200 dark:divide-gray-700 rounded border border-gray-200 dark:border-gray-700 w-full md:w-1/2"> 16 + {{ range $br := .BranchesTrunc }} 17 + <a href="/{{ $.RepoInfo.FullName }}/tree/{{$br.Name}}" class="no-underline hover:no-underline"> 18 + <div class="flex items-center justify-between p-2"> 19 + {{ $br.Name }} 20 + <time class="text-gray-500 dark:text-gray-400">{{ timeFmt $br.Commit.Author.When }}</time> 21 + </div> 22 + </a> 23 + {{ end }} 24 + </div> 25 + </div> 26 + {{ else }} 27 + <p class="text-center pt-5 text-gray-400 dark:text-gray-500"> 28 + This is an empty repository. Push some commits here. 29 + </p> 30 + {{ end }} 31 + </main> 14 32 {{ end }} 15 33 16 34 {{ define "repoAfter" }}
+11 -4
appview/pages/templates/repo/settings.html
··· 55 55 <label for="branch">default branch</label> 56 56 <div class="flex gap-2 items-center"> 57 57 <select id="branch" name="branch" required class="p-1 border border-gray-200 bg-white dark:bg-gray-800 dark:text-white dark:border-gray-700"> 58 + <option 59 + value="" 60 + disabled 61 + selected 62 + > 63 + Choose a default branch 64 + </option> 58 65 {{ range .Branches }} 59 66 <option 60 - value="{{ . }}" 67 + value="{{ .Name }}" 61 68 class="py-1" 62 - {{ if eq . $.DefaultBranch }} 69 + {{ if .IsDefault }} 63 70 selected 64 71 {{ end }} 65 72 > 66 - {{ . }} 73 + {{ .Name }} 67 74 </option> 68 75 {{ end }} 69 76 </select> 70 - <button class="btn my-2 flex gap-2 items-center" type="text"> 77 + <button class="btn my-2 flex gap-2 items-center" type="submit"> 71 78 <span>save</span> 72 79 {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }} 73 80 </button>
+19 -31
appview/state/repo.go
··· 981 981 } 982 982 } 983 983 984 - var branchNames []string 985 - var defaultBranch string 986 984 us, err := knotclient.NewUnsignedClient(f.Knot, s.config.Core.Dev) 987 985 if err != nil { 988 986 log.Println("failed to create unsigned client", err) 989 - } else { 990 - resp, err := us.Branches(f.OwnerDid(), f.RepoName) 991 - if err != nil { 992 - log.Println("failed to reach knotserver", err) 993 - } else { 994 - defer resp.Body.Close() 987 + return 988 + } 995 989 996 - body, err := io.ReadAll(resp.Body) 997 - if err != nil { 998 - log.Printf("Error reading response body: %v", err) 999 - } else { 1000 - var result types.RepoBranchesResponse 1001 - err = json.Unmarshal(body, &result) 1002 - if err != nil { 1003 - log.Println("failed to parse response:", err) 1004 - } else { 1005 - for _, branch := range result.Branches { 1006 - branchNames = append(branchNames, branch.Name) 1007 - } 1008 - } 1009 - } 1010 - } 990 + resp, err := us.Branches(f.OwnerDid(), f.RepoName) 991 + if err != nil { 992 + log.Println("failed to reach knotserver", err) 993 + return 994 + } 995 + defer resp.Body.Close() 1011 996 1012 - defaultBranchResp, err := us.DefaultBranch(f.OwnerDid(), f.RepoName) 1013 - if err != nil { 1014 - log.Println("failed to reach knotserver", err) 1015 - } else { 1016 - defaultBranch = defaultBranchResp.Branch 1017 - } 997 + body, err := io.ReadAll(resp.Body) 998 + if err != nil { 999 + log.Printf("Error reading response body: %v", err) 1000 + } 1001 + 1002 + var result types.RepoBranchesResponse 1003 + err = json.Unmarshal(body, &result) 1004 + if err != nil { 1005 + log.Println("failed to parse response:", err) 1018 1006 } 1007 + 1019 1008 s.pages.RepoSettings(w, pages.RepoSettingsParams{ 1020 1009 LoggedInUser: user, 1021 1010 RepoInfo: f.RepoInfo(s, user), 1022 1011 Collaborators: repoCollaborators, 1023 1012 IsCollaboratorInviteAllowed: isCollaboratorInviteAllowed, 1024 - Branches: branchNames, 1025 - DefaultBranch: defaultBranch, 1013 + Branches: result.Branches, 1026 1014 }) 1027 1015 } 1028 1016 }