Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions lib/algora/payments/payments.ex
Original file line number Diff line number Diff line change
Expand Up @@ -838,4 +838,61 @@ defmodule Algora.Payments do
end
end)
end

def list_featured_transactions do
tx_query =
from(tx in Transaction,
where: tx.type == :credit,
where: not is_nil(tx.succeeded_at),
join: u in assoc(tx, :user),
left_join: b in assoc(tx, :bounty),
left_join: tip in assoc(tx, :tip),
join: t in Ticket,
on: t.id == b.ticket_id or t.id == tip.ticket_id,
left_join: r in assoc(t, :repository),
left_join: o in assoc(r, :user),
join: ltx in assoc(tx, :linked_transaction),
join: ltx_user in assoc(ltx, :user),
select: %{
id: tx.id,
succeeded_at: tx.succeeded_at,
net_amount: tx.net_amount,
bounty_id: b.id,
tip_id: tip.id,
user: u,
ticket: %{t | repository: %{r | user: o}},
linked_transaction: %{ltx | user: ltx_user}
}
)

# case Algora.Settings.get_featured_transactions() do
# ids when is_list(ids) and ids != [] ->
# where(tx_query, [tx], tx.id in ^ids)
# _ ->
tx_query =
tx_query
|> where([tx], tx.succeeded_at > ago(2, "week"))
|> order_by([tx], desc: tx.net_amount)
|> limit(10)

# end

transactions =
tx_query
|> Repo.all()
|> Enum.reduce(%{}, fn tx, acc ->
# Group transactions by bounty_id when repository is null and bounty_id exists
if tx.bounty_id && !tx.ticket.repository do
Map.update(acc, tx.bounty_id, tx, fn existing ->
%{existing | net_amount: Money.add!(existing.net_amount, tx.net_amount)}
end)
else
# Keep other transactions as is
Map.put(acc, tx.id, tx)
end
end)
|> Map.values()

Enum.sort_by(transactions, & &1.succeeded_at, {:desc, DateTime})
end
end
3 changes: 2 additions & 1 deletion lib/algora_web/components/header.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ defmodule AlgoraWeb.Components.Header do

defp nav_links do
[
%{name: "Community", path: ~p"/community"},
%{name: "Bounties", path: ~p"/bounties"},
%{name: "Jobs", path: ~p"/jobs"},
%{name: "Docs", path: ~p"/docs"},
%{name: "Pricing", path: ~p"/pricing"}
]
Expand Down
54 changes: 14 additions & 40 deletions lib/algora_web/live/community_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule AlgoraWeb.CommunityLive do
alias Algora.Accounts
alias Algora.Accounts.User
alias Algora.Bounties
alias Algora.Payments
alias Algora.Payments.Transaction
alias Algora.Repo
alias Algora.Workspace
Expand Down Expand Up @@ -62,45 +63,6 @@ defmodule AlgoraWeb.CommunityLive do
featured_devs = Accounts.list_featured_developers()
featured_collabs = list_featured_collabs()

tx_query =
from(tx in Transaction,
where: tx.type == :credit,
where: not is_nil(tx.succeeded_at),
join: u in assoc(tx, :user),
left_join: b in assoc(tx, :bounty),
left_join: tip in assoc(tx, :tip),
join: t in Ticket,
on: t.id == b.ticket_id or t.id == tip.ticket_id,
join: r in assoc(t, :repository),
join: o in assoc(r, :user),
join: ltx in assoc(tx, :linked_transaction),
join: ltx_user in assoc(ltx, :user),
select: %{
id: tx.id,
succeeded_at: tx.succeeded_at,
net_amount: tx.net_amount,
bounty_id: b.id,
tip_id: tip.id,
user: u,
ticket: %{t | repository: %{r | user: o}},
linked_transaction: %{ltx | user: ltx_user}
}
)

tx_query =
case Algora.Settings.get_featured_transactions() do
ids when is_list(ids) and ids != [] ->
where(tx_query, [tx], tx.id in ^ids)

_ ->
tx_query
|> where([tx], tx.succeeded_at > ago(1, "week"))
|> order_by([tx], desc: tx.net_amount)
|> limit(5)
end

transactions = tx_query |> Repo.all() |> Enum.sort_by(& &1.succeeded_at, {:desc, DateTime})

{:ok,
socket
|> assign(:screenshot?, not is_nil(params["screenshot"]))
Expand All @@ -117,7 +79,7 @@ defmodule AlgoraWeb.CommunityLive do
|> assign(:selected_developer, nil)
|> assign(:share_drawer_type, nil)
|> assign(:show_share_drawer, false)
|> assign(:transactions, transactions)
|> assign(:transactions, Payments.list_featured_transactions())
|> assign_query_opts(params["tech"])
|> assign_bounties()}
end
Expand Down Expand Up @@ -1194,6 +1156,18 @@ defmodule AlgoraWeb.CommunityLive do
{:noreply, assign_bounties(socket)}
end

@impl true
def handle_event("create_bounty", %{"bounty_form" => params}, socket) do
Algora.Admin.alert("Bounty intent: #{inspect(params)}", :critical)
{:noreply, redirect(socket, to: ~p"/auth/signup")}
end

@impl true
def handle_event("create_tip", %{"tip_form" => params}, socket) do
Algora.Admin.alert("Tip intent: #{inspect(params)}", :critical)
{:noreply, redirect(socket, to: ~p"/auth/signup")}
end

@impl true
def handle_event("load_more", _params, socket) do
%{bounties: bounties} = socket.assigns
Expand Down
Loading