Hide duplicate timestamps on item trades page
Just a small visual cleanup because I happened to click on item trades today! We don't need to repeat "This Week" a million times. Just output it for the first row, then hide it for the following. (We still include it in screen reader output for semantic clarity; this is just a visual cleanup.)
This commit is contained in:
parent
99290235f5
commit
0e32eb5d8f
5 changed files with 32 additions and 7 deletions
|
|
@ -18,6 +18,16 @@
|
|||
overflow: hidden
|
||||
text-overflow: ellipsis
|
||||
|
||||
td[data-is-same-as-prev]
|
||||
// Visually hidden
|
||||
clip: rect(0 0 0 0)
|
||||
clip-path: inset(50%)
|
||||
height: 1px
|
||||
overflow: hidden
|
||||
position: absolute
|
||||
white-space: nowrap
|
||||
width: 1px
|
||||
|
||||
.trade-list-names
|
||||
list-style: none
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,28 @@
|
|||
module ItemTradesHelper
|
||||
def vague_trade_timestamp(last_trade_activity_at)
|
||||
if last_trade_activity_at >= 1.week.ago
|
||||
def vague_trade_timestamp(trade)
|
||||
return nil if trade.nil?
|
||||
|
||||
if trade.last_activity_at >= 1.week.ago
|
||||
translate "item_trades.index.table.last_active.this_week"
|
||||
else
|
||||
last_trade_activity_at.strftime("%b %Y")
|
||||
trade.last_activity_at.to_date.to_fs(:month_and_year)
|
||||
end
|
||||
end
|
||||
|
||||
def same_vague_trade_timestamp?(trade1, trade2)
|
||||
vague_trade_timestamp(trade1) == vague_trade_timestamp(trade2)
|
||||
end
|
||||
|
||||
def sorted_vaguely_by_trade_activity(trades)
|
||||
# First, sort the list in ascending order.
|
||||
trades_ascending = trades.sort_by do |trade|
|
||||
if trade.user.last_trade_activity_at >= 1.week.ago
|
||||
if trade.last_activity_at >= 1.week.ago
|
||||
# Sort recent trades in a random order, but still collectively as the
|
||||
# most recent. (This discourages spamming updates to game the system!)
|
||||
[1, rand]
|
||||
else
|
||||
# Sort older trades by last trade activity.
|
||||
[0, trade.user.last_trade_activity_at]
|
||||
[0, trade.last_activity_at]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -183,6 +183,10 @@ class ClosetHanger < ApplicationRecord
|
|||
def lists
|
||||
hangers.map(&:list).filter(&:present?)
|
||||
end
|
||||
|
||||
def last_activity_at
|
||||
user.last_trade_activity_at
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
|
|||
|
|
@ -17,10 +17,13 @@
|
|||
%th= t(".table.headings.user.#{@type}")
|
||||
%th= t(".table.headings.lists")
|
||||
%tbody
|
||||
- prev_trade = nil
|
||||
- sorted_vaguely_by_trade_activity(@trades).each do |trade|
|
||||
%tr
|
||||
%td
|
||||
= vague_trade_timestamp trade.user.last_trade_activity_at
|
||||
%td{
|
||||
'data-is-same-as-prev': same_vague_trade_timestamp?(trade, prev_trade)
|
||||
}
|
||||
= vague_trade_timestamp trade
|
||||
%td= trade.user.name
|
||||
%td
|
||||
- if trade.lists.present?
|
||||
|
|
@ -32,6 +35,7 @@
|
|||
= link_to t(".table.not_in_a_list.#{@type}"), user_closet_hangers_path(trade.user,
|
||||
anchor: "closet-hangers-group-#{@type == :offering}"),
|
||||
class: "not-in-a-list"
|
||||
- prev_trade = trade
|
||||
- else
|
||||
%p= t(".no_trades_yet")
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
Date::DATE_FORMATS[:month_and_day] = "%B %e"
|
||||
Date::DATE_FORMATS[:month_and_year] = "%b %Y"
|
||||
Time::DATE_FORMATS[:long_nst] = lambda { |time|
|
||||
time.in_time_zone("Pacific Time (US & Canada)").
|
||||
to_formatted_s(:long) + " NST"
|
||||
|
|
|
|||
Loading…
Reference in a new issue