mirror of
https://github.com/rystaf/mlmym.git
synced 2024-11-08 16:15:33 +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
|
return false
|
||||||
}
|
}
|
||||||
mycommunities.className = "open"
|
mycommunities.className = "open"
|
||||||
mycommunities.innerHTML = "<div>loading</div>"
|
if (mycommunities.innerHTML == "") {
|
||||||
request(e.target.href + "&xhr=1", "", function(res) {
|
mycommunities.innerHTML = "<div>loading</div>"
|
||||||
mycommunities.innerHTML = '<div><a href="'+e.target.href+'">view all »</a>'
|
request(e.target.href + "&xhr=1", "", function(res) {
|
||||||
mycommunities.innerHTML += res
|
mycommunities.innerHTML = '<div><a href="'+e.target.href+'">view all »</a>'
|
||||||
}, function() {
|
mycommunities.innerHTML += res
|
||||||
mycommunities.className = ""
|
}, function() {
|
||||||
})
|
mycommunities.className = ""
|
||||||
|
})
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
function openSettings(e) {
|
function openSettings(e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
var settings = document.getElementById("settingspopup")
|
var settings = document.getElementById("settingspopup")
|
||||||
|
if (settings.className == "open") {
|
||||||
|
settings.className = ""
|
||||||
|
return false
|
||||||
|
}
|
||||||
settings.className = "open"
|
settings.className = "open"
|
||||||
request(e.target.href + "?xhr=1", "", function(res) {
|
request(e.target.href + "?xhr=1", "", function(res) {
|
||||||
settings.innerHTML = res
|
settings.innerHTML = res
|
||||||
|
|
29
state.go
29
state.go
|
@ -59,8 +59,9 @@ type Post struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Session struct {
|
type Session struct {
|
||||||
UserName string
|
UserName string
|
||||||
UserID int
|
UserID int
|
||||||
|
Communities []types.CommunityView
|
||||||
}
|
}
|
||||||
|
|
||||||
type State struct {
|
type State struct {
|
||||||
|
@ -267,6 +268,18 @@ func (state *State) GetSite() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
state.Site = resp
|
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) {
|
func (state *State) GetComment(commentid int) {
|
||||||
|
@ -532,16 +545,10 @@ func (state *State) Search(searchtype string) {
|
||||||
if state.Page > 1 {
|
if state.Page > 1 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
state.GetSite()
|
if state.Site == nil {
|
||||||
for _, c := range state.Site.MyUser.MustValue().Follows {
|
state.GetSite()
|
||||||
state.Communities = append(state.Communities, types.CommunityView{
|
|
||||||
Community: c.Community,
|
|
||||||
Subscribed: "Subscribed",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
sort.Slice(state.Communities, func(a, b int) bool {
|
state.Communities = state.Session.Communities
|
||||||
return state.Communities[a].Community.Name < state.Communities[b].Community.Name
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resp, err := state.Client.Communities(context.Background(), types.ListCommunities{
|
resp, err := state.Client.Communities(context.Background(), types.ListCommunities{
|
||||||
|
|
|
@ -59,6 +59,6 @@
|
||||||
{{ template "sidebar.html" . }}
|
{{ template "sidebar.html" . }}
|
||||||
</main>
|
</main>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<script src="/_/static/utils.js?v=21"></script>
|
<script src="/_/static/utils.js?v=22"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -140,7 +140,7 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
<script src="/_/static/utils.js?v=21"></script>
|
<script src="/_/static/utils.js?v=22"></script>
|
||||||
{{ template "sidebar.html" . }}
|
{{ template "sidebar.html" . }}
|
||||||
</main>
|
</main>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
{{ $state := . }}
|
||||||
<nav>
|
<nav>
|
||||||
<div class="communities">
|
<div class="communities">
|
||||||
{{ if .Session }}
|
{{ if .Session }}
|
||||||
|
@ -14,7 +15,14 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<a href="/{{$host}}/search?searchtype=Communities&sort=TopMonth" class="more">more »</a>
|
<a href="/{{$host}}/search?searchtype=Communities&sort=TopMonth" class="more">more »</a>
|
||||||
</div>
|
</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">
|
<div class="right">
|
||||||
{{ if .Session }}
|
{{ if .Session }}
|
||||||
<a href="/{{.Host}}/u/{{ .Session.UserName}}">{{ .Session.UserName }}</a>
|
<a href="/{{.Host}}/u/{{ .Session.UserName}}">{{ .Session.UserName }}</a>
|
||||||
|
|
Loading…
Reference in a new issue