Skip to content

Commit

Permalink
Adding search results refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
boggydigital committed Jan 3, 2024
1 parent 6ef1e25 commit 85726e3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
13 changes: 10 additions & 3 deletions rest/get_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ import (
)

type ResultsViewModel struct {
Videos []*VideoViewModel
SearchQuery string
Refinements []string
Videos []*VideoViewModel
}

func GetResults(w http.ResponseWriter, r *http.Request) {

terms := strings.Split(r.URL.Query().Get("search_query"), " ")
searchQuery := r.URL.Query().Get("search_query")

terms := strings.Split(searchQuery, " ")

sid, err := yt_urls.GetSearchResultsPage(http.DefaultClient, terms...)
if err != nil {
Expand Down Expand Up @@ -43,7 +47,10 @@ func GetResults(w http.ResponseWriter, r *http.Request) {
}
}

rvm := &ResultsViewModel{}
rvm := &ResultsViewModel{
SearchQuery: searchQuery,
Refinements: sid.Refinements,
}

for _, vr := range sid.VideoRenderers() {
rvm.Videos = append(rvm.Videos, videoViewModel(vr.VideoId, vmRdx,
Expand Down
36 changes: 32 additions & 4 deletions rest/templates/results.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,42 @@
<meta name='color-scheme' content='dark light'>
<title>🔻 Search results</title>
{{template "css-shared"}}
<style id="css-results">
ul {
list-style: none;
padding: 0;
display: flex;
flex-direction: row;
row-gap: var(--normal);
column-gap: var(--large);
flex-wrap: wrap;
}

ul li a {
font-size: var(--fs-smaller);
margin: 0;
}
</style>
</head>
<body>

<h1>Search results</h1>
<h1>Search results for '{{.SearchQuery}}'</h1>

<details>
<summary><h2>Refinements</h2></summary>
<ul>
{{range .Refinements}}
<li><a href='/results?search_query={{.}}'>{{.}}</a></li>
{{end}}
</ul>
</details>

{{range .Videos}}
{{template "video" .}}
{{end}}
<details open>
<summary><h2>Videos</h2></summary>
{{range .Videos}}
{{template "video" .}}
{{end}}
</details>

</body>
</html>
Expand Down

0 comments on commit 85726e3

Please sign in to comment.