Skip to content

Commit 76fdc01

Browse files
Use links in people dropdown and make them work with prefetch
1 parent 362a0c2 commit 76fdc01

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

app/assets/stylesheets/styles.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,13 @@ pzsh-topbar {
310310
opacity: 1;
311311
}
312312

313+
.dropdown-option {
314+
width: 100%;
315+
display: block;
316+
text-decoration: none;
317+
color: black;
318+
}
319+
313320
.dropdown-option-highlighted {
314321
background-color: #2c97a6;
315322
}

app/helpers/person_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ def sorted_people
8282
end
8383

8484
def people_for_select
85-
Person.all.map { |p| [p.name, person_path(p)] }
85+
Person.all.map { |p| [p.name, person_path(p), {'data-html': "<a href='#{person_path(p)}' class='dropdown-option'>#{p.name}</a>" }] }
8686
end
8787
end

app/javascript/controllers/dropdown_controller.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ export default class extends Controller {
99
return;
1010

1111
new SlimSelect({
12-
select: this.dropdownTarget
12+
select: this.dropdownTarget,
13+
events: {
14+
beforeChange: (newVal) => {
15+
Turbo.visit(newVal[0].value)
16+
return false
17+
}
18+
},
1319
});
1420
}
15-
16-
handleChange(event) {
17-
window.location.href = event.target.value;
18-
}
1921
}

app/views/layouts/application.html.haml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
%html
33
%head
44
// This disables the Turbo prefetch in development as it gets quite annoying when debugging
5-
- if Rails.env.development?
6-
%meta{:name => "turbo-prefetch", :content => "false"}/
5+
%meta{:name => "turbo-prefetch", :content => "true"}/
76
%meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
87
%title PuzzleSkills
98
%meta{:content => "width=device-width,initial-scale=1", :name => "viewport"}/

app/views/people/_search.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
%div.d-flex.col-9.gap-3
33
%span.col-6{"data-controller": "dropdown"}
44
- selected_path = model_path_or_nil(person)
5-
= select :person_id, :person, options_for_select(sorted_people, select_when_available(selected_path)), {prompt: person.nil?}, {data:{"dropdown-target": "dropdown" , action: "change->dropdown#handleChange"}}
5+
= select :person_id, :person, options_for_select(sorted_people, select_when_available(selected_path)), {prompt: person.nil?}, {data:{"dropdown-target": "dropdown"}}
66
%div.d-flex.align-items-center.text-gray
77
= "#{t '.updated_at'}: #{@person&.last_updated_at.strftime("%d.%m.%Y")}" if @person&.last_updated_at
88
%a.d-flex.justify-content-between#new-person-button

0 commit comments

Comments
 (0)