Skip to content

Commit 94d8fc8

Browse files
committed
Change the search button click behavior and always show topics
Signed-off-by: Kai Wagner <kai.wagner@percona.com>
1 parent cded2c9 commit 94d8fc8

File tree

6 files changed

+75
-16
lines changed

6 files changed

+75
-16
lines changed

app/assets/stylesheets/components/sidebar.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@
88
margin-bottom: var(--spacing-8);
99
}
1010

11+
.sidebar-section.is-search-focus .sidebar-heading {
12+
background: linear-gradient(135deg, var(--color-bg-sidebar-header), var(--color-primary-2));
13+
border-radius: 999px;
14+
box-shadow: var(--shadow-sm);
15+
}
16+
17+
.sidebar-section.is-search-focus .sidebar-content {
18+
border-radius: 16px;
19+
box-shadow: 0 12px 24px rgba(15, 23, 42, 0.08);
20+
background: var(--color-bg-card);
21+
border: var(--border-width) solid var(--color-primary-200);
22+
}
23+
24+
.sidebar-section.is-search-focus .search-input {
25+
border-color: var(--color-primary-300);
26+
box-shadow: var(--shadow-focus);
27+
}
28+
29+
.sidebar-section.is-search-focus .search-button {
30+
border-color: var(--color-primary-300);
31+
background: var(--color-bg-hover);
32+
}
33+
1134
.sidebar .search-input {
1235
width: 100%;
1336
padding: var(--spacing-3) var(--spacing-4);

app/controllers/topics_controller.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,16 @@ def read_all
9595
def search
9696
@search_query = params[:q].to_s.strip
9797

98-
if @search_query.present?
99-
load_cached_search_results
100-
else
101-
base_query = topics_base_query(search_query: @search_query)
102-
apply_cursor_pagination(base_query)
103-
@new_topics_count = 0
98+
if @search_query.blank?
99+
respond_to do |format|
100+
format.html { redirect_to topics_path(anchor: "search") }
101+
format.turbo_stream { redirect_to topics_path(anchor: "search") }
102+
end
103+
return
104104
end
105105

106+
load_cached_search_results
107+
106108
preload_commitfest_summaries
107109
preload_participation_flags if user_signed_in?
108110

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Controller } from "@hotwired/stimulus"
2+
3+
export default class extends Controller {
4+
static targets = ["input", "section"]
5+
6+
connect() {
7+
this._onHashChange = this.focusIfHash.bind(this)
8+
this._onTurboLoad = this.focusIfHash.bind(this)
9+
this._onLinkClick = this.handleLinkClick.bind(this)
10+
window.addEventListener("hashchange", this._onHashChange)
11+
document.addEventListener("turbo:load", this._onTurboLoad)
12+
document.addEventListener("click", this._onLinkClick)
13+
this.focusIfHash()
14+
}
15+
16+
disconnect() {
17+
window.removeEventListener("hashchange", this._onHashChange)
18+
document.removeEventListener("turbo:load", this._onTurboLoad)
19+
document.removeEventListener("click", this._onLinkClick)
20+
}
21+
22+
focusIfHash() {
23+
const isSearch = window.location.hash === "#search"
24+
if (this.hasSectionTarget) {
25+
this.sectionTarget.classList.toggle("is-search-focus", isSearch)
26+
}
27+
if (isSearch && this.hasInputTarget) {
28+
this.inputTarget.focus()
29+
}
30+
}
31+
32+
handleLinkClick(event) {
33+
if (event.defaultPrevented) return
34+
const link = event.target.closest('a[href="#search"]')
35+
if (!link) return
36+
window.location.hash = "search"
37+
setTimeout(() => this.focusIfHash(), 0)
38+
}
39+
}

app/views/layouts/application.html.slim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ html data-theme="light"
4242
span.tagline PostgreSQL Hackers Archive
4343
.nav-links
4444
= link_to "Topics", topics_path, class: "nav-link"
45-
= link_to "Search", search_topics_path, class: "nav-link"
45+
- search_link = content_for?(:search_sidebar) ? "#search" : topics_path(anchor: "search")
46+
= link_to "Search", search_link, class: "nav-link"
4647
= link_to "Statistics", stats_path, class: "nav-link"
4748
.nav-right
4849
button.nav-link.theme-toggle type="button" aria-label="Toggle theme" data-controller="theme" data-action="click->theme#toggle"

app/views/topics/_sidebar.html.slim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
- content_for :sidebar do
2+
- content_for :search_sidebar, true
23
.sidebar
34

45
- if user_signed_in?
@@ -8,11 +9,10 @@
89
button.mark-aware-button data-action="click->topics-aware#markVisibleAware" Mark displayed threads aware
910
button.mark-aware-button.secondary data-action="click->topics-aware#markAllAware" Mark everything up to now aware
1011

11-
.sidebar-section
12-
h3.sidebar-heading Search
12+
.sidebar-section#search data-controller="search-focus" data-search-focus-target="section"
1313
.sidebar-search.sidebar-content
1414
= form_with url: search_topics_path, method: :get, local: true do |f|
15-
= f.text_field :q, placeholder: "Search topics and messages...", class: "search-input", value: search_query
15+
= f.text_field :q, placeholder: "Search topics and messages...", class: "search-input", value: search_query, data: { "search-focus-target": "input" }
1616
= f.submit "Search", class: "search-button"
1717

1818
.sidebar-section

app/views/topics/search.html.slim

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,3 @@
3434
h3 No results found
3535
p Try different search terms or browse all topics
3636
= link_to "Browse All Topics", topics_path, class: "browse-link"
37-
38-
- else
39-
.search-help
40-
h3 Search the PostgreSQL Hackers Archive
41-
p Enter keywords to search through topic titles and message content
42-
= link_to "Browse All Topics", topics_path, class: "browse-link"

0 commit comments

Comments
 (0)