-
Notifications
You must be signed in to change notification settings - Fork 1
Paginate plans index with Turbo Frame infinite scroll #96
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <%= turbo_frame_tag "plans-page-#{page}" do %> | ||
| <% plans.each do |plan| %> | ||
| <div class="card plans-list__item"> | ||
| <div class="plans-list__header"> | ||
| <%= link_to plan.title, plan_path(plan), class: "plans-list__title", data: { turbo_frame: "_top" } %> | ||
| <span class="badge badge--<%= plan.status %>"><%= plan.status %></span> | ||
| <% if plan.plan_type %> | ||
| <span class="badge badge--type"><%= plan.plan_type.name %></span> | ||
| <% end %> | ||
| <% plan_unread = plan_unread_counts[plan.id] || 0 %> | ||
| <% if plan_unread > 0 %> | ||
| <span class="inbox-badge"><%= plan_unread %></span> | ||
| <% end %> | ||
| </div> | ||
| <% if plan.tags.any? %> | ||
| <div class="plans-list__tags"> | ||
| <% plan.tags.each do |tag| %> | ||
| <%= link_to tag.name, plans_path(params.permit(:scope, :status, :plan_type).merge(tag: tag.name)), class: "badge badge--tag #{'badge--tag-active' if params[:tag] == tag.name}", data: { turbo_frame: "_top" } %> | ||
| <% end %> | ||
| </div> | ||
| <% end %> | ||
| <div class="plans-list__meta text-sm text-muted"> | ||
| <%= user_avatar(plan.created_by_user) %> <%= plan.created_by_user.name %> · v<%= plan.current_revision %> · updated <%= time_ago_in_words(plan.updated_at) %> ago | ||
| </div> | ||
| </div> | ||
| <% end %> | ||
|
|
||
| <% if has_next_page %> | ||
| <%= turbo_frame_tag "plans-page-#{page + 1}", src: plans_path(params.permit(:scope, :status, :plan_type, :tag).merge(page: page + 1)), loading: :lazy do %> | ||
| <div class="plans-list__loading text-muted text-sm">Loading more plans…</div> | ||
| <% end %> | ||
| <% end %> | ||
| <% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
offsetpagination here without a deterministic tie-breaker means pages can skip or duplicate plans when multiple records share the sameupdated_atvalue. The query still orders only byupdated_at, so framepage=2can return overlapping or missing rows relative topage=1for ties, which breaks infinite scroll correctness; add a secondary unique order (for exampleid) before applyingoffset.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch — added
id: :descas a secondary sort key in 283dc0d to make the offset pagination deterministic.