Skip to content

Commit 17e9874

Browse files
authored
Merge pull request #77 from amatsuda/thread_view_improvements
Thread view improvements
2 parents 1e2d632 + d8b58b2 commit 17e9874

File tree

6 files changed

+58
-9
lines changed

6 files changed

+58
-9
lines changed

app/assets/stylesheets/application.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@
1313
*= require_tree .
1414
*= require_self
1515
*/
16+
17+
.message-selected {
18+
background-color: oklch(98.5% 0.002 247.839) !important;
19+
}
20+
21+
@media (prefers-color-scheme: dark) {
22+
.message-selected {
23+
background-color: oklch(40% 0.08 247.839) !important;
24+
}
25+
}

app/decorators/message_decorator.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@ module MessageDecorator
44
def from
55
super&.gsub(/@[a-zA-Z.\-]+/, '@...')
66
end
7+
8+
def first_line
9+
body.lines.first&.strip
10+
end
11+
12+
def published_date
13+
published_at.strftime('%Y/%m/%d')
14+
end
715
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Controller } from "@hotwired/stimulus"
2+
3+
export default class extends Controller {
4+
select(event) {
5+
// Remove highlight from previously selected message
6+
const previousSelected = this.element.querySelector('.message-selected')
7+
if (previousSelected) {
8+
previousSelected.classList.remove('message-selected')
9+
}
10+
11+
// Add highlight to clicked message
12+
const messageElement = event.currentTarget
13+
if (messageElement) {
14+
messageElement.classList.add('message-selected')
15+
}
16+
}
17+
}

app/views/messages/_thread.html.erb

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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 %>
3-
<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">
3+
<%= link_to "/#{list.name}/#{message.list_seq}", class: 'message-item block 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', data: {turbo_frame: 'message_content', turbo_action: 'advance', action: 'click->message-list#select'} do %>
44
<div class="p-5">
55
<div class="flex items-start justify-between gap-4">
66
<div class="flex-1 min-w-0">
@@ -10,36 +10,48 @@
1010
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path>
1111
</svg>
1212
<% end %>
13-
<span class="px-0.5">[#<%= message.list_seq %>]</span>
14-
<%= link_to without_list_prefix(message.subject), "/#{list.name}/#{message.list_seq}", data: {turbo_frame: 'message_content'} %>
13+
<span class="px-0.5">[#<%= message.list_seq %>] <%= without_list_prefix(message.subject) %></span>
1514
<span class="text-sm text-gray-500 dark:text-gray-400 font-normal ml-2"><%= message.from %></span>
1615
</h2>
16+
<% if message.body.present? %>
17+
<p class="text-sm text-gray-600 dark:text-gray-400 mb-2 line-clamp-1"><%= message.first_line %></p>
18+
<% end %>
1719
<div class="flex items-center gap-3 text-sm text-gray-600 dark:text-gray-400">
1820
<span class="inline-flex items-center gap-1">
1921
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
2022
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"></path>
2123
</svg>
2224
<%= count = message.count_recursively %> <%= count == 1 ? 'message' : 'messages' %>
2325
</span>
26+
<span class="inline-flex items-center gap-1">
27+
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
28+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
29+
</svg>
30+
<%= message.published_date %>
31+
</span>
2432
</div>
2533
</div>
2634
</div>
2735
</div>
28-
</div>
36+
<% end %>
2937
<% else %>
30-
<div class="py-2 border-l-2 border-gray-200 dark:border-gray-700 pl-4 hover:border-red-400 dark:hover:border-red-500 transition-colors">
38+
<%= link_to "/#{list.name}/#{message.list_seq}", class: 'message-item block py-2 border-l-2 border-gray-200 dark:border-gray-700 pl-4 hover:border-red-400 dark:hover:border-red-500 transition-colors', data: {turbo_frame: 'message_content', turbo_action: 'advance', action: 'click->message-list#select'} do %>
3139
<div class="flex items-start gap-2 text-sm">
3240
<svg class="w-4 h-4 text-gray-400 dark:text-gray-500 mt-0.5 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
3341
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"></path>
3442
</svg>
3543
<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', data: {turbo_frame: 'message_content'} do %>
44+
<span class="text-gray-900 dark:text-gray-100 hover:text-red-600 dark:hover:text-red-400 transition-colors">
3745
<span class="px-0.5">[#<%= message.list_seq %>] <%= without_list_prefix(message.subject) %></span>
38-
<% end %>
46+
</span>
3947
<span class="text-gray-500 dark:text-gray-400"><%= message.from %></span>
48+
<span class="text-gray-500 dark:text-gray-400 ml-2"><%= message.published_date %></span>
49+
<% if message.body.present? %>
50+
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1 line-clamp-1"><%= message.first_line %></p>
51+
<% end %>
4052
</div>
4153
</div>
42-
</div>
54+
<% end %>
4355
<% end %>
4456

4557
<% if message.children&.any? %>

app/views/messages/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<p class="text-gray-600 dark:text-gray-400 mt-2">Mailing list archive</p>
1212
</div>
1313

14-
<div class="grid grid-cols-4 gap-6" style="height: calc(100vh - 16rem);">
14+
<div class="grid grid-cols-4 gap-6" style="height: calc(100vh - 16rem);" data-controller="message-list">
1515
<div class="col-span-1 overflow-y-auto space-y-6">
1616
<%= render partial: 'thread', collection: @messages, as: :message, locals: {list: @list, depth: 0} %>
1717
</div>

test/fixtures/messages.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ message1:
66
body: Body1
77
list_id: 1
88
list_seq: 123
9+
published_at: 1995-12-21 05:44:05
910

1011
message2:
1112
subject: Mail2
1213
from: From2
1314
body: Body2
1415
list_id: 2
1516
list_seq: 234
17+
published_at: 1997-07-28 14:51:40

0 commit comments

Comments
 (0)