post tooltips: use more compact timestamps.

* Use more compact timestamps in post tooltips ("39 minutes ago" -> "39m ago")
* Move timestamps to the right (after favcount + score).
* Switch favorite icon from star to heart.
This commit is contained in:
evazion
2019-11-04 18:18:56 -06:00
parent c1939f78d6
commit a418ed7281
2 changed files with 24 additions and 9 deletions

View File

@@ -50,10 +50,10 @@ module ApplicationHelper
end
end
def time_tag(content, time)
def time_tag(content, time, **options)
datetime = time.strftime("%Y-%m-%dT%H:%M%:z")
content_tag(:time, content || datetime, :datetime => datetime, :title => time.to_formatted_s)
tag.time content || datetime, datetime: datetime, title: time.to_formatted_s, **options
end
def humanized_duration(from, to)
@@ -71,11 +71,24 @@ module ApplicationHelper
def time_ago_in_words_tagged(time, compact: false)
if time.past?
text = time_ago_in_words(time) + " ago"
text = text.gsub(/almost|about|over/, "").strip if compact
raw time_tag(text, time)
if compact
text = time_ago_in_words(time)
text = text.gsub(/almost|about|over/, "").strip
text = text.gsub(/less than a/, "<1")
text = text.gsub(/ minutes?/, "m")
text = text.gsub(/ hours?/, "h")
text = text.gsub(/ days?/, "d")
text = text.gsub(/ months?/, "mo")
text = text.gsub(/ years?/, "y")
klass = "compact-timestamp"
else
text = time_ago_in_words(time) + " ago"
klass = ""
end
time_tag(text, time, class: klass)
else
raw time_tag("in " + distance_of_time_in_words(Time.now, time), time)
time_tag("in " + distance_of_time_in_words(Time.now, time), time)
end
end

View File

@@ -4,11 +4,9 @@
<%= link_to_user @post.uploader %>
<% end %>
<%= link_to time_ago_in_words_tagged(@post.created_at, compact: true), posts_path(tags: "date:#{@post.created_at.strftime("%Y-%m-%d")}"), class: "post-tooltip-date post-tooltip-info" %>
<span class="post-tooltip-favorites post-tooltip-info">
<span><%= @post.fav_count %></span>
<i class="far fa-star fa-xs"></i>
<i class="far fa-heart fa-xs"></i>
</span>
<span class="post-tooltip-score post-tooltip-info">
@@ -22,6 +20,10 @@
<i class="far fa-comments fa-xs"></i>
</span>
<% end %>
<%= link_to posts_path(tags: "date:#{@post.created_at.strftime("%Y-%m-%d")}"), class: "post-tooltip-date post-tooltip-info" do %>
<%= time_ago_in_words_tagged(@post.created_at, compact: true) %> ago
<% end %>
</span>
<span class="post-tooltip-header-right">