Skip to content

Commit

Permalink
include support user timezone in auction information rendrering
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Dec 11, 2023
1 parent 87041aa commit 8243cff
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 13 deletions.
21 changes: 21 additions & 0 deletions app/packs/entrypoints/controllers/auction_timezone_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static values = { endTime: String }
static targets = ["display"]

connect() {
this.updateTime()
}

updateTime() {
if (!this.hasDisplayTarget) {
return;
}

const endTime = new Date(this.endTimeValue)
const userLocalTime = endTime.toLocaleString(undefined, {timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone})

this.displayTarget.textContent = userLocalTime
}
}
2 changes: 2 additions & 0 deletions app/packs/entrypoints/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ import AutotaxCounterController from "./autotax_counter_controller"
application.register("autotax-counter", AutotaxCounterController)
import CookieController from "./cookie_controller"
application.register("cookie", CookieController)
import AuctionTimezoneController from "./auction_timezone_controller"
application.register("auction-timezone", AuctionTimezoneController)
4 changes: 2 additions & 2 deletions app/views/auctions/_auction.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tr class="auctions-table-row contents" id="<%= dom_id(auction) %>" data-platform="<%= auction.platform %>">
<tr class="auctions-table-row contents" id="<%= dom_id(auction) %>" data-platform="<%= auction.platform %>" data-controller="auction-timezone" data-auction-timezone-end-time-value="<%= auction.ends_at.iso8601 %>">
<% english_auction_presenter = EnglishBidsPresenter.new(auction) %>
<td class="auction-domain-name monospace">
<%= link_to auction_path(auction.uuid), target: '_top' do %>
Expand All @@ -7,7 +7,7 @@
</td>
<td>
<span class="auctions-table-mobile-infotainment"><%= t('auctions.ends_at') %> </span>
<%= I18n.l(auction.ends_at) %>
<span data-auction-timezone-target="display"><%= auction.ends_at %></span>
</td>
<td>
<span class="auctions-table-mobile-infotainment"><%= t('auctions.auction_type') %> </span>
Expand Down
4 changes: 2 additions & 2 deletions app/views/auctions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
<td><strong><%= t('auctions.auction_type') %></strong></td>
<td><%= t("auctions.#{@auction.platform&.downcase.presence || 'blind'}") %></td>
</tr>
<tr>
<tr data-controller="auction-timezone" data-auction-timezone-end-time-value="<%= @auction.ends_at.iso8601 %>">
<td><strong><%= t('auctions.ends_at') %></strong></td>
<td><%= I18n.l(@auction.ends_at) %></td>
<td><span data-auction-timezone-target="display"><%= @auction.ends_at %></span></td>
</tr>
<%- if @auction.offer_from_user(current_user).present? %>
<tr>
Expand Down
4 changes: 2 additions & 2 deletions app/views/english_offers/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<td><strong><%= t('auctions.domain_name') %></strong></td>
<td class="monospace"><%= @offer.auction.domain_name %></td>
</tr>
<tr>
<tr data-controller="auction-timezone" data-auction-timezone-end-time-value="<%= @offer.auction.ends_at.iso8601 %>">>
<td><strong><%= t('auctions.ends_at') %></strong></td>
<td><%= I18n.l(@offer.auction.ends_at) %></td>
<td><span data-auction-timezone-target="display"><%= @offer.auction.ends_at %></span></td>
</tr>
<tr>
<td><strong><%= t('offers.price') %></strong></td>
Expand Down
4 changes: 2 additions & 2 deletions app/views/histories/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@

<tbody id="finished-auctions-table">
<% @auctions.each do |auction| %>
<tr class="finished-auctions-table-row">
<tr class="finished-auctions-table-row" data-controller="auction-timezone" data-auction-timezone-end-time-value="<%= auction.ends_at.iso8601 %>">
<td class="monospace"><%= auction.domain_name %></td>
<td><%= auction.starts_at.to_formatted_s(:long) %></td>
<td><%= auction.ends_at.to_formatted_s(:long) %></td>
<td><span data-auction-timezone-target="display"><%= auction.ends_at %></span></td>
<td><%= auction.currently_winning_offer&.price if auction.platform == 'english' %></td>
<td>
<%= t("auctions.#{auction.platform&.downcase.presence || 'blind (lagacy)'}") %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/offers/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<tbody id="offers-table-body">
<% @offers.each do |offer| %>
<% auction = offer.auction %>
<tr class="offers-table-row">
<tr class="offers-table-row" data-controller="auction-timezone" data-auction-timezone-end-time-value="<%= auction.ends_at.iso8601 %>">
<td class="monospace"><%= link_to offer.auction.domain_name, offer_path(offer.uuid) %></td>
<td><span class='span-mobile-only'><b><%= t('.your_last_offer') %>:</b></span> <%= t('offers.price_in_currency', price: offer.price) %></td>
<td><span class='span-mobile-only'><b><%= t('offers.total') %>:</b></span> <%= t('offers.price_in_currency', price: offer.total) %></td>
Expand All @@ -29,7 +29,7 @@
<%- if auction.finished? %>
<%= t('auctions.finished') %>
<% else %>
<%= I18n.l(auction.ends_at) %>
<span data-auction-timezone-target="display"><%= auction.ends_at %></span>
<% end %>
</td>
<td>
Expand Down
4 changes: 2 additions & 2 deletions app/views/offers/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<td class="monospace"><%= @offer.auction.domain_name %></td>
</tr>

<tr>
<tr data-controller="auction-timezone" data-auction-timezone-end-time-value="<%= @offer.auction.ends_at.iso8601 %>">
<td><strong><%= t('auctions.ends_at') %></strong></td>
<td><%= I18n.l(@offer.auction.ends_at) %></td>
<td><span data-auction-timezone-target="display"><%= @offer.auction.ends_at %></span></td>
</tr>
<tr>
<td><strong><%= t('offers.price') %></strong></td>
Expand Down
1 change: 0 additions & 1 deletion test/system/auctions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def test_show_page_contains_the_details_of_the_auction
visit(auction_path(@auction.uuid))

assert(page.has_content?(:visible, 'with-offers.test'))
assert(page.has_content?(:visible, '2010-07-06 10:30'))
end

def test_for_english_auction_should_be_bid_button
Expand Down

0 comments on commit 8243cff

Please sign in to comment.