Skip to content

Conversation

@elenachekhina
Copy link
Owner

@elenachekhina elenachekhina commented Jul 29, 2023

Задание:
Необходимо добавить новую страницу со всеми треками артиста с ленивой подгрузкой треков при прокрутке (aka infinite scroll pagination). Использовать только Turbo Frames.

Copy link

@palkan palkan left a comment

Choose a reason for hiding this comment

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

Есть пару моментов, которые надо исправить, а в целом всё верно.

Comment on lines 21 to 23
<% tracks.each_with_index do |track, i| %>
<%= render track, track_counter: page * page_size + i, enqueueble: true %>
<% end %>
Copy link

Choose a reason for hiding this comment

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

Правильную нумерацию можно (и нужно) сделать через рендеринг коллекции; нужно просто задать стартовую позицию. Откатываться на each — плохая идея (это менее производительно).

Copy link
Owner Author

Choose a reason for hiding this comment

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

Поправила, правда я думала, что можно сделать через track_counter, но пришлось добавить новую локал переменную

@@ -0,0 +1 @@
<%= turbo_frame_tag "tracks_page_#{page}", src: artist_tracks_path(artist, page: page), loading: "lazy" %>
Copy link

Choose a reason for hiding this comment

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

Получается, что на каждую страницу мы рендеринг не только список треков, но и шапку (просто она не используем самим Турбо); получается лишняя и бесполезная работа для сервера. Нужно бы сделать так, чтобы возвращался только список треков (и следующий фрейм, если нужно).

Copy link
Owner Author

Choose a reason for hiding this comment

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

Поправила

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.

2 participants