diff --git a/public/style.css b/public/style.css index 6340191..4cef8b7 100644 --- a/public/style.css +++ b/public/style.css @@ -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; } diff --git a/public/utils.js b/public/utils.js index 802058e..04c8a92 100644 --- a/public/utils.js +++ b/public/utils.js @@ -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 = "
loading
" + request(e.target.href + "&xhr=1", "", function(res) { + mycommunities.innerHTML = '
view all »' + 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) } diff --git a/routes.go b/routes.go index 88b5371..a0e4da3 100644 --- a/routes.go +++ b/routes.go @@ -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 } diff --git a/state.go b/state.go index c5a44b8..630a9e1 100644 --- a/state.go +++ b/state.go @@ -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)), diff --git a/templates/community.html b/templates/community.html index 42d3f26..287e868 100644 --- a/templates/community.html +++ b/templates/community.html @@ -1,17 +1,17 @@
- +
- c/{{fullcname .Community}}: {{.Community.Title}} + c/{{fullcname .Community}}: {{.Community.Title}}
{{ if .Community.Description.IsValid }}
- {{markdown "" .Community.Description.String}} + {{ markdown "" .Community.Description.String }}
{{ end }}
- {{printer .Counts.Subscribers}} subscribers, + {{ if .Counts.Subscribers }}{{ printer .Counts.Subscribers }} subscribers,{{end}} a community founded {{ humanize .Community.Published.Time }}
diff --git a/templates/frontpage.html b/templates/frontpage.html index 7ca8f0a..14f746f 100644 --- a/templates/frontpage.html +++ b/templates/frontpage.html @@ -2,7 +2,7 @@ {{ 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}} - + @@ -59,6 +59,6 @@ {{ template "sidebar.html" . }} {{ end }} - + diff --git a/templates/main.html b/templates/main.html index 110bd75..a110926 100644 --- a/templates/main.html +++ b/templates/main.html @@ -3,7 +3,7 @@ {{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}} - +