mirror of
https://github.com/rystaf/mlmym.git
synced 2024-11-08 08:04:26 +00:00
remove excess community api calls
This commit is contained in:
parent
3ebf9b3793
commit
d5a96181d2
|
@ -245,19 +245,25 @@ function toggleMyCommunities(e) {
|
|||
return false
|
||||
}
|
||||
mycommunities.className = "open"
|
||||
mycommunities.innerHTML = "<div>loading</div>"
|
||||
request(e.target.href + "&xhr=1", "", function(res) {
|
||||
mycommunities.innerHTML = '<div><a href="'+e.target.href+'">view all »</a>'
|
||||
mycommunities.innerHTML += res
|
||||
}, function() {
|
||||
mycommunities.className = ""
|
||||
})
|
||||
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>'
|
||||
mycommunities.innerHTML += res
|
||||
}, 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
|
||||
|
|
29
state.go
29
state.go
|
@ -59,8 +59,9 @@ type Post struct {
|
|||
}
|
||||
|
||||
type Session struct {
|
||||
UserName string
|
||||
UserID int
|
||||
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
|
||||
}
|
||||
state.GetSite()
|
||||
for _, c := range state.Site.MyUser.MustValue().Follows {
|
||||
state.Communities = append(state.Communities, types.CommunityView{
|
||||
Community: c.Community,
|
||||
Subscribed: "Subscribed",
|
||||
})
|
||||
if state.Site == nil {
|
||||
state.GetSite()
|
||||
}
|
||||
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{
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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 }}
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue