mirror of
https://github.com/rystaf/mlmym.git
synced 2024-11-22 05:36:16 +00:00
search all, url
This commit is contained in:
parent
8dcbb2665e
commit
4a862b4e03
|
@ -947,14 +947,19 @@ func Search(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|||
state.GetSite()
|
||||
}
|
||||
m, _ := url.ParseQuery(r.URL.RawQuery)
|
||||
state.SearchType = "Posts"
|
||||
state.SearchType = "All"
|
||||
if len(m["searchtype"]) > 0 {
|
||||
switch m["searchtype"][0] {
|
||||
case "Posts":
|
||||
state.SearchType = "Posts"
|
||||
case "Comments":
|
||||
state.SearchType = "Comments"
|
||||
case "Communities":
|
||||
state.SearchType = "Communities"
|
||||
case "Url":
|
||||
state.SearchType = "Url"
|
||||
}
|
||||
|
||||
}
|
||||
state.Search(state.SearchType)
|
||||
Render(w, "index.html", state)
|
||||
|
|
13
state.go
13
state.go
|
@ -157,14 +157,14 @@ func (s State) Unknown() string {
|
|||
func (p State) SortBy(v string) string {
|
||||
var q string
|
||||
if p.Query != "" || p.SearchType == "Communities" {
|
||||
q = "q=" + p.Query + "&communityname=" + p.CommunityName + "&username=" + p.UserName + "&searchtype=" + p.SearchType + "&"
|
||||
q = "q=" + url.QueryEscape(p.Query) + "&communityname=" + p.CommunityName + "&username=" + p.UserName + "&searchtype=" + p.SearchType + "&"
|
||||
}
|
||||
return "?" + q + "sort=" + v + "&listingType=" + p.Listing
|
||||
}
|
||||
func (p State) ListBy(v string) string {
|
||||
var q string
|
||||
if p.Query != "" || p.SearchType == "Communities" {
|
||||
q = "q=" + p.Query + "&communityname=" + p.CommunityName + "&username=" + p.UserName + "&searchtype=" + p.SearchType + "&"
|
||||
q = "q=" + url.QueryEscape(p.Query) + "&communityname=" + p.CommunityName + "&username=" + p.UserName + "&searchtype=" + p.SearchType + "&"
|
||||
}
|
||||
return "?" + q + "sort=" + p.Sort + "&listingType=" + v
|
||||
}
|
||||
|
@ -625,10 +625,14 @@ func (state *State) Search(searchtype string) {
|
|||
return
|
||||
} else {
|
||||
for i, p := range resp.Posts {
|
||||
state.Posts = append(state.Posts, Post{
|
||||
post := Post{
|
||||
PostView: p,
|
||||
Rank: (state.Page-1)*25 + i + 1,
|
||||
State: state,
|
||||
}
|
||||
state.Activities = append(state.Activities, Activity{
|
||||
Timestamp: p.Post.Published,
|
||||
Post: &post,
|
||||
})
|
||||
}
|
||||
for _, c := range resp.Comments {
|
||||
|
@ -641,6 +645,9 @@ func (state *State) Search(searchtype string) {
|
|||
Comment: &comment,
|
||||
})
|
||||
}
|
||||
sort.Slice(state.Activities, func(i, j int) bool {
|
||||
return state.Activities[i].Timestamp.After(state.Activities[j].Timestamp.Time)
|
||||
})
|
||||
state.Communities = resp.Communities
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,8 +34,10 @@
|
|||
{{ if ne .SearchType "Communities" }}
|
||||
<div>
|
||||
<select name="searchtype">
|
||||
<option value="All"{{ if eq .SearchType "All" }} selected{{ end }}>all</option>
|
||||
<option value="Posts"{{ if eq .SearchType "Posts" }} selected{{ end }}>posts</option>
|
||||
<option value="Comments"{{ if eq .SearchType "Comments" }} selected{{ end }}>comments</option>
|
||||
<option value="Url"{{ if eq .SearchType "Url" }} selected{{ end }}>url</option>
|
||||
</select>
|
||||
<label>from
|
||||
<input type="text" placeholder="everywhere" name="communityname" value="{{.CommunityName}}"></label>
|
||||
|
|
Loading…
Reference in a new issue