remove excess community api calls

This commit is contained in:
Ryan Stafford 2023-07-23 22:12:01 -04:00
parent 3ebf9b3793
commit d5a96181d2
5 changed files with 42 additions and 21 deletions

View file

@ -245,6 +245,7 @@ function toggleMyCommunities(e) {
return false
}
mycommunities.className = "open"
if (mycommunities.innerHTML == "") {
mycommunities.innerHTML = "<div>loading</div>"
request(e.target.href + "&xhr=1", "", function(res) {
mycommunities.innerHTML = '<div><a href="'+e.target.href+'">view all »</a>'
@ -252,12 +253,17 @@ function toggleMyCommunities(e) {
}, function() {
mycommunities.className = ""
})
}
return false
}
function openSettings(e) {
e.preventDefault()
var settings = document.getElementById("settingspopup")
if (settings.className == "open") {
settings.className = ""
return false
}
settings.className = "open"
request(e.target.href + "?xhr=1", "", function(res) {
settings.innerHTML = res

View file

@ -61,6 +61,7 @@ type Post struct {
type Session struct {
UserName string
UserID int
Communities []types.CommunityView
}
type State struct {
@ -267,6 +268,18 @@ func (state *State) GetSite() {
return
}
state.Site = resp
if !state.Site.MyUser.IsValid() {
return
}
for _, c := range state.Site.MyUser.MustValue().Follows {
state.Session.Communities = append(state.Session.Communities, types.CommunityView{
Community: c.Community,
Subscribed: "Subscribed",
})
}
sort.Slice(state.Session.Communities, func(a, b int) bool {
return state.Session.Communities[a].Community.Name < state.Session.Communities[b].Community.Name
})
}
func (state *State) GetComment(commentid int) {
@ -532,16 +545,10 @@ func (state *State) Search(searchtype string) {
if state.Page > 1 {
return
}
if state.Site == nil {
state.GetSite()
for _, c := range state.Site.MyUser.MustValue().Follows {
state.Communities = append(state.Communities, types.CommunityView{
Community: c.Community,
Subscribed: "Subscribed",
})
}
sort.Slice(state.Communities, func(a, b int) bool {
return state.Communities[a].Community.Name < state.Communities[b].Community.Name
})
state.Communities = state.Session.Communities
return
}
resp, err := state.Client.Communities(context.Background(), types.ListCommunities{

View file

@ -59,6 +59,6 @@
{{ template "sidebar.html" . }}
</main>
{{ end }}
<script src="/_/static/utils.js?v=21"></script>
<script src="/_/static/utils.js?v=22"></script>
</body>
</html>

View file

@ -140,7 +140,7 @@
{{ end }}
{{ end }}
<script src="/_/static/utils.js?v=21"></script>
<script src="/_/static/utils.js?v=22"></script>
{{ template "sidebar.html" . }}
</main>
{{ end }}

View file

@ -1,3 +1,4 @@
{{ $state := . }}
<nav>
<div class="communities">
{{ if .Session }}
@ -14,7 +15,14 @@
{{ end }}
<a href="/{{$host}}/search?searchtype=Communities&sort=TopMonth" class="more">more »</a>
</div>
<div id="mycommunities"></div>
<div id="mycommunities">
{{- if and .Session .Session.Communities }}
<a href="/{{.Host}}/search?searchtype=Communities&listingType=Subscribed&sort=TopMonth&page=0">view all »</a>
{{ range .Session.Communities }}
<a href="/{{ $state.Host}}/{{ if .Community.Local }}c/{{.Community.Name}}{{else}}{{ localize .Community.ActorID }}{{end}}">{{fullcname .Community }}</a>
{{ end }}
{{ end -}}
</div>
<div class="right">
{{ if .Session }}
<a href="/{{.Host}}/u/{{ .Session.UserName}}">{{ .Session.UserName }}</a>