Skip to content

Commit b32a865

Browse files
committed
Rename topics_controller.js to more generic name
This is because the methods in this controller could be re-used on the other views where we want to implement search functionalities.
1 parent df54086 commit b32a865

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Controller } from "@hotwired/stimulus";
2+
import { useDebounce } from "stimulus-use";
3+
4+
export default class extends Controller {
5+
static targets = ["search", "choose"];
6+
static debounces = ["submit"];
7+
8+
connect() {
9+
useDebounce(this, { wait: 300 });
10+
}
11+
12+
submit() {
13+
this.searchTarget.requestSubmit();
14+
}
15+
16+
chooseOption() {
17+
this.chooseTarget.requestSubmit();
18+
}
19+
}

app/javascript/controllers/topics_controller.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

app/views/topics/_choose_provider.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<%= form_for :provider , url: provider_settings_path, method: :put, data: { controller: "topics", topics_target: "chooseForm", turbo_frame: "topics", turbo_action: "advance" } do |f| %>
1+
<%= form_for :provider , url: provider_settings_path, method: :put, data: { controller: "search", search_target: "choose", turbo_frame: "topics", turbo_action: "advance" } do |f| %>
22
<div class="form-body">
33
<div class="row">
44
<div class="col-md-6 col-12">
55
<div class="form-group">
66
<%= f.label :provider %>
7-
<%= f.select :id, options_from_collection_for_select(providers, :id, :name), { prompt: "Change provider" }, class: "form-select", data: { action: "change->topics#chooseProvider" } %>
7+
<%= f.select :id, options_from_collection_for_select(providers, :id, :name), { prompt: "Change provider" }, class: "form-select", data: { action: "change->search#chooseOption" } %>
88
</div>
99
</div>
1010
</div>

app/views/topics/_search.html.erb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,43 @@
44
</div>
55
<div class="card-content">
66
<div class="card-body">
7-
<%= form_for :search, url: topics_path, method: :get, data: { controller: "topics", topics_target: "searchForm", turbo_frame: "topic-list", turbo_action: "advance" } do |f| %>
7+
<%= form_for :search, url: topics_path, method: :get, data: { controller: "search", search_target: "search", turbo_frame: "topic-list", turbo_action: "advance" } do |f| %>
88
<div class="form-body">
99
<div class="row">
1010
<div class="col-12">
1111
<div class="form-group">
1212
<%= f.label :query %>
13-
<%= f.text_field :query, value: params[:query], class: "form-control", data: { action: "input->topics#searchTopics" } %>
13+
<%= f.text_field :query, value: params[:query], class: "form-control", data: { action: "input->search#submit" } %>
1414
</div>
1515
</div>
1616
<div class="col-md-6 col-12">
1717
<div class="form-group">
1818
<%= f.label :language %>
19-
<%= f.select :language_id, options_from_collection_for_select(languages, :id, :name, params[:provider_id]), { prompt: "Select language" }, class: "form-select", data: { action: "change->topics#searchTopics" } %>
19+
<%= f.select :language_id, options_from_collection_for_select(languages, :id, :name, params[:provider_id]), { prompt: "Select language" }, class: "form-select", data: { action: "change->search#submit" } %>
2020
</div>
2121
</div>
2222
<div class="col-md-3 col-12">
2323
<div class="form-group">
2424
<%= f.label :year %>
25-
<%= f.select :year, options_for_select((Date.today.year-10..Date.today.year).to_a, params[:year]), { prompt: "Select year" }, class: "form-select", data: { action: "change->topics#searchTopics" } %>
25+
<%= f.select :year, options_for_select((Date.today.year-10..Date.today.year).to_a, params[:year]), { prompt: "Select year" }, class: "form-select", data: { action: "change->search#submit" } %>
2626
</div>
2727
</div>
2828
<div class="col-md-3 col-12">
2929
<div class="form-group">
3030
<%= f.label :month %>
31-
<%= f.select :month, options_for_select((1..12).to_a, params[:month]), { prompt: "Select month" }, class: "form-select", data: { action: "change->topics#searchTopics" } %>
31+
<%= f.select :month, options_for_select((1..12).to_a, params[:month]), { prompt: "Select month" }, class: "form-select", data: { action: "change->search#submit" } %>
3232
</div>
3333
</div>
3434
<div class="col-md-6 col-12">
3535
<div class="form-group">
3636
<%= f.label :state %>
37-
<%= f.select :state, options_for_select(Topic::STATES.index_with(&:itself), params[:state]), { prompt: "Select state" }, class: "form-select", data: { action: "change->topics#searchTopics" } %>
37+
<%= f.select :state, options_for_select(Topic::STATES.index_with(&:itself), params[:state]), { prompt: "Select state" }, class: "form-select", data: { action: "change->search#submit" } %>
3838
</div>
3939
</div>
4040
<div class="col-md-6 col-12">
4141
<div class="form-group">
4242
<%= f.label :order %>
43-
<%= f.select :order, options_for_select(Topic::SORTS.reverse.index_with(&:itself), params[:order]), {}, class: "form-select", data: { action: "change->topics#searchTopics" } %>
43+
<%= f.select :order, options_for_select(Topic::SORTS.reverse.index_with(&:itself), params[:order]), {}, class: "form-select", data: { action: "change->search#submit" } %>
4444
</div>
4545
</div>
4646
<div class="col-12 d-flex justify-content-end">

0 commit comments

Comments
 (0)