1111 < p class ="text-xl leading-[1.4] text-gray-400 "> Get answers to frequently asked questions about personal finance, investing, budgeting, and wealth management.</ p >
1212 </ div >
1313
14- <%= form_with method : :get , html : { class : "relative mb-4 max-w-[450px] mx-auto" } , data : { controller : "auto-submit-form" , turbo_frame : "faqs_list" } do |f | %>
14+ <%= form_with method : :get , local : true , html : { class : "relative mb-4 max-w-[450px] mx-auto" } do |f | %>
1515 <%= f . text_field :q , value : @query ,
1616 class : "w-full py-2.5 px-3 pl-10 bg-white border border-gray-300 shadow-xs rounded-xl text-base leading-[1.4]" ,
17- placeholder : "Search FAQs..." ,
18- data : { auto_submit_form_target : "auto" } %>
17+ placeholder : "Search FAQs..." %>
1918 <%= lucide_icon "search" , class : "absolute top-3 left-3 w-5 h-5 text-gray-500 pointer-events-none" %>
2019 <% end %>
21-
22- <!-- Category Filter -->
23- <% if @categories . any? %>
24- < div class ="mb-8 ">
25- < div class ="flex flex-wrap gap-2 justify-center ">
26- <%= link_to "All" , faqs_path ,
27- class : "px-4 py-2 rounded-full text-sm font-medium transition-colors #{ @selected_category . blank? ? 'bg-gray-900 text-white' : 'bg-gray-200 text-gray-700 hover:bg-gray-300' } " %>
28- <% @categories . each do |category | %>
29- <%= link_to category , faqs_path ( category : category ) ,
30- class : "px-4 py-2 rounded-full text-sm font-medium transition-colors #{ @selected_category == category ? 'bg-gray-900 text-white' : 'bg-gray-200 text-gray-700 hover:bg-gray-300' } " %>
31- <% end %>
32- </ div >
33- </ div >
34- <% end %>
3520 </ div >
3621
37- < turbo-frame id ="faqs_list " target ="_top ">
38- <% if @faqs . any? %>
39- < div class ="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-8 ">
40- <% @faqs . each do |faq | %>
41- <%= link_to faq_path ( faq ) , class : "block bg-white p-6 rounded-lg border shadow-xs hover:shadow-sm transition-shadow duration-200" do %>
42- < h3 class ="text-lg font-semibold mb-3 text-gray-900 leading-tight ">
43- <%= faq . question %>
44- </ h3 >
45- <% if faq . category . present? %>
46- < div class ="mb-3 ">
47- < span class ="inline-block px-3 py-1 text-xs font-medium bg-gray-100 text-gray-600 rounded-full ">
48- <%= faq . category %>
49- </ span >
22+ <% if @faqs . any? %>
23+ <% if @query . present? %>
24+ <!-- Search Results -->
25+ < div class ="mb-6 ">
26+ < h2 class ="text-2xl font-semibold mb-4 "> Search Results for "<%= @query %> "</ h2 >
27+ < div class ="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-8 ">
28+ <% @faqs . each do |faq | %>
29+ <%= link_to faq_path ( faq ) , class : "block bg-white p-6 rounded-lg border shadow-xs hover:shadow-sm transition-shadow duration-200" do %>
30+ < h3 class ="text-lg font-semibold mb-3 text-gray-900 leading-tight ">
31+ <%= faq . question %>
32+ </ h3 >
33+ <% if faq . category . present? %>
34+ < div class ="mb-3 ">
35+ < span class ="inline-block px-3 py-1 text-xs font-medium bg-gray-100 text-gray-600 rounded-full ">
36+ <%= faq . category %>
37+ </ span >
38+ </ div >
39+ <% end %>
40+ < p class ="text-sm text-gray-600 leading-relaxed ">
41+ <%= truncate ( strip_tags ( faq . answer ) , length : 120 , separator : ' ' ) %>
42+ </ p >
43+ < div class ="mt-4 flex items-center text-sm font-medium text-gray-900 ">
44+ Read answer
45+ <%= lucide_icon "chevron-right" , class : "ml-1 w-4 h-4" %>
5046 </ div >
5147 <% end %>
52- < p class ="text-sm text-gray-600 leading-relaxed ">
53- <%= truncate ( strip_tags ( faq . answer ) , length : 120 , separator : ' ' ) %>
54- </ p >
55- < div class ="mt-4 flex items-center text-sm font-medium text-gray-900 ">
56- Read answer
57- <%= lucide_icon "chevron-right" , class : "ml-1 w-4 h-4" %>
58- </ div >
5948 <% end %>
60- <% end % >
49+ </ div >
6150 </ div >
62-
63- <!-- Pagination -->
64- <% if @pagy . pages > 1 %>
65- < div class ="flex justify-center mt-12 ">
66- <%== pagy_nav ( @pagy ) %>
51+ <% else %>
52+ <!-- FAQs Grouped by Category -->
53+ <% faqs_grouped = @faqs . group_by { |faq | faq . category . present? ? faq . category : "General" } %>
54+ <% faqs_grouped . sort . each do |category_name , category_faqs | %>
55+ < div class ="mb-12 ">
56+ < h2 class ="text-2xl font-semibold mb-6 text-gray-900 "> <%= category_name %> </ h2 >
57+ < div class ="space-y-4 ">
58+ <% category_faqs . each do |faq | %>
59+ <%= link_to faq_path ( faq ) , class : "block bg-white p-6 rounded-lg border shadow-xs hover:shadow-sm transition-shadow duration-200" do %>
60+ < h3 class ="text-lg font-semibold mb-3 text-gray-900 leading-tight ">
61+ <%= faq . question %>
62+ </ h3 >
63+ < p class ="text-sm text-gray-600 leading-relaxed ">
64+ <%= truncate ( strip_tags ( faq . answer ) , length : 120 , separator : ' ' ) %>
65+ </ p >
66+ < div class ="mt-4 flex items-center text-sm font-medium text-gray-900 ">
67+ Read answer
68+ <%= lucide_icon "chevron-right" , class : "ml-1 w-4 h-4" %>
69+ </ div >
70+ <% end %>
71+ <% end %>
72+ </ div >
6773 </ div >
6874 <% end %>
69- <% else %>
70- < div class ="py-56 mx-auto text-center max-w-96 ">
71- <%= lucide_icon "search-x" , class : "w-6 h-6 mx-auto text-gray-500" %>
72- < p class ="mt-4 text-sm font-medium "> No FAQs found</ p >
73- <% if @query . present? %>
74- < p class ="mt-2 text-sm text-gray-500 "> We didn't find any FAQs matching "<%= @query %> ".</ p >
75- <% elsif @selected_category . present? %>
76- < p class ="mt-2 text-sm text-gray-500 "> No FAQs found in the "<%= @selected_category %> " category.</ p >
77- <% else %>
78- < p class ="mt-2 text-sm text-gray-500 "> No FAQs available yet.</ p >
79- <% end %>
75+ <% end %>
76+
77+ <!-- Pagination -->
78+ <% if @pagy . pages > 1 %>
79+ < div class ="flex justify-center mt-12 ">
80+ <%== pagy_nav ( @pagy ) %>
8081 </ div >
8182 <% end %>
82- </ turbo-frame >
83+ <% else %>
84+ < div class ="py-56 mx-auto text-center max-w-96 ">
85+ <%= lucide_icon "search-x" , class : "w-6 h-6 mx-auto text-gray-500" %>
86+ < p class ="mt-4 text-sm font-medium "> No FAQs found</ p >
87+ <% if @query . present? %>
88+ < p class ="mt-2 text-sm text-gray-500 "> We didn't find any FAQs matching "<%= @query %> ".</ p >
89+ <% else %>
90+ < p class ="mt-2 text-sm text-gray-500 "> No FAQs available yet.</ p >
91+ <% end %>
92+ </ div >
93+ <% end %>
8394</ div >
0 commit comments