Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2400 next eventful period #2438

Merged
merged 10 commits into from
Apr 26, 2024
Merged

2400 next eventful period #2438

merged 10 commits into from
Apr 26, 2024

Conversation

aaaaargZombies
Copy link
Contributor

fixes #2400

Grabs the next future event, takes it's start date and links to it using the same logic as the paginator. Retains "period" mode and won't show if there's no future events.

next_date.mp4

@ivan-kocienski-gfsc ivan-kocienski-gfsc self-requested a review April 25, 2024 13:18
Copy link
Contributor

@ivan-kocienski-gfsc ivan-kocienski-gfsc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well but just a few changes to make it more robust

@@ -28,6 +28,18 @@ def index
@events = sort_events(@events, @sort)
@multiple_days = true

@next = if params[:year]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe params[:year].present? ?

@@ -24,5 +24,5 @@
</ol>
<% end %>
<% else %>
<p>No events with this selection.</p>
<p>No events with this selection.<% if @next.present? %> <a href=<%= next_url(@next, period, sort, repeating)%>>skip to next date with events</a>.<% end %></p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a link_to

so something like

<%= link_to 'skip to next date with events', next_url(@next) if @next.present? %>

@@ -35,4 +35,13 @@ def online_link
def html_to_plaintext(input)
Nokogiri::HTML.fragment(input).text
end

def next_url(next_event, period, sort, repeating)
opts = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

building URLs like this seems very un-railsy as it has some hard-coded strings in it

it would be better to use a named route (like how there's an events_path) so if the routing changes we don't get caught out with old-style routes.

unfortunately you'll have to modify the route file to give that path a name.

In config/routes.rb you'll want to

  get '/events/:year/:month/:day' => 'events#index', constraints: ymd
  # and add at the end to be

  get '/events/:year/:month/:day' => 'events#index', constraints: ymd, as: :events_by_date

Then the URL can be built with

def next_url(next_event)
  opts = {
    year: next_event.dtstart.year,
    month: next_event.dtstart.month,
    day: next_event.dtstart.day,
    anchor: 'paginator',
    period: @period,
    sort: @sort,
    repeating: @repeating
  }.keep_if { |_key, value| value.present? }

  events_by_date_path(opts)
end

Copy link
Contributor

@ivan-kocienski-gfsc ivan-kocienski-gfsc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work

@aaaaargZombies aaaaargZombies merged commit e38acde into main Apr 26, 2024
2 checks passed
@aaaaargZombies aaaaargZombies deleted the 2400-next-eventful-period branch April 26, 2024 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unclear how to find next date with events on index
2 participants