From b0dbbb1e9d1eb730efa5c72e175dc0101c3b0e2e Mon Sep 17 00:00:00 2001 From: Mebareksaf Date: Wed, 28 Feb 2024 18:26:49 +0100 Subject: [PATCH] add cursor based pagination --- apps/ex_nvr/lib/ex_nvr/model/recording.ex | 5 ++-- .../ex_nvr_web/components/core_components.ex | 26 ++----------------- .../ex_nvr_web/live/recordings_list_live.ex | 14 +++++++++- 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/apps/ex_nvr/lib/ex_nvr/model/recording.ex b/apps/ex_nvr/lib/ex_nvr/model/recording.ex index d2320f0a8..0253fba4f 100644 --- a/apps/ex_nvr/lib/ex_nvr/model/recording.ex +++ b/apps/ex_nvr/lib/ex_nvr/model/recording.ex @@ -23,9 +23,8 @@ defmodule ExNVR.Model.Recording do ] ] ], - pagination_types: [:page], - default_limit: 100, - max_limit: 150} + pagination_types: [:first, :last], + default_pagination_type: :first} @type t :: %__MODULE__{ start_date: DateTime.t(), diff --git a/apps/ex_nvr_web/lib/ex_nvr_web/components/core_components.ex b/apps/ex_nvr_web/lib/ex_nvr_web/components/core_components.ex index 38a1febd2..555167d37 100644 --- a/apps/ex_nvr_web/lib/ex_nvr_web/components/core_components.ex +++ b/apps/ex_nvr_web/lib/ex_nvr_web/components/core_components.ex @@ -686,7 +686,7 @@ defmodule ExNVRWeb.CoreComponents do -
  • 6}> - <.pagination_link current_page={@meta.current_page} page={page} /> -
  • -
  • 6 && @meta.current_page > 4}> - ... -
  • -
  • 6 && abs(@meta.current_page - idx) <= 1} - > - <.pagination_link current_page={@meta.current_page} page={idx} /> -
  • -
  • 6 && @meta.current_page < @meta.total_pages - 3}> - ... -
  • -
  • 6}> - <.pagination_link current_page={@meta.current_page} page={page} /> -
  • -
  • - <.pagination_link current_page={@meta.current_page} page={idx} /> -
  • after_cursor}) + else + old_pagination_params = Map.drop(socket.assigns.pagination_params, ["after"]) + Map.merge(old_pagination_params, %{"before" => before_cursor}) + end + + pagination_params = Map.merge(pagination_params, cursor_params) params = Map.merge(socket.assigns.filter_params, pagination_params)