diff --git a/app/controllers/concerns/events_timeline.rb b/app/controllers/concerns/events_timeline.rb new file mode 100644 index 000000000..7b4e98e2e --- /dev/null +++ b/app/controllers/concerns/events_timeline.rb @@ -0,0 +1,44 @@ +module EventsTimeline + extend ActiveSupport::Concern + + include BucketFilterable + + included do + before_action :set_activity_day + end + + private + def set_activity_day + @activity_day = if params[:day].present? + Time.zone.parse(params[:day]) + else + Time.zone.now + end + rescue ArgumentError + raise ActionController::RoutingError + end + + def events_for_activity_day + user_events.where(created_at: @activity_day.all_day). + group_by { |event| [ event.created_at.hour, helpers.event_column(event) ] }. + map { |hour_col, events| + [ hour_col, + events.uniq { |e| e.action == "boosted" ? [ e.creator_id, e.bubble_id ] : e.id } + ] + } + end + + def latest_event_before_activity_day + user_events.where(created_at: ...@activity_day.beginning_of_day).chronologically.last + end + + def user_events + Event.where(bubble: user_bubbles, creator: Current.account.users) + end + + def user_bubbles + Current.user.accessible_bubbles + .published_or_drafted_by(Current.user) + .where(bucket_id: bucket_filter) + end +end diff --git a/app/controllers/events/days_controller.rb b/app/controllers/events/days_controller.rb new file mode 100644 index 000000000..c2966357d --- /dev/null +++ b/app/controllers/events/days_controller.rb @@ -0,0 +1,8 @@ +class Events::DaysController < ApplicationController + include EventsTimeline + + def index + @events = events_for_activity_day + @next_day = latest_event_before_activity_day&.created_at + end +end diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 7c2b35064..ba6df4e27 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -1,47 +1,13 @@ class EventsController < ApplicationController - include BucketFilterable - before_action :set_activity_day + include EventsTimeline def index update_bucket_filter + @buckets = Current.user.buckets.alphabetically - @events = events_by_hour_and_column @filters = Current.user.filters.all - @next_day = latest_event_before_today&.created_at + + @events = events_for_activity_day + @next_day = latest_event_before_activity_day&.created_at end - - private - def events_by_hour_and_column - user_events.where(created_at: @activity_day.all_day). - group_by { |event| [ event.created_at.hour, helpers.event_column(event) ] }. - map { |hour_col, events| - [ hour_col, - events.uniq { |e| e.action == "boosted" ? [ e.creator_id, e.bubble_id ] : e.id } - ] - } - end - - def latest_event_before_today - user_events.where(created_at: ...@activity_day.beginning_of_day).chronologically.last - end - - def user_events - Event.where(bubble: user_bubbles, creator: Current.account.users) - end - - def user_bubbles - Current.user.accessible_bubbles - .published_or_drafted_by(Current.user) - .where(bucket_id: bucket_filter) - end - - def set_activity_day - @activity_day = if params[:day].present? - Time.zone.parse(params[:day]) - else - Time.zone.now - end - rescue ArgumentError - raise ActionController::RoutingError - end end diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index f51b1e361..613c7fe36 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -29,7 +29,7 @@ module EventsHelper def event_next_page_link(next_day) if next_day tag.div id: "next_page", - data: { controller: "fetch-on-visible", fetch_on_visible_url_value: events_path(day: next_day.strftime("%Y-%m-%d")) } + data: { controller: "fetch-on-visible", fetch_on_visible_url_value: events_days_path(day: next_day.strftime("%Y-%m-%d")) } end end diff --git a/app/views/events/_day.html.erb b/app/views/events/_day.html.erb index 523679b48..416d67e63 100644 --- a/app/views/events/_day.html.erb +++ b/app/views/events/_day.html.erb @@ -11,7 +11,7 @@ <% events.each do | hour_column, cluster| %> <%= event_cluster_tag(*hour_column) do %> - <%= render cluster.sort_by(&:created_at).reverse %> + <%= render partial: "events/event", collection: cluster.sort_by(&:created_at).reverse %> <%= local_datetime_tag cluster.first.created_at, class: "event__timestamp txt-small translucent" %> <% end %> diff --git a/app/views/events/index.turbo_stream.erb b/app/views/events/days/index.turbo_stream.erb similarity index 100% rename from app/views/events/index.turbo_stream.erb rename to app/views/events/days/index.turbo_stream.erb diff --git a/app/views/first_runs/show.html.erb b/app/views/first_runs/show.html.erb index 5ee2efeb1..476fbe987 100644 --- a/app/views/first_runs/show.html.erb +++ b/app/views/first_runs/show.html.erb @@ -3,7 +3,7 @@