Skip to content

Commit 60a4eb4

Browse files
committed
feat: implement exclusive sharing logic in BountyLive
- Added a new private function `assign_exclusives` to manage users with exclusive access to bounties. - Updated the bounty sharing logic to include the assignment of exclusives after sharing. - Enhanced the UI to display the names of users with exclusive access, replacing previous shared user displays. - Refactored the drawer title from "Share Exclusive" to "Share" for clarity.
1 parent 849a7c3 commit 60a4eb4

File tree

1 file changed

+36
-64
lines changed

1 file changed

+36
-64
lines changed

lib/algora_web/live/bounty_live.ex

Lines changed: 36 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ defmodule AlgoraWeb.BountyLive do
99
alias Algora.Bounties.Bounty
1010
alias Algora.Bounties.LineItem
1111
alias Algora.Repo
12+
alias Algora.Workspace
1213

1314
require Logger
1415

@@ -108,7 +109,22 @@ defmodule AlgoraWeb.BountyLive do
108109
|> assign(:selected_context, nil)
109110
|> assign(:line_items, [])
110111
|> assign(:reward_form, to_form(reward_changeset))
111-
|> assign(:exclusive_form, to_form(exclusive_changeset))}
112+
|> assign(:exclusive_form, to_form(exclusive_changeset))
113+
|> assign_exclusives(bounty.shared_with)}
114+
end
115+
116+
defp assign_exclusives(socket, shared_with) do
117+
exclusives =
118+
Enum.flat_map(shared_with, fn github_handle ->
119+
with {:ok, token} <- Accounts.get_access_token(socket.assigns.current_user),
120+
{:ok, user} <- Workspace.ensure_user(token, github_handle) do
121+
[user]
122+
else
123+
_ -> []
124+
end
125+
end)
126+
127+
assign(socket, :exclusives, exclusives)
112128
end
113129

114130
@impl true
@@ -176,14 +192,20 @@ defmodule AlgoraWeb.BountyLive do
176192

177193
case apply_action(changeset, :save) do
178194
{:ok, data} ->
195+
shared_with = Enum.uniq(bounty.shared_with ++ [data.github_handle])
196+
179197
case bounty
180-
|> Bounty.settings_changeset(%{shared_with: Enum.uniq(bounty.shared_with ++ [data.github_handle])})
198+
|> Bounty.settings_changeset(%{shared_with: shared_with})
181199
|> Repo.update() do
182200
{:ok, _} ->
183-
{:noreply, socket |> put_flash(:info, "Bounty shared") |> close_drawers()}
201+
{:noreply,
202+
socket
203+
|> put_flash(:info, "Bounty shared!")
204+
|> assign_exclusives(shared_with)
205+
|> close_drawers()}
184206

185-
{:error, _reason} ->
186-
Logger.error("Failed to share bounty: #{inspect(_reason)}")
207+
{:error, reason} ->
208+
Logger.error("Failed to share bounty: #{inspect(reason)}")
187209
{:noreply, put_flash(socket, :error, "Something went wrong")}
188210
end
189211

@@ -328,62 +350,27 @@ defmodule AlgoraWeb.BountyLive do
328350
Shared with
329351
</.card_title>
330352
<.button phx-click="exclusive">
331-
Share Exclusive
353+
Share
332354
</.button>
333355
</div>
334356
</.card_header>
335357
<.card_content>
336-
<div class="space-y-4">
337-
<%!-- <div class="flex justify-between text-sm">
358+
<%= for user <- @exclusives do %>
359+
<div class="flex justify-between text-sm">
338360
<span>
339361
<div class="flex items-center gap-4">
340362
<.avatar>
341-
<.avatar_image src={@bounty.owner.avatar_url} />
342-
<.avatar_fallback>{String.first(@bounty.owner.name)}</.avatar_fallback>
363+
<.avatar_image src={user.avatar_url} />
364+
<.avatar_fallback>{String.first(user.name)}</.avatar_fallback>
343365
</.avatar>
344366
<div>
345-
<p class="font-medium">{@bounty.owner.name} Contributors</p>
346-
<p class="text-sm text-muted-foreground">
347-
<% names =
348-
org_contributors(@bounty)
349-
|> Enum.map(&"@#{&1.handle}") %>
350-
{if length(names) > 3,
351-
do: "#{names |> Enum.take(3) |> Enum.join(", ")} and more",
352-
else: "#{names |> Algora.Util.format_name_list()}"}
353-
</p>
367+
<p class="font-medium">{user.name}</p>
368+
<p class="text-sm text-muted-foreground">@{user.provider_login}</p>
354369
</div>
355370
</div>
356371
</span>
357372
</div>
358-
<%= for user <- shared_users(@bounty) do %>
359-
<div class="flex justify-between text-sm">
360-
<span>
361-
<div class="flex items-center gap-4">
362-
<.avatar>
363-
<.avatar_image src={user.avatar_url} />
364-
<.avatar_fallback>{String.first(user.name)}</.avatar_fallback>
365-
</.avatar>
366-
<div>
367-
<p class="font-medium">{user.name}</p>
368-
<p class="text-sm text-muted-foreground">@{User.handle(user)}</p>
369-
</div>
370-
</div>
371-
</span>
372-
</div>
373-
<% end %> --%>
374-
<%= for user <- @bounty.shared_with do %>
375-
<div class="flex justify-between text-sm">
376-
<span>
377-
<div class="flex items-center gap-4">
378-
<.icon name="github" class="h-10 w-10 text-muted-foreground" />
379-
<div>
380-
<p class="font-medium">{user}</p>
381-
</div>
382-
</div>
383-
</span>
384-
</div>
385-
<% end %>
386-
</div>
373+
<% end %>
387374
</.card_content>
388375
</.card>
389376
</div>
@@ -397,7 +384,7 @@ defmodule AlgoraWeb.BountyLive do
397384
direction="right"
398385
>
399386
<.drawer_header>
400-
<.drawer_title>Share Exclusive</.drawer_title>
387+
<.drawer_title>Share</.drawer_title>
401388
<.drawer_description>
402389
Make this bounty exclusive to specific users
403390
</.drawer_description>
@@ -535,21 +522,6 @@ defmodule AlgoraWeb.BountyLive do
535522
"""
536523
end
537524

538-
# TODO: implement this
539-
defp shared_users(_bounty) do
540-
Enum.drop(Accounts.list_featured_developers(), 3)
541-
end
542-
543-
# TODO: implement this
544-
defp invited_users(_bounty) do
545-
546-
end
547-
548-
# TODO: implement this
549-
defp org_contributors(_bounty) do
550-
Enum.take(Accounts.list_featured_developers(), 3)
551-
end
552-
553525
defp contexts(_bounty) do
554526
Accounts.list_featured_developers()
555527
end

0 commit comments

Comments
 (0)