forked from OpenNeo/impress
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
|
overflow: hidden
|
||||||
text-overflow: ellipsis
|
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
|
.trade-list-names
|
||||||
list-style: none
|
list-style: none
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,28 @@
|
||||||
module ItemTradesHelper
|
module ItemTradesHelper
|
||||||
def vague_trade_timestamp(last_trade_activity_at)
|
def vague_trade_timestamp(trade)
|
||||||
if last_trade_activity_at >= 1.week.ago
|
return nil if trade.nil?
|
||||||
|
|
||||||
|
if trade.last_activity_at >= 1.week.ago
|
||||||
translate "item_trades.index.table.last_active.this_week"
|
translate "item_trades.index.table.last_active.this_week"
|
||||||
else
|
else
|
||||||
last_trade_activity_at.strftime("%b %Y")
|
trade.last_activity_at.to_date.to_fs(:month_and_year)
|
||||||
end
|
end
|
||||||
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)
|
def sorted_vaguely_by_trade_activity(trades)
|
||||||
# First, sort the list in ascending order.
|
# First, sort the list in ascending order.
|
||||||
trades_ascending = trades.sort_by do |trade|
|
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
|
# Sort recent trades in a random order, but still collectively as the
|
||||||
# most recent. (This discourages spamming updates to game the system!)
|
# most recent. (This discourages spamming updates to game the system!)
|
||||||
[1, rand]
|
[1, rand]
|
||||||
else
|
else
|
||||||
# Sort older trades by last trade activity.
|
# Sort older trades by last trade activity.
|
||||||
[0, trade.user.last_trade_activity_at]
|
[0, trade.last_activity_at]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -183,6 +183,10 @@ class ClosetHanger < ApplicationRecord
|
||||||
def lists
|
def lists
|
||||||
hangers.map(&:list).filter(&:present?)
|
hangers.map(&:list).filter(&:present?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def last_activity_at
|
||||||
|
user.last_trade_activity_at
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,13 @@
|
||||||
%th= t(".table.headings.user.#{@type}")
|
%th= t(".table.headings.user.#{@type}")
|
||||||
%th= t(".table.headings.lists")
|
%th= t(".table.headings.lists")
|
||||||
%tbody
|
%tbody
|
||||||
|
- prev_trade = nil
|
||||||
- sorted_vaguely_by_trade_activity(@trades).each do |trade|
|
- sorted_vaguely_by_trade_activity(@trades).each do |trade|
|
||||||
%tr
|
%tr
|
||||||
%td
|
%td{
|
||||||
= vague_trade_timestamp trade.user.last_trade_activity_at
|
'data-is-same-as-prev': same_vague_trade_timestamp?(trade, prev_trade)
|
||||||
|
}
|
||||||
|
= vague_trade_timestamp trade
|
||||||
%td= trade.user.name
|
%td= trade.user.name
|
||||||
%td
|
%td
|
||||||
- if trade.lists.present?
|
- if trade.lists.present?
|
||||||
|
|
@ -32,6 +35,7 @@
|
||||||
= link_to t(".table.not_in_a_list.#{@type}"), user_closet_hangers_path(trade.user,
|
= link_to t(".table.not_in_a_list.#{@type}"), user_closet_hangers_path(trade.user,
|
||||||
anchor: "closet-hangers-group-#{@type == :offering}"),
|
anchor: "closet-hangers-group-#{@type == :offering}"),
|
||||||
class: "not-in-a-list"
|
class: "not-in-a-list"
|
||||||
|
- prev_trade = trade
|
||||||
- else
|
- else
|
||||||
%p= t(".no_trades_yet")
|
%p= t(".no_trades_yet")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
Date::DATE_FORMATS[:month_and_day] = "%B %e"
|
Date::DATE_FORMATS[:month_and_day] = "%B %e"
|
||||||
|
Date::DATE_FORMATS[:month_and_year] = "%b %Y"
|
||||||
Time::DATE_FORMATS[:long_nst] = lambda { |time|
|
Time::DATE_FORMATS[:long_nst] = lambda { |time|
|
||||||
time.in_time_zone("Pacific Time (US & Canada)").
|
time.in_time_zone("Pacific Time (US & Canada)").
|
||||||
to_formatted_s(:long) + " NST"
|
to_formatted_s(:long) + " NST"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue