mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
Activity log loads as you scroll
The activity log stopped at 200 events. It now loads 50 at a time, the next page coming in a lazy frame as it scrolls into view (as Oil & Fuel does), keeping the category filter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e4c27c6ff7
commit
2e8d789975
5 files changed
+60
-3
No files matched your search
@@ -1,10 +1,18 @@
|
||||
class EventsController < ApplicationController
|
||||
include AircraftScoped
|
||||
|
||||
EVENTS_PER_PAGE = 50
|
||||
|
||||
# A page at a time; the rest load as you scroll (each page ends in a lazy
|
||||
# frame that fetches the next).
|
||||
def index
|
||||
@category = params[:category].presence_in(AircraftEvent::CATEGORIES.keys)
|
||||
scope = @aircraft.events.includes(:user)
|
||||
@page = [ params[:page].to_i, 1 ].max
|
||||
scope = @aircraft.events.includes(:user).reorder(created_at: :desc, id: :desc)
|
||||
scope = scope.where(category: @category) if @category
|
||||
@events = scope.limit(200)
|
||||
rows = scope.offset((@page - 1) * EVENTS_PER_PAGE).limit(EVENTS_PER_PAGE + 1).to_a
|
||||
@more = rows.size > EVENTS_PER_PAGE
|
||||
@events = rows.first(EVENTS_PER_PAGE)
|
||||
render(partial: "events/page", locals: { events: @events, page: @page, more: @more, category: @category }) if turbo_frame_request?
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user