From 67311c2c9a9935b0c0408aa16a727f0c9f2d757c Mon Sep 17 00:00:00 2001 From: Alejandro Fanjul Date: Fri, 14 Mar 2025 14:08:56 +0100 Subject: [PATCH] feat: Implement search results functionality with improved UX in PublicArticleSearch component - Now you can use /hc/{account}/en/search?query=XXX to view search results --- .../api/v1/portals/search_controller.rb | 19 +++ .../portal/components/PublicArticleSearch.vue | 23 +++- .../api/v1/portals/search/index.html.erb | 115 ++++++++++++++++++ config/locales/en.yml | 7 ++ config/locales/es.yml | 7 ++ config/routes.rb | 1 + 6 files changed, 166 insertions(+), 6 deletions(-) create mode 100644 app/controllers/public/api/v1/portals/search_controller.rb create mode 100644 app/views/public/api/v1/portals/search/index.html.erb diff --git a/app/controllers/public/api/v1/portals/search_controller.rb b/app/controllers/public/api/v1/portals/search_controller.rb new file mode 100644 index 000000000..7d2cc2f56 --- /dev/null +++ b/app/controllers/public/api/v1/portals/search_controller.rb @@ -0,0 +1,19 @@ +class Public::Api::V1::Portals::SearchController < Public::Api::V1::Portals::BaseController + before_action :portal + layout 'portal' + + def index + @query = params[:query] + @articles = @portal.articles.published + + @articles = @articles.search(search_params) if @query.present? + + @articles = @articles.page(params[:page]).per(10) # Add pagination + end + + private + + def search_params + params.permit(:query, :locale, :sort, :status, :page) + end +end diff --git a/app/javascript/portal/components/PublicArticleSearch.vue b/app/javascript/portal/components/PublicArticleSearch.vue index 809755e46..1ac4bcfd5 100644 --- a/app/javascript/portal/components/PublicArticleSearch.vue +++ b/app/javascript/portal/components/PublicArticleSearch.vue @@ -90,18 +90,29 @@ export default { this.isLoading = false; } }, + handleSubmit() { + if (this.searchTerm.trim()) { + const url = `/hc/${this.portalSlug}/${this.localeCode}/search?query=${encodeURIComponent(this.searchTerm)}`; + window.location.href = url; + } + }, }, };