Skip to content

Commit

Permalink
feat: show subtopics inside a topic page
Browse files Browse the repository at this point in the history
  • Loading branch information
danirod committed May 16, 2024
1 parent 2bef1e7 commit a07d8ea
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 18 deletions.
12 changes: 12 additions & 0 deletions app/components/six/explorer/child_topics_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="topicexplorer">
<%= render Six::Base::WrapperComponent.new(classes: 'topicexplorer__wrap') do %>
<h2 class="topicexplorer__title">Subcategorías de este tema</h2>
<div class="topicexplorer__topics">
<% @topic.child_topics.each do |topic| %>
<div class="topicexplorer__topic">
<%= render Six::Explorer::TopicThumbnailComponent.new(topic: topic, name: topic.title) %>
</div>
<% end %>
</div>
<% end %>
</div>
20 changes: 20 additions & 0 deletions app/components/six/explorer/child_topics_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Six
module Explorer
class ChildTopicsComponent < ViewComponent::Base
include ViewComponent::Translatable

with_collection_parameter :topic

def render?
@topic.child_topics.present?
end

def initialize(topic:)
super
@topic = topic
end
end
end
end
3 changes: 2 additions & 1 deletion app/components/six/front/topic_explorer_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class TopicExplorerComponent < ViewComponent::Base
'desarrollo-web' => 'Desarrollo web',
'lenguajes-de-programacion' => 'Programación',
'java' => 'Java',
'desarrollo-de-juegos' => 'Desarrollo de juegos'
'elixir' => 'Elixir',
'creamos-una-api-rest-con-quarkus' => 'Quarkus',
}.freeze

def topics
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/six/components/topicthumb.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
margin: 0;
padding: 0;

@include desktop-layout {
@include wide-layout {
display: block;
}
}

&__icon {
max-width: 96px;

@include desktop-layout {
@include wide-layout {
max-width: 100%;
}
}
Expand Down
22 changes: 8 additions & 14 deletions app/javascript/six/front/topics.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,23 @@
}
}

&__topics {
display: grid;
grid-template-columns: repeat(auto-fit, 320px);
justify-content: center;
gap: 10px;
}

@include desktop-layout {
&__title {
text-align: center;
font-size: 1.8rem;
}

&__topics {
display: flex;
margin-left: -10px;
margin-right: -10px;
}

&__topic {
flex: 1;
padding-left: 10px;
padding-right: 10px;
}
}

@include wide-layout {
&__topics {
width: 1100px;
margin: 0 auto;
grid-template-columns: repeat(auto-fit, 180px);
}
}
}
3 changes: 2 additions & 1 deletion app/views/topics/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
<% content_for(:hero) do %>
<h1><%= @topic.title %></h1>
<% end %>
<%= render Six::Explorer::PlaylistListComponent.new(playlists: @topic.playlists_with_children.with_public_videos.order('playlists.topic_position' => :asc)) %>
<%= render Six::Explorer::ChildTopicsComponent.new(topic: @topic) %>
<%= render Six::Explorer::PlaylistListComponent.new(playlists: @topic.playlists.with_public_videos.order('playlists.topic_position' => :asc)) %>

0 comments on commit a07d8ea

Please sign in to comment.