ML-168: broadcast index_changed event after background import
Import workers now broadcast :records_index_changed on "records:index_changed" after successful import via Records.broadcast_index_changed/0. CollectionLive.Index and WishlistLive.Index subscribe to the topic in mount/3 and reload their record streams on receipt, with a live_action guard to skip reloads when the grid is hidden behind a modal (:import, :barcode_scan). IndexActions.handle_index_changed/1 refreshes total_entries before reloading to keep the pagination bar accurate.
This commit is contained in:
@@ -146,6 +146,18 @@ defmodule MusicLibraryWeb.LiveHelpers.IndexActions do
|
||||
{:noreply, load_and_assign_records(socket, socket.assigns.record_list_params)}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Handles a PubSub notification that records have changed.
|
||||
Refreshes total_entries and reloads the record stream using the current parameters.
|
||||
"""
|
||||
def handle_index_changed(socket) do
|
||||
config = socket.assigns.index_config
|
||||
params = socket.assigns.record_list_params
|
||||
total_records = config.context_module.search_records_count(params.query)
|
||||
updated_params = %{params | total_entries: total_records}
|
||||
load_and_assign_records(socket, updated_params)
|
||||
end
|
||||
|
||||
defp record_page_title(record, config) do
|
||||
Enum.join(
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user