@@ -218,6 +218,16 @@ defmodule AlgoraWeb.Org.BountiesLive do
218218 </ table >
219219 </ div >
220220 </ div >
221+ < div :if = { @ has_more_open and @ current_tab == :open } class = "flex justify-center mt-4 " >
222+ < . button variant = "ghost " phx-click = "load_more_open " >
223+ < . icon name = "tabler-arrow-down " class = "mr-2 h-4 w-4 " /> Load More
224+ </ . button >
225+ </ div >
226+ < div :if = { @ has_more_paid and @ current_tab == :completed } class = "flex justify-center mt-4 " >
227+ < . button variant = "ghost " phx-click = "load_more_paid " >
228+ < . icon name = "tabler-arrow-down " class = "mr-2 h-4 w-4 " /> Load More
229+ </ . button >
230+ </ div >
221231 </ div >
222232 """
223233 end
@@ -230,8 +240,58 @@ defmodule AlgoraWeb.Org.BountiesLive do
230240 { :noreply , push_patch ( socket , to: ~p" /org/#{ socket . assigns . current_org . handle } /bounties?status=open" ) }
231241 end
232242
243+ def handle_event ( "load_more_open" , _params , socket ) do
244+ % { open_bounties: open_bounties , current_org: current_org } = socket . assigns
245+
246+ last_bounty = List . last ( open_bounties )
247+
248+ cursor = % {
249+ inserted_at: last_bounty . inserted_at ,
250+ id: last_bounty . id
251+ }
252+
253+ more_bounties =
254+ Bounties . list_bounties (
255+ owner_id: current_org . id ,
256+ limit: page_size ( ) ,
257+ status: :open ,
258+ before: cursor
259+ )
260+
261+ { :noreply ,
262+ socket
263+ |> assign ( :open_bounties , open_bounties ++ more_bounties )
264+ |> assign ( :has_more_open , length ( more_bounties ) >= page_size ( ) )
265+ |> assign_bounties ( ) }
266+ end
267+
268+ def handle_event ( "load_more_paid" , _params , socket ) do
269+ % { paid_bounties: paid_bounties , current_org: current_org } = socket . assigns
270+
271+ last_bounty = List . last ( paid_bounties )
272+
273+ cursor = % {
274+ inserted_at: last_bounty . inserted_at ,
275+ id: last_bounty . id
276+ }
277+
278+ more_bounties =
279+ Bounties . list_bounties (
280+ owner_id: current_org . id ,
281+ limit: page_size ( ) ,
282+ status: :paid ,
283+ before: cursor
284+ )
285+
286+ { :noreply ,
287+ socket
288+ |> assign ( :paid_bounties , paid_bounties ++ more_bounties )
289+ |> assign ( :has_more_paid , length ( more_bounties ) >= page_size ( ) )
290+ |> assign_bounties ( ) }
291+ end
292+
233293 def handle_params ( params , _uri , socket ) do
234- limit = 10
294+ limit = page_size ( )
235295 current_org = socket . assigns . current_org
236296 current_tab = get_current_tab ( params )
237297
@@ -243,10 +303,23 @@ defmodule AlgoraWeb.Org.BountiesLive do
243303 open_count = length ( open_bounties )
244304 paid_count = length ( paid_bounties )
245305
306+ { :noreply ,
307+ socket
308+ |> assign ( :current_tab , current_tab )
309+ |> assign ( :open_count , open_count )
310+ |> assign ( :completed_count , paid_count )
311+ |> assign ( :open_bounties , open_bounties )
312+ |> assign ( :paid_bounties , paid_bounties )
313+ |> assign ( :has_more_open , length ( open_bounties ) >= page_size ( ) )
314+ |> assign ( :has_more_paid , length ( paid_bounties ) >= page_size ( ) )
315+ |> assign_bounties ( ) }
316+ end
317+
318+ defp assign_bounties ( socket ) do
246319 bounties =
247- case current_tab do
248- :open -> open_bounties
249- :completed -> paid_bounties
320+ case socket . assigns . current_tab do
321+ :open -> socket . assigns . open_bounties
322+ :completed -> socket . assigns . paid_bounties
250323 end
251324
252325 claims_by_ticket =
@@ -263,12 +336,7 @@ defmodule AlgoraWeb.Org.BountiesLive do
263336 % { bounty: bounty , claim_groups: Map . get ( claims_by_ticket , bounty . ticket . id , % { } ) }
264337 end )
265338
266- { :noreply ,
267- socket
268- |> assign ( :current_tab , current_tab )
269- |> assign ( :bounties , bounties )
270- |> assign ( :open_count , open_count )
271- |> assign ( :completed_count , paid_count ) }
339+ assign ( socket , :bounties , bounties )
272340 end
273341
274342 defp get_current_tab ( params ) do
@@ -278,4 +346,6 @@ defmodule AlgoraWeb.Org.BountiesLive do
278346 _ -> :open
279347 end
280348 end
349+
350+ defp page_size , do: 10
281351end
0 commit comments