Skip to content

Commit 4a1b236

Browse files
committed
First pass at Turbo topic navigation with sidebar
1 parent 0378f5c commit 4a1b236

File tree

4 files changed

+52
-38
lines changed

4 files changed

+52
-38
lines changed

app/controllers/topics_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
class TopicsController < ApplicationController
22
def index
33
@topics = Topic.approved.with_pages.order(name: :asc)
4-
@topics = @topics.where("lower(slug) LIKE ?", "#{params[:letter].downcase}%") if params[:letter].present?
54
end
65

76
def show
7+
@topics = Topic.approved.with_pages.order(name: :asc)
88
@topic = Topic.find_by!(slug: params[:slug])
99
end
1010
end

app/views/topics/_topic.html.erb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<%# locals: (topics:, topic: nil) %>
2+
3+
<% title = topic ? "Topic: #{topic.name}" : "Topics" %>
4+
5+
<%= render Pages::Header.new(title: title) %>
6+
7+
<div class="column-content container py-gap mb-3xl">
8+
<nav class="sidebar">
9+
<% topics.each do |topic| %>
10+
<%= tag.div id: dom_id(topic), class: "mb-4" do %>
11+
<%= link_to topic.name, topic_path(topic), data: {turbo_frame: :topic_articles} %>
12+
<span class="text-faint">(<%= topic.pages_count %>)</span>
13+
<% end %>
14+
<% end %>
15+
</nav>
16+
<div class="mainbar w-full">
17+
<% if !topic %>
18+
<div>
19+
<h2>Welcome!</h2>
20+
<div>
21+
<p>Here you‘ll find topics currently covered at Joy of Rails.</p>
22+
<p>Choose a topic from the sidebar to view articles.</p>
23+
</div>
24+
</div>
25+
<% elsif topic.pages.blank? %>
26+
<div>
27+
<h2>No articles have been added for this topic yet!</h2>
28+
<div>
29+
<p>Coming soon. Maybe ;)</p>
30+
</div>
31+
</div>
32+
<% else %>
33+
<% topic.pages.as_published_articles.each do |page| %>
34+
<%= tag.div id: dom_id(page) do %>
35+
<%= render Pages::Info.new(
36+
title: page.title,
37+
request_path: page.request_path,
38+
description: page.description,
39+
image: page.image
40+
) %>
41+
<% end %>
42+
<% end %>
43+
<% end %>
44+
</div>
45+
</div>

app/views/topics/index.html.erb

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
2-
<%= render Pages::Header.new(title: "Topics") %>
3-
<div class="section-content container py-gap mb-3xl">
4-
<% if @topics.blank? %>
5-
<div class="only:inherit grid grid-row-mid">
6-
<h2>No topics have been created yet!</h2>
7-
<div>
8-
<p>Coming soon ;)</p>
9-
</div>
10-
</div>
11-
<% else %>
12-
<% @topics.each do |topic| %>
13-
<%= tag.div id: dom_id(topic) do %>
14-
<h3>
15-
<%= link_to topic.name, topic_path(topic) %>
16-
<span class="text-faint">(<%= topic.pages_count %>)</span>
17-
</h3>
18-
<% end %>
19-
<% end %>
20-
<% end %>
21-
</div>
1+
<%= turbo_frame_tag :topic_articles, class: "row-gap-none", data: {turbo_action: "advance"} do %>
2+
<%= render "topic", topics: @topics %>
3+
<% end %>

app/views/topics/show.html.erb

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
2-
<%= render Pages::Header.new(title: "Topic: #{@topic.name}") %>
3-
<div class="section-content container py-gap mb-3xl">
4-
<% if @topic.pages.blank? %>
5-
<div class="only:inherit grid grid-row-mid">
6-
<h2>No articles have been added for this topic yet!</h2>
7-
<div>
8-
<p>Coming soon. Maybe ;)</p>
9-
</div>
10-
</div>
11-
<% else %>
12-
<%= render Pages::List.new(@topic.pages.as_published_articles) %>
13-
<% end %>
14-
15-
<div><%= link_to "Back to Topics list", topics_path %></div>
16-
</div>
1+
<%= turbo_frame_tag :topic_articles, class: "row-gap-none", data: {turbo_action: "advance"} do %>
2+
<%= render @topic, topics: @topics %>
3+
<% end %>

0 commit comments

Comments
 (0)