Skip to content

Commit

Permalink
Better readout on event by day navigation links
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-kocienski-gfsc committed Aug 22, 2024
1 parent 4aabd0d commit fae6799
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
23 changes: 16 additions & 7 deletions app/helpers/events_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module EventsHelper
DATE_TIME_FORMAT = '%H:%M'
DATE_DAY_FORMAT = '%A %e %B, %Y'
DATE_TIME_FORMAT = '%H:%M'.freeze

Check failure on line 2 in app/helpers/events_helper.rb

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
DATE_DAY_FORMAT = '%A %-d %B, %Y'.freeze

def link_to_day(date)
link_to date.strftime(DATE_DAY_FORMAT), events_path(day: date.strftime('%Y-%m-%d'))
Expand Down Expand Up @@ -34,20 +34,29 @@ def render_day_navigator(first_day, show_day)
first_day_s = first_day.strftime('%Y-%m-%d')
day = first_day.dup
html = []
# html << "<span>#{day.strftime('%Y-%m-%d')}</span>"
month = day.month

7.times do
date_s = day.strftime('%Y-%m-%d')
7.times do
format = '%A %-d' # day number
if month != day.month
format += ' %B' # month name
month = day.month
end

date_s = day.strftime(format)

if day == show_day
html << "<span>#{date_s}</span>"
else
html << link_to(date_s, events_path(first: first_day_s, day: date_s))
# html << link_to(date_s, events_path(first: first_day_s, day: date_s), data: { 'turbo-frame': 'events-on-day-list' })
day_param_s = day.strftime('%Y-%m-%d')
html << link_to(date_s, events_path(first: first_day_s, day: day_param_s))
end
day += 1.day
end

day_param_s = day.strftime('%Y-%m-%d')
html << link_to('Later >>', events_path(first: day_param_s, day: day_param_s))

html.join(' | ').html_safe
end
end
4 changes: 2 additions & 2 deletions app/views/events/events_by_day.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%h1 Events on #{@epoch.strftime('%Y-%m-%d')}
%h1 Events on #{@epoch.strftime(EventsHelper::DATE_DAY_FORMAT)}

= render_day_navigator @first_day, @epoch

Expand All @@ -8,6 +8,6 @@
%div
= # %turbo-frame#events-on-day-list
- @events.each do |event|
%p= link_to(event.name, event_path(event.id))
%p #{event.start_date.strftime(EventsHelper::DATE_TIME_FORMAT)} #{link_to(event.name, event_path(event.id))}


2 changes: 1 addition & 1 deletion spec/integration/event_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
travel_to FakeEvents::NOW do
visit "/events"
click_link 'Wednesday 3 June, 2020'
expect(page).to have_selector('h1', text: 'Events on 2020-06-03')
expect(page).to have_selector('h1', text: 'Events on Wednesday 3 June, 2020')
expect(page).to have_selector('.events-listing p', count: 7)
end
end
Expand Down

0 comments on commit fae6799

Please sign in to comment.