@@ -9,10 +9,8 @@ defmodule AlgoraWeb.BountiesLive do
99 require Logger
1010
1111 @ impl true
12- def handle_params ( params , _uri , socket ) do
13- selected_techs =
14- ( params [ "tech" ] || "" ) |> String . split ( "," ) |> Enum . reject ( & ( & 1 == "" ) ) |> Enum . map ( & String . downcase / 1 )
15-
12+ def handle_params ( % { "tech" => tech } , _uri , socket ) when is_binary ( tech ) do
13+ selected_techs = tech |> String . split ( "," ) |> Enum . reject ( & ( & 1 == "" ) ) |> Enum . map ( & String . downcase / 1 )
1614 valid_techs = Enum . map ( socket . assigns . techs , fn { tech , _ } -> String . downcase ( tech ) end )
1715 # Only keep valid techs that exist in the available tech list
1816 selected_techs = Enum . filter ( selected_techs , & ( & 1 in valid_techs ) )
@@ -31,15 +29,23 @@ defmodule AlgoraWeb.BountiesLive do
3129 |> assign_bounties ( ) }
3230 end
3331
32+ def handle_params ( _params , _uri , socket ) do
33+ { :noreply ,
34+ socket
35+ |> assign ( :selected_techs , [ ] )
36+ |> assign ( :query_opts , Keyword . delete ( socket . assigns . query_opts , :tech_stack ) )
37+ |> assign_bounties ( ) }
38+ end
39+
3440 @ impl true
35- def mount ( params , _session , socket ) do
41+ def mount ( % { "tech" => tech } , _session , socket ) when is_binary ( tech ) do
3642 if connected? ( socket ) do
3743 Bounties . subscribe ( )
3844 end
3945
4046 # Parse selected techs from URL params and ensure lowercase
4147 selected_techs =
42- ( params [ " tech" ] || "" )
48+ tech
4349 |> String . split ( "," )
4450 |> Enum . reject ( & ( & 1 == "" ) )
4551 |> Enum . map ( & String . downcase / 1 )
@@ -71,6 +77,32 @@ defmodule AlgoraWeb.BountiesLive do
7177 |> assign_bounties ( ) }
7278 end
7379
80+ def mount ( _params , _session , socket ) do
81+ if connected? ( socket ) do
82+ Bounties . subscribe ( )
83+ end
84+
85+ query_opts =
86+ [
87+ status: :open ,
88+ limit: page_size ( )
89+ ] ++
90+ if socket . assigns . current_user do
91+ [ amount_gt: Money . new ( :USD , 200 ) ]
92+ else
93+ [ amount_gt: Money . new ( :USD , 500 ) ]
94+ end
95+
96+ techs = Bounties . list_tech ( query_opts )
97+
98+ { :ok ,
99+ socket
100+ |> assign ( :techs , techs )
101+ |> assign ( :selected_techs , [ ] )
102+ |> assign ( :query_opts , query_opts )
103+ |> assign_bounties ( ) }
104+ end
105+
74106 @ impl true
75107 def render ( assigns ) do
76108 ~H"""
@@ -157,11 +189,11 @@ defmodule AlgoraWeb.BountiesLive do
157189 end
158190
159191 # Update the URL with selected techs
160- tech_param = if selected_techs == [ ] , do: nil , else: Enum . join ( selected_techs , "," )
192+ path = if selected_techs == [ ] , do: ~p " /bounties " , else: ~p " /bounties/ #{ Enum . join ( selected_techs , "," ) } "
161193
162194 { :noreply ,
163195 socket
164- |> push_patch ( to: ~p " /bounties? #{ % { tech: tech_param } } " )
196+ |> push_patch ( to: path )
165197 |> assign ( :selected_techs , selected_techs )
166198 |> assign ( :query_opts , query_opts )
167199 |> assign_bounties ( ) }
0 commit comments