Skip to content

Commit f5efd13

Browse files
committed
Adding a basic attachment sidebar
The latest attachment is the first, everything is in descending order. This should be the more useful ordering for the typical "I want to see the latest patch version" usecase.
1 parent 8523287 commit f5efd13

File tree

4 files changed

+73
-2
lines changed

4 files changed

+73
-2
lines changed

app/assets/stylesheets/components/sidebar.css

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,53 @@
5757
text-decoration: underline;
5858
}
5959
}
60+
61+
.sidebar .attachments-list {
62+
list-style: none;
63+
padding-left: 0;
64+
margin: var(--spacing-3) 0;
65+
}
66+
67+
.sidebar .attachments-list li + li {
68+
margin-top: var(--spacing-2);
69+
}
70+
71+
.sidebar .attachment-link {
72+
display: flex;
73+
justify-content: space-between;
74+
gap: var(--spacing-2);
75+
color: var(--color-text-link);
76+
text-decoration: none;
77+
font-weight: var(--font-weight-medium);
78+
}
79+
80+
.sidebar .attachment-link:hover {
81+
text-decoration: underline;
82+
}
83+
84+
.sidebar .attachment-target {
85+
font-weight: var(--font-weight-bold);
86+
}
87+
88+
.sidebar .attachment-date {
89+
color: var(--color-text-secondary);
90+
font-size: var(--font-size-sm);
91+
}
92+
93+
.sidebar .attachment-name {
94+
display: block;
95+
padding-left: var(--spacing-4);
96+
margin-top: var(--spacing-1);
97+
}
98+
99+
.sidebar .attachment-more {
100+
display: block;
101+
padding-left: var(--spacing-4);
102+
color: var(--color-text-secondary);
103+
font-size: var(--font-size-sm);
104+
margin-top: var(--spacing-1);
105+
}
106+
107+
.sidebar .attachment-names {
108+
color: var(--color-text-secondary);
109+
}

app/controllers/topics_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def new_topics_count
3333
end
3434

3535
def show
36-
messages_scope = @topic.messages.includes(:sender, reply_to: :sender)
36+
messages_scope = @topic.messages.includes(:sender, { reply_to: :sender }, :attachments)
3737

3838
@messages = messages_scope.order(created_at: :asc)
3939
@message_numbers = @messages.each_with_index.to_h { |msg, idx| [msg.id, idx + 1] }

app/views/topics/_message.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
= render_message_body(message.body)
3939

4040
- if message.attachments.any?
41-
.message-attachments
41+
.message-attachments id="message-#{message.id}-attachments"
4242
h4 Attachments:
4343
- message.attachments.each do |attachment|
4444
- if attachment.patch?

app/views/topics/show.html.slim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@
1515
- else
1616
p No participants yet
1717

18+
- attachment_messages = @messages.select { |msg| msg.attachments.any? }
19+
details.sidebar-section open=true
20+
summary.sidebar-heading Attachments
21+
.sidebar-section
22+
- if attachment_messages.any?
23+
ul.attachments-list
24+
- attachment_messages.sort_by(&:created_at).reverse_each do |msg|
25+
- number = @message_numbers[msg.id]
26+
li
27+
= link_to "#message-#{msg.id}-attachments", class: "attachment-link" do
28+
span.attachment-target = "##{number}"
29+
span.attachment-date = smart_time_display(msg.created_at)
30+
- names = msg.attachments.map(&:file_name)
31+
- names.first(2).each do |name|
32+
.attachment-name = name
33+
- if names.size > 2
34+
.attachment-more = "+ #{names.size - 2} more"
35+
- else
36+
p No attachments in this thread
37+
38+
1839
details.sidebar-section open=true
1940
summary.sidebar-heading Thread Outline
2041
- if @thread_outline.present?

0 commit comments

Comments
 (0)