Skip to content

Commit f2d78e1

Browse files
committed
feat: update bounties routing and footer links for improved tech filtering
1 parent 14e111d commit f2d78e1

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

lib/algora_web/components/footer.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,31 @@ defmodule AlgoraWeb.Components.Footer do
2323
<li>
2424
<.link
2525
class="text-base font-medium leading-6 text-gray-400 hover:text-white"
26-
navigate={~p"/bounties?#{%{tech: "rust"}}"}
26+
navigate={~p"/bounties/rust"}
2727
>
2828
Rust
2929
</.link>
3030
</li>
3131
<li>
3232
<.link
3333
class="text-base font-medium leading-6 text-gray-400 hover:text-white"
34-
navigate={~p"/bounties?#{%{tech: "typescript"}}"}
34+
navigate={~p"/bounties/typescript"}
3535
>
3636
TypeScript
3737
</.link>
3838
</li>
3939
<li>
4040
<.link
4141
class="text-base font-medium leading-6 text-gray-400 hover:text-white"
42-
navigate={~p"/bounties?#{%{tech: "scala"}}"}
42+
navigate={~p"/bounties/scala"}
4343
>
4444
Scala
4545
</.link>
4646
</li>
4747
<li>
4848
<.link
4949
class="text-base font-medium leading-6 text-gray-400 hover:text-white"
50-
navigate={~p"/bounties?#{%{tech: "c,c++"}}"}
50+
navigate={~p"/bounties/c,c++"}
5151
>
5252
C / C++
5353
</.link>

lib/algora_web/live/bounties_live.ex

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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()}

lib/algora_web/router.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ defmodule AlgoraWeb.Router do
119119
layout: {AlgoraWeb.Layouts, :user},
120120
on_mount: [{AlgoraWeb.UserAuth, :current_user}, AlgoraWeb.User.Nav] do
121121
live "/bounties", BountiesLive, :index
122+
live "/bounties/:tech", BountiesLive, :index
122123
live "/community", CommunityLive, :index
123124
live "/leaderboard", LeaderboardLive, :index
124125
live "/projects", OrgsLive, :index

0 commit comments

Comments
 (0)