UX: Improve sub-sub-categories styling in categories list (#8593)

- Using h4 instead of h3 for sub-categories.
- Show category description if it does not have subcategories.
- Implemented equivalent for mobile-view.
- Include description_excerpt in basic serializer. This is needed for
  displaying second-level categories in category list.

Follow-up to 9253cb79e3.
This commit is contained in:
Dan Ungureanu 2019-12-19 17:09:45 +02:00 committed by GitHub
parent e8beccdaa4
commit 069bc70bd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 72 additions and 16 deletions

View File

@ -21,9 +21,9 @@
{{#if c.isGrandParent}} {{#if c.isGrandParent}}
<table class="category-list"> <table class="category-list">
{{#each c.subcategories as |subcategory|}} {{#each c.subcategories as |subcategory|}}
<tr data-category-id={{subcategory.id}} class="no-description {{if subcategory.uploaded_logo.url 'has-logo' 'no-logo'}}"> <tr data-category-id={{subcategory.id}} class="{{if subcategory.description_excerpt 'has-description' 'no-description'}} {{if subcategory.uploaded_logo.url 'has-logo' 'no-logo'}}">
<td class="category" style={{border-color subcategory.color}}> <td class="category" style={{border-color subcategory.color}}>
{{category-title-link category=subcategory}} {{category-title-link tagName="h4" category=subcategory}}
{{#if subcategory.subcategories}} {{#if subcategory.subcategories}}
<div class='subcategories'> <div class='subcategories'>
@ -36,6 +36,10 @@
{{/unless}} {{/unless}}
{{/each}} {{/each}}
</div> </div>
{{else}}
<div class="category-description">
{{{dir-span subcategory.description_excerpt}}}
</div>
{{/if}} {{/if}}
</td> </td>
</tr> </tr>

View File

@ -23,7 +23,27 @@
{{/each}} {{/each}}
{{/if}} {{/if}}
{{#if c.subcategories}} {{#if c.isGrandParent}}
{{#each c.subcategories as |subcategory|}}
<tr data-category-id={{c.id}} class='subcategory-list-item category' style={{border-color subcategory.color}}>
<td>
{{category-title-link tagName="h4" category=subcategory}}
<div class="subcategories-list">
{{#if subcategory.subcategories}}
<div class='subcategories'>
{{#each subcategory.subcategories as |subsubcategory|}}
{{#unless subsubcategory.isMuted}}
{{category-link subsubcategory}}
{{/unless}}
{{/each}}
</div>
{{/if}}
</div>
</td>
</tr>
{{/each}}
{{else if c.subcategories}}
<tr class="subcategories-list"> <tr class="subcategories-list">
<td> <td>
<div class='subcategories'> <div class='subcategories'>

View File

@ -95,13 +95,21 @@
tbody { tbody {
.category { .category {
border-left: 6px solid; border-left: 6px solid;
h3 { h3,
font-size: $font-up-2; h4 {
line-height: $line-height-medium; line-height: $line-height-medium;
a[href] { a[href] {
color: $primary; color: $primary;
} }
} }
h3 {
font-size: $font-up-2;
}
h4 {
font-size: $font-up-1;
}
} }
.latest { .latest {

View File

@ -264,6 +264,16 @@
} }
} }
.subcategory-list-item.category {
td:first-of-type {
padding: 12px 0px;
}
.subcategories {
padding-left: 10px;
}
}
tr.category-topic-link { tr.category-topic-link {
border-bottom: 1px solid $primary-low; border-bottom: 1px solid $primary-low;
&:last-of-type { &:last-of-type {
@ -271,14 +281,15 @@ tr.category-topic-link {
} }
} }
.category-list-item { .category-list-item,
padding: 5px 0 2px; .subcategory-list-item {
padding: 5px 0 2px 3px;
border-left: 6px solid; border-left: 6px solid;
border-top: 1px solid; border-top: 1px solid;
h3 { h3,
h4 {
max-width: 100%; max-width: 100%;
font-size: $font-up-2;
padding: 0 0 0 10px; padding: 0 0 0 10px;
.d-icon { .d-icon {
margin-right: 5px; margin-right: 5px;
@ -288,6 +299,14 @@ tr.category-topic-link {
} }
} }
h3 {
font-size: $font-up-2;
}
h4 {
font-size: $font-up-1;
}
.category-name { .category-name {
max-width: 80vw; max-width: 80vw;
} }

View File

@ -265,13 +265,22 @@ class Category < ActiveRecord::Base
def description_text def description_text
return nil unless self.description return nil unless self.description
@@cache ||= LruRedux::ThreadSafeCache.new(1000) @@cache_text ||= LruRedux::ThreadSafeCache.new(1000)
@@cache.getset(self.description) do @@cache_text.getset(self.description) do
text = Nokogiri::HTML.fragment(self.description).text.strip text = Nokogiri::HTML.fragment(self.description).text.strip
Rack::Utils.escape_html(text).html_safe Rack::Utils.escape_html(text).html_safe
end end
end end
def description_excerpt
return nil unless self.description
@@cache_excerpt ||= LruRedux::ThreadSafeCache.new(1000)
@@cache_excerpt.getset(self.description) do
PrettyText.excerpt(description, 300)
end
end
def access_category_via_group def access_category_via_group
Group Group
.joins(:category_groups) .joins(:category_groups)

View File

@ -12,6 +12,7 @@ class BasicCategorySerializer < ApplicationSerializer
:position, :position,
:description, :description,
:description_text, :description_text,
:description_excerpt,
:topic_url, :topic_url,
:read_restricted, :read_restricted,
:permission, :permission,

View File

@ -9,7 +9,6 @@ class CategoryDetailedSerializer < BasicCategorySerializer
:topics_month, :topics_month,
:topics_year, :topics_year,
:topics_all_time, :topics_all_time,
:description_excerpt,
:is_uncategorized, :is_uncategorized,
:subcategory_ids :subcategory_ids
@ -27,10 +26,6 @@ class CategoryDetailedSerializer < BasicCategorySerializer
is_uncategorized is_uncategorized
end end
def description_excerpt
PrettyText.excerpt(description, 300) if description
end
def include_subcategory_ids? def include_subcategory_ids?
subcategory_ids.present? subcategory_ids.present?
end end