@@ -72,6 +72,28 @@ defmodule YearbookWeb.Approvals do
7272 )
7373 end
7474
75+ defp page_range ( current , total ) do
76+ if total <= 7 do
77+ Enum . to_list ( 1 .. total )
78+ else
79+ ( [ 1 , total ] ++ Enum . to_list ( ( current - 2 ) .. ( current + 2 ) ) )
80+ |> Enum . filter ( & ( & 1 >= 1 and & 1 <= total ) )
81+ |> Enum . uniq ( )
82+ |> Enum . sort ( )
83+ |> add_dots ( [ ] )
84+ end
85+ end
86+
87+ defp add_dots ( [ a , b | tail ] , acc ) when b > a + 1 do
88+ add_dots ( [ b | tail ] , acc ++ [ a , :ellipsis ] )
89+ end
90+
91+ defp add_dots ( [ head | tail ] , acc ) do
92+ add_dots ( tail , acc ++ [ head ] )
93+ end
94+
95+ defp add_dots ( [ ] , acc ) , do: acc
96+
7597 def render ( assigns ) do
7698 ~H"""
7799 < div class = "flex-1 p-7 bg-white rounded-2xl " >
@@ -133,7 +155,7 @@ defmodule YearbookWeb.Approvals do
133155 Página < strong > { @ current_page_num } </ strong > de { @ total_pages }
134156 </ span >
135157
136- < div class = "flex gap-2 " >
158+ < div class = "flex items-center gap-2 " >
137159 < . link
138160 :if = { @ current_page_num > 1 }
139161 patch = { ~p" /backoffice/approvals?page=#{ @ current_page_num - 1 } " }
@@ -142,6 +164,25 @@ defmodule YearbookWeb.Approvals do
142164 < . icon name = "hero-chevron-left " class = "size-5 " />
143165 </ . link >
144166
167+ <%= for item <- page_range ( @ current_page_num , @ total_pages ) do %>
168+ <%= if item == :ellipsis do %>
169+ < span class = "px-2 text-gray-400 " > ...</ span >
170+ <% else %>
171+ < . link
172+ patch = { ~p" /backoffice/approvals?page=#{ item } " }
173+ class = { [
174+ "px-3 py-1 rounded text-sm font-medium" ,
175+ if ( item == @ current_page_num ,
176+ do: "bg-gray-800 text-white" ,
177+ else: "text-gray-600 hover:bg-gray-100"
178+ )
179+ ] }
180+ >
181+ { item }
182+ </ . link >
183+ <% end %>
184+ <% end %>
185+
145186 < . link
146187 :if = { @ current_page_num < @ total_pages }
147188 patch = { ~p" /backoffice/approvals?page=#{ @ current_page_num + 1 } " }
0 commit comments