@@ -3,6 +3,7 @@ defmodule AlgoraWeb.BountyLive do
33 use AlgoraWeb , :live_view
44
55 import Ecto.Changeset
6+ import Ecto.Query
67
78 alias Algora.Accounts
89 alias Algora.Admin
@@ -65,13 +66,49 @@ defmodule AlgoraWeb.BountyLive do
6566 bounty =
6667 Bounty
6768 |> Repo . get! ( bounty_id )
68- |> Repo . preload ( [
69- :owner ,
70- :creator ,
71- :transactions ,
72- ticket: [ repository: [ :user ] ]
73- ] )
69+ |> Repo . preload ( [ :owner , :creator , :transactions , ticket: [ repository: [ :user ] ] ] )
7470
71+ ticket_ref = % {
72+ owner: bounty . ticket . repository . user . provider_login ,
73+ repo: bounty . ticket . repository . name ,
74+ number: bounty . ticket . number
75+ }
76+
77+ socket
78+ |> assign ( :bounty , bounty )
79+ |> assign ( :ticket_ref , ticket_ref )
80+ |> on_mount ( bounty )
81+ end
82+
83+ @ impl true
84+ def mount ( % { "repo_owner" => repo_owner , "repo_name" => repo_name , "number" => number } , _session , socket ) do
85+ number = String . to_integer ( number )
86+
87+ ticket_ref = % { owner: repo_owner , repo: repo_name , number: number }
88+
89+ bounty =
90+ from ( b in Bounty ,
91+ join: t in assoc ( b , :ticket ) ,
92+ join: r in assoc ( t , :repository ) ,
93+ join: u in assoc ( r , :user ) ,
94+ where: u . provider == "github" ,
95+ where: u . provider_login == ^ repo_owner ,
96+ where: r . name == ^ repo_name ,
97+ where: t . number == ^ number ,
98+ # TODO: pool bounties
99+ limit: 1 ,
100+ order_by: [ asc: b . inserted_at ]
101+ )
102+ |> Repo . one ( )
103+ |> Repo . preload ( [ :owner , :creator , :transactions , ticket: [ repository: [ :user ] ] ] )
104+
105+ socket
106+ |> assign ( :bounty , bounty )
107+ |> assign ( :ticket_ref , ticket_ref )
108+ |> on_mount ( bounty )
109+ end
110+
111+ defp on_mount ( socket , bounty ) do
75112 debits = Enum . filter ( bounty . transactions , & ( & 1 . type == :debit and & 1 . status == :succeeded ) )
76113
77114 total_paid =
@@ -81,8 +118,6 @@ defmodule AlgoraWeb.BountyLive do
81118
82119 ticket_body_html = Algora.Markdown . render ( bounty . ticket . description )
83120
84- contexts = contexts ( bounty )
85-
86121 reward_changeset =
87122 RewardBountyForm . changeset ( % RewardBountyForm { } , % {
88123 tip_percentage: 0 ,
@@ -102,11 +137,9 @@ defmodule AlgoraWeb.BountyLive do
102137 { :ok ,
103138 socket
104139 |> assign ( :page_title , bounty . ticket . title )
105- |> assign ( :bounty , bounty )
106140 |> assign ( :ticket , bounty . ticket )
107141 |> assign ( :total_paid , total_paid )
108142 |> assign ( :ticket_body_html , ticket_body_html )
109- |> assign ( :contexts , contexts )
110143 |> assign ( :show_reward_modal , false )
111144 |> assign ( :show_exclusive_modal , false )
112145 |> assign ( :selected_context , nil )
@@ -126,11 +159,6 @@ defmodule AlgoraWeb.BountyLive do
126159 { :noreply , socket }
127160 end
128161
129- # @impl true
130- # def handle_params(%{"context" => context_id}, _url, socket) do
131- # {:noreply, socket |> assign_selected_context(context_id) |> assign_line_items(nil)}
132- # end
133-
134162 @ impl true
135163 def handle_params ( _params , _url , socket ) do
136164 { :noreply , socket }
@@ -164,7 +192,7 @@ defmodule AlgoraWeb.BountyLive do
164192
165193 { :noreply ,
166194 socket
167- |> update ( :messages , & ( & 1 ++ [ message ] ) )
195+ |> Phoenix.Component . update ( :messages , & ( & 1 ++ [ message ] ) )
168196 |> push_event ( "clear-input" , % { selector: "#message-input" } ) }
169197 end
170198
@@ -367,22 +395,38 @@ defmodule AlgoraWeb.BountyLive do
367395 < . social_share_button
368396 id = "twitter-share-url "
369397 icon = "tabler-brand-x "
370- value = { url ( ~p" /org/#{ @ bounty . owner . handle } /bounties/#{ @ bounty . id } " ) }
398+ value = {
399+ url (
400+ ~p" /#{ @ ticket_ref . owner } /#{ @ ticket_ref . repo } /issues/#{ @ ticket_ref . number } "
401+ )
402+ }
371403 />
372404 < . social_share_button
373405 id = "reddit-share-url "
374406 icon = "tabler-brand-reddit "
375- value = { url ( ~p" /org/#{ @ bounty . owner . handle } /bounties/#{ @ bounty . id } " ) }
407+ value = {
408+ url (
409+ ~p" /#{ @ ticket_ref . owner } /#{ @ ticket_ref . repo } /issues/#{ @ ticket_ref . number } "
410+ )
411+ }
376412 />
377413 < . social_share_button
378414 id = "linkedin-share-url "
379415 icon = "tabler-brand-linkedin "
380- value = { url ( ~p" /org/#{ @ bounty . owner . handle } /bounties/#{ @ bounty . id } " ) }
416+ value = {
417+ url (
418+ ~p" /#{ @ ticket_ref . owner } /#{ @ ticket_ref . repo } /issues/#{ @ ticket_ref . number } "
419+ )
420+ }
381421 />
382422 < . social_share_button
383423 id = "hackernews-share-url "
384424 icon = "tabler-brand-ycombinator "
385- value = { url ( ~p" /org/#{ @ bounty . owner . handle } /bounties/#{ @ bounty . id } " ) }
425+ value = {
426+ url (
427+ ~p" /#{ @ ticket_ref . owner } /#{ @ ticket_ref . repo } /issues/#{ @ ticket_ref . number } "
428+ )
429+ }
386430 />
387431 </ div >
388432 </ div >
@@ -635,16 +679,6 @@ defmodule AlgoraWeb.BountyLive do
635679 """
636680 end
637681
638- # defp assign_selected_context(socket, context_id) do
639- # case Enum.find(socket.assigns.contexts, &(&1.id == context_id)) do
640- # nil ->
641- # socket
642-
643- # context ->
644- # assign(socket, :selected_context, context)
645- # end
646- # end
647-
648682 defp assign_recipient ( socket , github_handle ) do
649683 case Workspace . ensure_user ( Admin . token! ( ) , github_handle ) do
650684 { :ok , recipient } ->
@@ -658,7 +692,7 @@ defmodule AlgoraWeb.BountyLive do
658692 defp assign_line_items ( socket ) do
659693 amount = calculate_final_amount ( socket . assigns . reward_form . source )
660694 recipient = socket . assigns . recipient
661- ticket_ref = ticket_ref ( socket )
695+ ticket_ref = socket . assigns . ticket_ref
662696
663697 line_items =
664698 if recipient do
@@ -685,20 +719,12 @@ defmodule AlgoraWeb.BountyLive do
685719 assign ( socket , :line_items , line_items )
686720 end
687721
688- defp ticket_ref ( socket ) do
689- % {
690- owner: socket . assigns . ticket . repository . user . provider_login ,
691- repo: socket . assigns . ticket . repository . name ,
692- number: socket . assigns . ticket . number
693- }
694- end
695-
696722 defp reward_bounty ( socket , bounty , changeset ) do
697723 final_amount = calculate_final_amount ( changeset )
698724
699725 Bounties . reward_bounty (
700726 % { owner: bounty . owner , amount: final_amount , bounty_id: bounty . id , claims: [ ] } ,
701- ticket_ref: ticket_ref ( socket ) ,
727+ ticket_ref: socket . assigns . ticket_ref ,
702728 recipient: socket . assigns . recipient
703729 )
704730 end
@@ -745,10 +771,6 @@ defmodule AlgoraWeb.BountyLive do
745771 """
746772 end
747773
748- defp contexts ( _bounty ) do
749- Accounts . list_featured_developers ( )
750- end
751-
752774 defp close_drawers ( socket ) do
753775 socket
754776 |> assign ( :show_reward_modal , false )
0 commit comments