Skip to content

Commit 75a63f8

Browse files
committed
Add links to the first unread messages
Clicking on the unread messages icon now immediately jumps to the first unread message instead the top of the thread.
1 parent 1b38a05 commit 75a63f8

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

app/assets/stylesheets/components/topics.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@
104104
position: relative;
105105
}
106106

107+
a.topic-icon {
108+
text-decoration: none;
109+
color: var(--color-text-primary);
110+
111+
&:hover {
112+
filter: brightness(0.95);
113+
}
114+
}
115+
107116
.topic-icon-badge {
108117
position: absolute;
109118
bottom: -6px;

app/views/topics/_message.html.slim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.message-card id=message_dom_id(message) class=("reply-message" if message.reply_to_id)
22
- if (mid_anchor = message_id_anchor(message))
33
a.message-id-anchor id=mid_anchor aria-hidden="true"
4+
- if local_assigns[:is_first_unread]
5+
a.message-id-anchor id="first-unread" aria-hidden="true"
46
- display_number = number || (@message_numbers && @message_numbers[message.id])
57
- is_read = defined?(@read_message_ids) && @read_message_ids[message.id]
68
- if user_signed_in?

app/views/topics/_status_cell.html.slim

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ td.topic-title.status-border class=status_class id=dom_id(topic, "status_cell")
66
- read_count = state[:read_count].to_i
77
- total_count = topic.message_count
88
- unread_count = [total_count - read_count, 0].max
9-
.topic-icon.topic-icon-reading title="Unread messages: #{unread_count}"
10-
i.fa-solid.fa-envelope
11-
- if unread_count.positive?
9+
- if unread_count.positive?
10+
= link_to topic_path(topic, anchor: "first-unread"), class: "topic-icon topic-icon-reading", title: "Jump to first unread message (#{unread_count} unread)" do
11+
i.fa-solid.fa-envelope
1212
span.topic-icon-badge.topic-icon-badge-sup = unread_count
13+
- else
14+
.topic-icon.topic-icon-reading title="All messages read"
15+
i.fa-solid.fa-envelope
1316
= render partial: "topics/star_icon", locals: { topic: topic, star_data: star_data }
1417
= render partial: "topics/note_icon", locals: { topic: topic, count: note_count.to_i }
1518
= render partial: "topics/team_readers_icon", locals: { topic: topic, readers: team_readers }

app/views/topics/show.html.slim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,13 @@
193193
.thread-actions data-controller="thread-actions" data-thread-actions-topic-id-value[email protected] data-thread-actions-read-all-url-value=read_all_topic_path(@topic, format: :json)
194194
button.button-secondary data-action="click->thread-actions#markAllRead" Mark all messages read
195195

196+
- first_unread_found = false
196197
- @messages.each do |message|
197-
= render 'message', message: message, number: @message_numbers[message.id]
198+
- is_first_unread = false
199+
- if user_signed_in? && !first_unread_found && !@read_message_ids&.dig(message.id)
200+
- is_first_unread = true
201+
- first_unread_found = true
202+
= render 'message', message: message, number: @message_numbers[message.id], is_first_unread: is_first_unread
198203

199204
.topic-navigation
200205
= link_to "← Back to Topics", topics_path, class: "back-link"

0 commit comments

Comments
 (0)