impress/app/helpers/item_trades_helper.rb
Emi Matchu 0e32eb5d8f 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.)
2025-06-22 10:43:48 -07:00

32 lines
890 B
Ruby

module ItemTradesHelper
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
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.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.last_activity_at]
end
end
# Then, reverse it!
trades_ascending.reverse!
end
end