diff --git a/app/assets/stylesheets/item_trades/index.sass b/app/assets/stylesheets/item_trades/index.sass index fc5d4a1e..3624dd3e 100644 --- a/app/assets/stylesheets/item_trades/index.sass +++ b/app/assets/stylesheets/item_trades/index.sass @@ -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 diff --git a/app/helpers/item_trades_helper.rb b/app/helpers/item_trades_helper.rb index 1401462b..89252cc7 100644 --- a/app/helpers/item_trades_helper.rb +++ b/app/helpers/item_trades_helper.rb @@ -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 diff --git a/app/models/closet_hanger.rb b/app/models/closet_hanger.rb index fcdbc2c0..7d3675a8 100644 --- a/app/models/closet_hanger.rb +++ b/app/models/closet_hanger.rb @@ -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 diff --git a/app/views/item_trades/index.html.haml b/app/views/item_trades/index.html.haml index 9c7ed59c..ae0cea28 100644 --- a/app/views/item_trades/index.html.haml +++ b/app/views/item_trades/index.html.haml @@ -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") diff --git a/config/initializers/date_formats.rb b/config/initializers/date_formats.rb index f4e46e4f..0e67ac3f 100644 --- a/config/initializers/date_formats.rb +++ b/config/initializers/date_formats.rb @@ -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"