Add users search page
This commit is contained in:
parent
8079d44781
commit
ae749a19d2
@ -17,6 +17,8 @@ type SearchPageData struct {
|
|||||||
SearchText string
|
SearchText string
|
||||||
SortOrder persistence.SortOrder
|
SortOrder persistence.SortOrder
|
||||||
SortOrderOptions []string
|
SortOrderOptions []string
|
||||||
|
IsUsersSearch bool
|
||||||
|
UsersList []scraper.User
|
||||||
// TODO: fill out the search text in the search bar as well (needs modifying the base template)
|
// TODO: fill out the search text in the search bar as well (needs modifying the base template)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +46,14 @@ func (t SearchPageData) FocusedTweetID() scraper.TweetID {
|
|||||||
return scraper.TweetID(0)
|
return scraper.TweetID(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *Application) SearchUsers(w http.ResponseWriter, r *http.Request) {
|
||||||
|
ret := NewSearchPageData()
|
||||||
|
ret.IsUsersSearch = true
|
||||||
|
ret.SearchText = strings.Trim(r.URL.Path, "/")
|
||||||
|
ret.UsersList = app.Profile.SearchUsers(ret.SearchText)
|
||||||
|
app.buffered_render_tweet_page(w, "tpl/search.tpl", ret)
|
||||||
|
}
|
||||||
|
|
||||||
func (app *Application) Search(w http.ResponseWriter, r *http.Request) {
|
func (app *Application) Search(w http.ResponseWriter, r *http.Request) {
|
||||||
app.traceLog.Printf("'Search' handler (path: %q)", r.URL.Path)
|
app.traceLog.Printf("'Search' handler (path: %q)", r.URL.Path)
|
||||||
|
|
||||||
@ -60,6 +70,12 @@ func (app *Application) Search(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle users search
|
||||||
|
if r.URL.Query().Get("type") == "users" {
|
||||||
|
app.SearchUsers(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Handle "@username"
|
// Handle "@username"
|
||||||
if search_text[0] == '@' {
|
if search_text[0] == '@' {
|
||||||
http.Redirect(w, r, fmt.Sprintf("/%s", search_text[1:]), 302)
|
http.Redirect(w, r, fmt.Sprintf("/%s", search_text[1:]), 302)
|
||||||
|
@ -222,7 +222,10 @@ h3 {
|
|||||||
.user-feed-header .profile-image {
|
.user-feed-header .profile-image {
|
||||||
width: 8em;
|
width: 8em;
|
||||||
}
|
}
|
||||||
.user-feed-header a.user-feed-tab {
|
.tabs-container {
|
||||||
|
outline: 1px solid var(--color-outline-gray);
|
||||||
|
}
|
||||||
|
.tabs-container a.tab {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 1.1em;
|
font-size: 1.1em;
|
||||||
@ -230,11 +233,11 @@ h3 {
|
|||||||
color: var(--color-twitter-text-gray);
|
color: var(--color-twitter-text-gray);
|
||||||
padding: 0.8em;
|
padding: 0.8em;
|
||||||
}
|
}
|
||||||
.user-feed-header a.user-feed-tab.active-tab {
|
.tabs-container a.tab.active-tab {
|
||||||
color: var(--color-twitter-blue);
|
color: var(--color-twitter-blue);
|
||||||
border-bottom: 0.2em solid var(--color-twitter-blue);
|
border-bottom: 0.2em solid var(--color-twitter-blue);
|
||||||
}
|
}
|
||||||
.user-feed-header a.user-feed-tab:hover {
|
.tabs-container a.tab:hover {
|
||||||
color: var(--color-twitter-blue);
|
color: var(--color-twitter-blue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,7 +351,6 @@ ul.quick-links {
|
|||||||
}
|
}
|
||||||
.user-feed-header-info-container {
|
.user-feed-header-info-container {
|
||||||
padding: 2em;
|
padding: 2em;
|
||||||
margin-bottom: 0.1em;
|
|
||||||
border-bottom: 1px solid var(--color-outline-gray);
|
border-bottom: 1px solid var(--color-outline-gray);
|
||||||
}
|
}
|
||||||
.timeline .tweet, .quoted-tweet .tweet {
|
.timeline .tweet, .quoted-tweet .tweet {
|
||||||
@ -600,9 +602,30 @@ ul.dropdown-items {
|
|||||||
.users-list-container {
|
.users-list-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 1em;
|
|
||||||
padding: 1em;
|
|
||||||
}
|
}
|
||||||
.users-list-container .author-info .profile-image {
|
.users-list-container .author-info .profile-image {
|
||||||
width: 4em;
|
width: 4em;
|
||||||
}
|
}
|
||||||
|
.users-list-container .user {
|
||||||
|
border-color: var(--color-twitter-off-white-dark);
|
||||||
|
border-bottom-style: solid;
|
||||||
|
border-width: 1px;
|
||||||
|
padding: 1em;
|
||||||
|
}
|
||||||
|
.users-list-container .user p.bio {
|
||||||
|
margin: 0 5.3em;
|
||||||
|
font-size: 0.9em;
|
||||||
|
color: var(--color-twitter-text-gray);
|
||||||
|
}
|
||||||
|
.sort-order-container {
|
||||||
|
padding: 1em 1em 1em 3em;
|
||||||
|
margin-bottom: -0.5em;
|
||||||
|
border-bottom: 1px solid var(--color-outline-gray);
|
||||||
|
}
|
||||||
|
.sort-order-container select {
|
||||||
|
text-transform: capitalize;
|
||||||
|
margin: 0 1em;
|
||||||
|
}
|
||||||
|
.sort-order-container .sort-order-label {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
10
internal/webserver/tpl/includes/list.tpl
Normal file
10
internal/webserver/tpl/includes/list.tpl
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{{define "list"}}
|
||||||
|
<div class="users-list-container">
|
||||||
|
{{range .}}
|
||||||
|
<div class="user">
|
||||||
|
{{template "author-info" .}}
|
||||||
|
<p class="bio">{{.Bio}}</p>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
{{end}}
|
@ -1,9 +1,5 @@
|
|||||||
{{define "title"}}Followed Users{{end}}
|
{{define "title"}}Followed Users{{end}}
|
||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
<div class="users-list-container">
|
{{template "list" .}}
|
||||||
{{range .}}
|
|
||||||
{{template "author-info" .}}
|
|
||||||
{{end}}
|
|
||||||
</div>
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -2,13 +2,36 @@
|
|||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
<div class="search-header">
|
<div class="search-header">
|
||||||
<h2>Search results: {{.SearchText}}</h2>
|
<h2 style="text-align: center">Search results: {{.SearchText}}</h2>
|
||||||
<select name="sort-order" style="text-transform: capitalize;" hx-get="#" hx-target="body" hx-push-url="true">
|
|
||||||
|
<div class="row tabs-container">
|
||||||
|
<a
|
||||||
|
class="tab unstyled-link {{if (not .IsUsersSearch)}}active-tab{{end}}"
|
||||||
|
href="?type=tweets"
|
||||||
|
>
|
||||||
|
<span class="tab-inner">Tweets</span>
|
||||||
|
</a>
|
||||||
|
<a
|
||||||
|
class="tab unstyled-link {{if .IsUsersSearch}}active-tab{{end}}"
|
||||||
|
href="?type=users"
|
||||||
|
>
|
||||||
|
<span class="tab-inner">Users</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{if .IsUsersSearch}}
|
||||||
|
{{template "list" .UsersList}}
|
||||||
|
{{else}}
|
||||||
|
<div class="sort-order-container">
|
||||||
|
<span class="sort-order-label">order:</span>
|
||||||
|
<select name="sort-order" hx-get="#" hx-target="body" hx-push-url="true">
|
||||||
{{range .SortOrderOptions}}
|
{{range .SortOrderOptions}}
|
||||||
<option
|
<option
|
||||||
value="{{.}}"
|
value="{{.}}"
|
||||||
{{if (eq ($.SortOrder.String) .)}} selected {{end}}
|
|
||||||
style="text-transform: capitalize;"
|
style="text-transform: capitalize;"
|
||||||
|
{{if (eq ($.SortOrder.String) .)}}
|
||||||
|
selected
|
||||||
|
{{end}}
|
||||||
>{{.}}</option>
|
>{{.}}</option>
|
||||||
{{end}}
|
{{end}}
|
||||||
</select>
|
</select>
|
||||||
@ -17,3 +40,4 @@
|
|||||||
{{template "timeline" .}}
|
{{template "timeline" .}}
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
@ -58,18 +58,18 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row user-feed-tabs-container">
|
<div class="row tabs-container">
|
||||||
<a class="user-feed-tab unstyled-link {{if (eq .FeedType "")}}active-tab{{end}}" href="/{{$user.Handle}}">
|
<a class="tab unstyled-link {{if (eq .FeedType "")}}active-tab{{end}}" href="/{{$user.Handle}}">
|
||||||
<span class="user-feed-tab-inner">Tweets and replies</span>
|
<span class="tab-inner">Tweets and replies</span>
|
||||||
</a>
|
</a>
|
||||||
<a class="user-feed-tab unstyled-link {{if (eq .FeedType "without_replies")}}active-tab{{end}}" href="/{{$user.Handle}}/without_replies">
|
<a class="tab unstyled-link {{if (eq .FeedType "without_replies")}}active-tab{{end}}" href="/{{$user.Handle}}/without_replies">
|
||||||
<span class="user-feed-tab-inner">Tweets</span>
|
<span class="tab-inner">Tweets</span>
|
||||||
</a>
|
</a>
|
||||||
<a class="user-feed-tab unstyled-link {{if (eq .FeedType "media")}}active-tab{{end}}" href="/{{$user.Handle}}/media">
|
<a class="tab unstyled-link {{if (eq .FeedType "media")}}active-tab{{end}}" href="/{{$user.Handle}}/media">
|
||||||
<span class="user-feed-tab-inner">Media</span>
|
<span class="tab-inner">Media</span>
|
||||||
</a>
|
</a>
|
||||||
<a class="user-feed-tab unstyled-link {{if (eq .FeedType "likes")}}active-tab{{end}}" href="/{{$user.Handle}}/likes">
|
<a class="tab unstyled-link {{if (eq .FeedType "likes")}}active-tab{{end}}" href="/{{$user.Handle}}/likes">
|
||||||
<span class="user-feed-tab-inner">Likes</span>
|
<span class="tab-inner">Likes</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user