From 950f085e800a5a08fcfce8c1a5505f32c9537f63 Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Thu, 9 Nov 2023 07:33:16 +0530 Subject: [PATCH] feat: Updated the design of the category page (#8165) Co-authored-by: Muhsin Keloth Co-authored-by: Pranav Raj S --- app/helpers/portal_helper.rb | 4 ++ .../v1/portals/_uncategorized-block.html.erb | 2 +- .../categories/_category-block.html.erb | 6 +-- .../categories/_category-hero.html.erb | 37 ++++++++++------- .../api/v1/portals/categories/show.html.erb | 40 +++++++------------ lib/chatwoot_markdown_renderer.rb | 4 ++ spec/helpers/portal_helper_spec.rb | 15 +++++++ spec/lib/chatwoot_markdown_renderer_spec.rb | 13 ++++++ 8 files changed, 77 insertions(+), 44 deletions(-) diff --git a/app/helpers/portal_helper.rb b/app/helpers/portal_helper.rb index 12ba41f95..72d4eeda1 100644 --- a/app/helpers/portal_helper.rb +++ b/app/helpers/portal_helper.rb @@ -41,4 +41,8 @@ module PortalHelper def generate_article_link(portal_slug, article_slug, theme) "/hc/#{portal_slug}/articles/#{article_slug}#{theme.present? && theme != 'system' ? "?theme=#{theme}" : ''}" end + + def render_category_content(content) + ChatwootMarkdownRenderer.new(content).render_markdown_to_plain_text + end end diff --git a/app/views/public/api/v1/portals/_uncategorized-block.html.erb b/app/views/public/api/v1/portals/_uncategorized-block.html.erb index f96584427..0fb3ab591 100644 --- a/app/views/public/api/v1/portals/_uncategorized-block.html.erb +++ b/app/views/public/api/v1/portals/_uncategorized-block.html.erb @@ -11,7 +11,7 @@ <% portal.articles.published.where(category_id: nil).order(position: :asc).take(5).each do |article| %>
<%= article.title %> diff --git a/app/views/public/api/v1/portals/categories/_category-block.html.erb b/app/views/public/api/v1/portals/categories/_category-block.html.erb index eddb18ab1..f2cf547fe 100644 --- a/app/views/public/api/v1/portals/categories/_category-block.html.erb +++ b/app/views/public/api/v1/portals/categories/_category-block.html.erb @@ -2,7 +2,7 @@

- + <%= category.name %>

@@ -20,7 +20,7 @@
<%= article.title %> @@ -45,7 +45,7 @@
<%= I18n.t('public_portal.common.view_all_articles') %> diff --git a/app/views/public/api/v1/portals/categories/_category-hero.html.erb b/app/views/public/api/v1/portals/categories/_category-hero.html.erb index 3cc474742..5b0d85fa2 100644 --- a/app/views/public/api/v1/portals/categories/_category-hero.html.erb +++ b/app/views/public/api/v1/portals/categories/_category-hero.html.erb @@ -1,17 +1,26 @@ -
- - <%= I18n.t('public_portal.common.home') %> - - / -
-

- <%= category.name %> -

-
- <%= render 'public/api/v1/portals/article_count', article_count: category.articles.published.size %> +
+
+ + <%= I18n.t('public_portal.common.home') %> + + <%= render partial: 'icons/chevron-right' %> + <%= category.name %> +
+
+
+ <% if category.icon.present? %> + <%= category.icon %> + <% end %> +

+ <%= category.name %> +

+ <% if category.description.present? %> + <%= category.description %> + <% end %>
+ <%= render 'public/api/v1/portals/article_count', article_count: category.articles.published.size %>
diff --git a/app/views/public/api/v1/portals/categories/show.html.erb b/app/views/public/api/v1/portals/categories/show.html.erb index 66203d74f..27ae0dd08 100644 --- a/app/views/public/api/v1/portals/categories/show.html.erb +++ b/app/views/public/api/v1/portals/categories/show.html.erb @@ -6,48 +6,36 @@ <% end %> <% if !@is_plain_layout_enabled %> -
-
+
+
<%= render 'public/api/v1/portals/categories/category-hero', category: @category, portal: @portal %>
<% else %> <%= render 'public/api/v1/portals/categories/category-hero', category: @category, portal: @portal %> <% end %> -
-
+
+
<% if @category.articles.published.size == 0 %>

<%= I18n.t('public_portal.common.no_articles') %>

<% else %> <% @category.articles.published.order(:position).each do |article| %> + diff --git a/lib/chatwoot_markdown_renderer.rb b/lib/chatwoot_markdown_renderer.rb index 73b52e1d6..2177f8b8f 100644 --- a/lib/chatwoot_markdown_renderer.rb +++ b/lib/chatwoot_markdown_renderer.rb @@ -18,6 +18,10 @@ class ChatwootMarkdownRenderer render_as_html_safe(html) end + def render_markdown_to_plain_text + CommonMarker.render_doc(@content, :DEFAULT).to_plaintext + end + private def render_as_html_safe(html) diff --git a/spec/helpers/portal_helper_spec.rb b/spec/helpers/portal_helper_spec.rb index 0f131a279..3294e6cb6 100644 --- a/spec/helpers/portal_helper_spec.rb +++ b/spec/helpers/portal_helper_spec.rb @@ -119,4 +119,19 @@ describe PortalHelper do end end end + + describe '#render_category_content' do + let(:markdown_content) { 'This is a *test* markdown content' } + let(:plain_text_content) { 'This is a test markdown content' } + let(:renderer) { instance_double(ChatwootMarkdownRenderer) } + + before do + allow(ChatwootMarkdownRenderer).to receive(:new).with(markdown_content).and_return(renderer) + allow(renderer).to receive(:render_markdown_to_plain_text).and_return(plain_text_content) + end + + it 'converts markdown to plain text' do + expect(helper.render_category_content(markdown_content)).to eq(plain_text_content) + end + end end diff --git a/spec/lib/chatwoot_markdown_renderer_spec.rb b/spec/lib/chatwoot_markdown_renderer_spec.rb index a3109a7f2..cbfc4c6fe 100644 --- a/spec/lib/chatwoot_markdown_renderer_spec.rb +++ b/spec/lib/chatwoot_markdown_renderer_spec.rb @@ -2,6 +2,7 @@ require 'rails_helper' RSpec.describe ChatwootMarkdownRenderer do let(:markdown_content) { 'This is a *test* content with ^markdown^' } + let(:plain_text_content) { 'This is a test content with markdown' } let(:doc) { instance_double(CommonMarker::Node) } let(:renderer) { described_class.new(markdown_content) } let(:markdown_renderer) { instance_double(CustomMarkdownRenderer) } @@ -44,4 +45,16 @@ RSpec.describe ChatwootMarkdownRenderer do expect(rendered_message).to be_html_safe end end + + describe '#render_markdown_to_plain_text' do + let(:rendered_content) { renderer.render_markdown_to_plain_text } + + before do + allow(doc).to receive(:to_plaintext).and_return(plain_text_content) + end + + it 'renders the markdown content to plain text' do + expect(rendered_content).to eq(plain_text_content) + end + end end