Skip to content

Commit 1e2d632

Browse files
authored
Merge pull request #76 from amatsuda/two_pane_view
Two pane view with a turbo-frame
2 parents d49d9b0 + 6cf4e8c commit 1e2d632

File tree

6 files changed

+34
-18
lines changed

6 files changed

+34
-18
lines changed

app/javascript/application.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
2+
import "@hotwired/turbo-rails"
23
import "controllers"
4+
import "@hotwired/turbo-rails"

app/views/layouts/application.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</div>
3535
</header>
3636

37-
<main class="container mx-auto px-4 py-8">
37+
<main class="px-4 py-8">
3838
<%= yield %>
3939
</main>
4040
</body>

app/views/messages/_thread.html.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<div class="thread-message" style="margin-left: <%= depth * 6 %>px;" <% if (depth == 0) && message.children&.any? %>data-controller="thread"<% end %>>
22
<% if depth == 0 %>
33
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-md border border-gray-200 dark:border-gray-700 overflow-hidden hover:shadow-lg transition-shadow">
4-
<div class="p-5 <% if message.children&.any? %>cursor-pointer<% end %>" <% if message.children&.any? %>data-action="click->thread#toggle"<% end %>>
4+
<div class="p-5">
55
<div class="flex items-start justify-between gap-4">
66
<div class="flex-1 min-w-0">
77
<h2 class="text-lg font-semibold text-gray-900 dark:text-gray-100 hover:text-red-600 dark:hover:text-red-400 transition-colors mb-2">
88
<% if message.children&.any? %>
9-
<svg class="w-4 h-4 inline-block transition-transform" data-thread-target="icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
9+
<svg class="w-4 h-4 inline-block transition-transform cursor-pointer" data-thread-target="icon" data-action="click->thread#toggle" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1010
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path>
1111
</svg>
1212
<% end %>
1313
<span class="px-0.5">[#<%= message.list_seq %>]</span>
14-
<%= link_to without_list_prefix(message.subject), "/#{list.name}/#{message.list_seq}", data: {action: 'click->thread#toggle:stop'} %>
14+
<%= link_to without_list_prefix(message.subject), "/#{list.name}/#{message.list_seq}", data: {turbo_frame: 'message_content'} %>
1515
<span class="text-sm text-gray-500 dark:text-gray-400 font-normal ml-2"><%= message.from %></span>
1616
</h2>
1717
<div class="flex items-center gap-3 text-sm text-gray-600 dark:text-gray-400">
@@ -33,7 +33,7 @@
3333
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"></path>
3434
</svg>
3535
<div class="flex-1 min-w-0">
36-
<%= link_to "/#{list.name}/#{message.list_seq}", class: "text-gray-900 dark:text-gray-100 hover:text-red-600 dark:hover:text-red-400 transition-colors" do %>
36+
<%= link_to "/#{list.name}/#{message.list_seq}", class: 'text-gray-900 dark:text-gray-100 hover:text-red-600 dark:hover:text-red-400 transition-colors', data: {turbo_frame: 'message_content'} do %>
3737
<span class="px-0.5">[#<%= message.list_seq %>] <%= without_list_prefix(message.subject) %></span>
3838
<% end %>
3939
<span class="text-gray-500 dark:text-gray-400"><%= message.from %></span>

app/views/messages/index.html.erb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,26 @@
66
</div>
77
<% end %>
88

9-
<div class="mb-8">
9+
<div class="mb-4">
1010
<h1 class="text-3xl font-bold text-gray-900 dark:text-gray-100"><%= @list.name %></h1>
1111
<p class="text-gray-600 dark:text-gray-400 mt-2">Mailing list archive</p>
1212
</div>
1313

14-
<div class="space-y-6">
15-
<%= render partial: 'thread', collection: @messages, as: :message, locals: {list: @list, depth: 0} %>
14+
<div class="grid grid-cols-4 gap-6" style="height: calc(100vh - 16rem);">
15+
<div class="col-span-1 overflow-y-auto space-y-6">
16+
<%= render partial: 'thread', collection: @messages, as: :message, locals: {list: @list, depth: 0} %>
17+
</div>
18+
19+
<div class="col-span-3 overflow-y-auto">
20+
<%= turbo_frame_tag "message_content", class: "block" do %>
21+
<div class="flex items-center justify-center h-full text-gray-400 dark:text-gray-500">
22+
<div class="text-center">
23+
<svg class="w-16 h-16 mx-auto mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
24+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path>
25+
</svg>
26+
<p>Select a message to view</p>
27+
</div>
28+
</div>
29+
<% end %>
30+
</div>
1631
</div>

app/views/messages/show.html.erb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<% content_for :title, @message.subject %>
22

3-
<% if notice %>
4-
<div class="mb-4 p-4 bg-green-50 dark:bg-green-900 border border-green-200 dark:border-green-700 text-green-800 dark:text-green-200 rounded-lg">
5-
<%= notice %>
6-
</div>
7-
<% end %>
8-
9-
<div class="mb-4">
10-
<%= link_to "← Back to #{@message.list.name}", "/#{@message.list.name}/", class: "text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 font-medium" %>
11-
</div>
3+
<%= turbo_frame_tag 'message_content' do %>
4+
<% if notice %>
5+
<div class="mb-4 p-4 bg-green-50 dark:bg-green-900 border border-green-200 dark:border-green-700 text-green-800 dark:text-green-200 rounded-lg">
6+
<%= notice %>
7+
</div>
8+
<% end %>
129

13-
<%= render @message %>
10+
<%= render @message %>
11+
<% end %>

config/importmap.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
pin "@hotwired/stimulus", to: "stimulus.min.js"
55
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
66
pin_all_from "app/javascript/controllers", under: "controllers"
7+
pin "@hotwired/turbo-rails", to: "turbo.min.js"

0 commit comments

Comments
 (0)