fix search paging, empty subscribed community search, my subscriptions dropdown. fixes #39

This commit is contained in:
Ryan Stafford 2023-07-23 13:53:02 -04:00
parent ed7d9422d7
commit b6ce673292
10 changed files with 108 additions and 18 deletions

View file

@ -502,21 +502,52 @@ form.nsfw div {
position: relative;
color: #000;
}
#settingspopup {
#mycommunities, #settingspopup {
background-color: white;
border: 1px solid #888;
display: none;
position: absolute;
z-index: 100;
}
#mycommunities {
top: 17px;
padding: 5px 0px;
border-width: 0px 1px 1px 0px;
}
#mycommunities div {
margin: 0px 5px;
}
#mycommunities a:first-child {
text-align: right;
}
#mycommunities a {
text-decoration: none;
color: #369;
text-transform: uppercase;
font-size: 9px;
display: block;
padding: 0px 3px;
}
.dark #mycommunities a {
color: #8cb3d9;
}
.dark #mycommunities a:hover {
background-color: #3e3e3e;
}
#mycommunities a:hover {
background-color: #c7def7;
}
#settingspopup {
right: 10px;
top: 45px;
}
#settingspopup form {
margin: 0px;
}
.dark #settingspopup {
.dark #settingspopup, .dark #mycommunities {
background-color: #262626;
}
#settingspopup.open {
#settingspopup.open, #mycommunities.open {
display: inline-block;
}
.expando.open{
@ -807,11 +838,11 @@ nav .communities a.more {
color: orangered !important;
}
nav a {
nav .communities a {
text-decoration: none;
color: black;
}
nav > a:hover {
nav .title a:hover {
text-decoration: underline;
}

View file

@ -237,6 +237,24 @@ function formSubmit(e) {
return false
}
function toggleMyCommunities(e) {
e.preventDefault()
var mycommunities = document.getElementById("mycommunities")
if (mycommunities.className.indexOf("open") > -1) {
mycommunities.className = ""
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 = ""
})
return false
}
function openSettings(e) {
e.preventDefault()
var settings = document.getElementById("settingspopup")
@ -332,6 +350,9 @@ function setup() {
if (settings = document.getElementById("opensettings")) {
settings.addEventListener("click", openSettings)
}
if (settings = document.getElementById("openmycommunities")) {
settings.addEventListener("click", toggleMyCommunities)
}
if (hidechildren = document.getElementById("hidechildren")){
hidechildren.addEventListener("click", hideAllChildComments)
}

View file

@ -416,6 +416,12 @@ func GetFrontpage(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
}
}
func GetCommunities(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
r.URL.Path = "/search"
r.URL.RawQuery = "searchtype=Communities"
http.Redirect(w, r, r.URL.String(), 301)
}
func ResolveId(r *http.Request, class string, id string, host string) string {
remoteAddr := r.RemoteAddr
if r.Header.Get("CF-Connecting-IP") != "" {
@ -1284,6 +1290,7 @@ func GetRouter() *httprouter.Router {
router.POST("/:host/create_post", middleware(UserOp))
router.GET("/:host/create_community", middleware(GetCreateCommunity))
router.POST("/:host/create_community", middleware(UserOp))
router.GET("/:host/communities", middleware(GetCommunities))
} else {
router.ServeFiles("/_/static/*filepath", http.Dir("public"))
router.GET("/", middleware(GetFrontpage))
@ -1315,6 +1322,7 @@ func GetRouter() *httprouter.Router {
router.POST("/create_post", middleware(UserOp))
router.GET("/create_community", middleware(GetCreateCommunity))
router.POST("/create_community", middleware(UserOp))
router.GET("/communities", middleware(GetCommunities))
}
return router
}

View file

@ -527,7 +527,24 @@ func (state *State) GetPosts() {
func (state *State) Search(searchtype string) {
if state.Query == "" && searchtype == "Communities" {
if state.Listing == "Subscribed" {
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",
})
}
sort.Slice(state.Communities, func(a, b int) bool {
return state.Communities[a].Community.Name < state.Communities[b].Community.Name
})
return
}
resp, err := state.Client.Communities(context.Background(), types.ListCommunities{
Type: types.NewOptional(types.ListingType(state.Listing)),
Sort: types.NewOptional(types.SortType(state.Sort)),
Limit: types.NewOptional(int64(25)),
Page: types.NewOptional(int64(state.Page)),

View file

@ -1,17 +1,17 @@
<div class="community">
<form method="POST" class="member {{ membership .Subscribed }}">
<input name="op" type="submit" value="{{ membership .Subscribed}}">
<input type="hidden" name="communityid" value ="{{.Community.ID}}">
<input type="hidden" name="communityid" value ="{{ .Community.ID }}">
</form>
<span class="title"><a href="{{localize .Community.ActorID}}">c/{{fullcname .Community}}: {{.Community.Title}}</a></span>
<span class="title"><a href="{{ if .Community.Local }}./c/{{.Community.Name}}{{else}}{{ localize .Community.ActorID }}{{end}}">c/{{fullcname .Community}}: {{.Community.Title}}</a></span>
<div class="details">
{{ if .Community.Description.IsValid }}
<div class="description">
{{markdown "" .Community.Description.String}}
{{ markdown "" .Community.Description.String }}
</div>
{{ end }}
<div class="gray">
{{printer .Counts.Subscribers}} subscribers,
{{ if .Counts.Subscribers }}{{ printer .Counts.Subscribers }} subscribers,{{end}}
a community founded {{ humanize .Community.Published.Time }}
</div>
</div>

View file

@ -2,7 +2,7 @@
<head>
<title>{{ if and .Community (ne .Community.CommunityView.Community.Title "")}}{{.Community.CommunityView.Community.Title}}{{else if ne .CommunityName ""}}/c/{{.CommunityName}}{{ else if .User}}overview for {{.User.PersonView.Person.Name}}{{else}}{{ host .Host }}{{end}}</title>
<link rel="shortcut icon" href="/{{.Host}}/icon.jpg">
<link rel="stylesheet" href="/_/static/style.css?v=25">
<link rel="stylesheet" href="/_/static/style.css?v=27">
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body {{ if .Dark }}class="dark"{{end}}>
@ -59,6 +59,6 @@
{{ template "sidebar.html" . }}
</main>
{{ end }}
<script src="/_/static/utils.js?v=20"></script>
<script src="/_/static/utils.js?v=21"></script>
</body>
</html>

View file

@ -3,7 +3,7 @@
<title>{{if and .Posts .PostID }}{{ (index .Posts 0).Post.Name}} : {{.CommunityName}}{{else if and .Community (ne .Community.CommunityView.Community.Title "")}}{{.Community.CommunityView.Community.Title}}{{else if ne .CommunityName ""}}/c/{{.CommunityName}}{{ else if .User}}overview for {{.User.PersonView.Person.Name}}{{else}}{{ host .Host }}{{end}}</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="shortcut icon" href="/{{.Host}}/icon.jpg">
<link rel="stylesheet" href="/_/static/style.css?v=26">
<link rel="stylesheet" href="/_/static/style.css?v=27">
</head>
<body{{ if .Dark }} class="dark"{{end}}>
<noscript>
@ -34,6 +34,7 @@
{{ if or (ne .Query "") .Communities }}
<form class="search" method="GET">
<input type="hidden" name="sort" value="{{.Sort}}">
<input type="hidden" name="listingType" value="{{.Listing}}">
<div>search</div>
<div class="query">
<input type="text" name="q" value="{{.Query}}">
@ -139,7 +140,7 @@
{{ end }}
{{ end }}
<script src="/_/static/utils.js?v=20"></script>
<script src="/_/static/utils.js?v=21"></script>
{{ template "sidebar.html" . }}
</main>
{{ end }}

View file

@ -1,5 +1,8 @@
<nav>
<div class="communities">
{{ if .Session }}
<a id="openmycommunities" href="/{{.Host}}/search?searchtype=Communities&listingType=Subscribed&sort=TopMonth&page=0">my communities ▼</a>
{{ end }}
<a href="/{{.Host}}">home</a>
<span> - </span>
<a href="/{{.Host}}?listingType=All">all</a>
@ -9,8 +12,9 @@
<a href="/{{$host}}/c/{{fullcname $c.Community}}">{{$c.Community.Name}}</a>
<span> - </span>
{{ end }}
<a href="/{{$host}}/search?searchtype=Communities&sort=TopAll" class="more">more »</a>
<a href="/{{$host}}/search?searchtype=Communities&sort=TopMonth" class="more">more »</a>
</div>
<div id="mycommunities"></div>
<div class="right">
{{ if .Session }}
<a href="/{{.Host}}/u/{{ .Session.UserName}}">{{ .Session.UserName }}</a>

View file

@ -1,9 +1,8 @@
{{ $host := .Host }}
<div class="{{ if .User }}user {{end}}side">
{{ if not .SearchType }}
<form method="GET" action="/{{.Host}}/search">
<input type="text" placeholder="search" name="q" value="{{.Query}}">
<input type="text" placeholder="search" name="q" value="">
{{ if .User }}
<input type="hidden" name="username" value="{{.UserName}}">
{{ else if .Community }}
@ -11,7 +10,6 @@
{{ end }}
<input type="hidden" name="sort" value="New">
</form>
{{ end }}
{{ if .User }}
<h1>{{ .User.PersonView.Person.Name }}</h1>

View file

@ -1,11 +1,21 @@
{{ $state := . }}
{{ if or .PostID .CommentID }}
{{ range $i, $comment := .Comments }}
{{ template "comment.html" $comment }}
{{ end }}
{{ else if .Activities }}
{{ template "activities.html" . }}
{{ else }}
{{ else if .Posts }}
{{ range $post := .Posts }}
{{ template "post.html" $post }}
{{ end }}
{{ else if .Communities }}
{{ range .Communities }}
{{ if not $state.Page }}
<a href="/{{ $state.Host}}/{{ if .Community.Local }}c/{{.Community.Name}}{{else}}{{ localize .Community.ActorID }}{{end}}">{{fullcname .Community }}</a>
{{ else }}
{{ template "community.html" . }}
{{ end }}
{{ end }}
{{ else }}
{{ end }}