Skip to content

Commit 848e08b

Browse files
authored
feat: homepage updates (#133)
1 parent a1718a0 commit 848e08b

File tree

4 files changed

+964
-452
lines changed

4 files changed

+964
-452
lines changed

lib/algora/payments/payments.ex

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,4 +838,61 @@ defmodule Algora.Payments do
838838
end
839839
end)
840840
end
841+
842+
def list_featured_transactions do
843+
tx_query =
844+
from(tx in Transaction,
845+
where: tx.type == :credit,
846+
where: not is_nil(tx.succeeded_at),
847+
join: u in assoc(tx, :user),
848+
left_join: b in assoc(tx, :bounty),
849+
left_join: tip in assoc(tx, :tip),
850+
join: t in Ticket,
851+
on: t.id == b.ticket_id or t.id == tip.ticket_id,
852+
left_join: r in assoc(t, :repository),
853+
left_join: o in assoc(r, :user),
854+
join: ltx in assoc(tx, :linked_transaction),
855+
join: ltx_user in assoc(ltx, :user),
856+
select: %{
857+
id: tx.id,
858+
succeeded_at: tx.succeeded_at,
859+
net_amount: tx.net_amount,
860+
bounty_id: b.id,
861+
tip_id: tip.id,
862+
user: u,
863+
ticket: %{t | repository: %{r | user: o}},
864+
linked_transaction: %{ltx | user: ltx_user}
865+
}
866+
)
867+
868+
# case Algora.Settings.get_featured_transactions() do
869+
# ids when is_list(ids) and ids != [] ->
870+
# where(tx_query, [tx], tx.id in ^ids)
871+
# _ ->
872+
tx_query =
873+
tx_query
874+
|> where([tx], tx.succeeded_at > ago(2, "week"))
875+
|> order_by([tx], desc: tx.net_amount)
876+
|> limit(10)
877+
878+
# end
879+
880+
transactions =
881+
tx_query
882+
|> Repo.all()
883+
|> Enum.reduce(%{}, fn tx, acc ->
884+
# Group transactions by bounty_id when repository is null and bounty_id exists
885+
if tx.bounty_id && !tx.ticket.repository do
886+
Map.update(acc, tx.bounty_id, tx, fn existing ->
887+
%{existing | net_amount: Money.add!(existing.net_amount, tx.net_amount)}
888+
end)
889+
else
890+
# Keep other transactions as is
891+
Map.put(acc, tx.id, tx)
892+
end
893+
end)
894+
|> Map.values()
895+
896+
Enum.sort_by(transactions, & &1.succeeded_at, {:desc, DateTime})
897+
end
841898
end

lib/algora_web/components/header.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ defmodule AlgoraWeb.Components.Header do
77

88
defp nav_links do
99
[
10-
%{name: "Community", path: ~p"/community"},
10+
%{name: "Bounties", path: ~p"/bounties"},
11+
%{name: "Jobs", path: ~p"/jobs"},
1112
%{name: "Docs", path: ~p"/docs"},
1213
%{name: "Pricing", path: ~p"/pricing"}
1314
]

lib/algora_web/live/community_live.ex

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ defmodule AlgoraWeb.CommunityLive do
1111
alias Algora.Accounts
1212
alias Algora.Accounts.User
1313
alias Algora.Bounties
14+
alias Algora.Payments
1415
alias Algora.Payments.Transaction
1516
alias Algora.Repo
1617
alias Algora.Workspace
@@ -62,45 +63,6 @@ defmodule AlgoraWeb.CommunityLive do
6263
featured_devs = Accounts.list_featured_developers()
6364
featured_collabs = list_featured_collabs()
6465

65-
tx_query =
66-
from(tx in Transaction,
67-
where: tx.type == :credit,
68-
where: not is_nil(tx.succeeded_at),
69-
join: u in assoc(tx, :user),
70-
left_join: b in assoc(tx, :bounty),
71-
left_join: tip in assoc(tx, :tip),
72-
join: t in Ticket,
73-
on: t.id == b.ticket_id or t.id == tip.ticket_id,
74-
join: r in assoc(t, :repository),
75-
join: o in assoc(r, :user),
76-
join: ltx in assoc(tx, :linked_transaction),
77-
join: ltx_user in assoc(ltx, :user),
78-
select: %{
79-
id: tx.id,
80-
succeeded_at: tx.succeeded_at,
81-
net_amount: tx.net_amount,
82-
bounty_id: b.id,
83-
tip_id: tip.id,
84-
user: u,
85-
ticket: %{t | repository: %{r | user: o}},
86-
linked_transaction: %{ltx | user: ltx_user}
87-
}
88-
)
89-
90-
tx_query =
91-
case Algora.Settings.get_featured_transactions() do
92-
ids when is_list(ids) and ids != [] ->
93-
where(tx_query, [tx], tx.id in ^ids)
94-
95-
_ ->
96-
tx_query
97-
|> where([tx], tx.succeeded_at > ago(1, "week"))
98-
|> order_by([tx], desc: tx.net_amount)
99-
|> limit(5)
100-
end
101-
102-
transactions = tx_query |> Repo.all() |> Enum.sort_by(& &1.succeeded_at, {:desc, DateTime})
103-
10466
{:ok,
10567
socket
10668
|> assign(:screenshot?, not is_nil(params["screenshot"]))
@@ -117,7 +79,7 @@ defmodule AlgoraWeb.CommunityLive do
11779
|> assign(:selected_developer, nil)
11880
|> assign(:share_drawer_type, nil)
11981
|> assign(:show_share_drawer, false)
120-
|> assign(:transactions, transactions)
82+
|> assign(:transactions, Payments.list_featured_transactions())
12183
|> assign_query_opts(params["tech"])
12284
|> assign_bounties()}
12385
end
@@ -1194,6 +1156,18 @@ defmodule AlgoraWeb.CommunityLive do
11941156
{:noreply, assign_bounties(socket)}
11951157
end
11961158

1159+
@impl true
1160+
def handle_event("create_bounty", %{"bounty_form" => params}, socket) do
1161+
Algora.Admin.alert("Bounty intent: #{inspect(params)}", :critical)
1162+
{:noreply, redirect(socket, to: ~p"/auth/signup")}
1163+
end
1164+
1165+
@impl true
1166+
def handle_event("create_tip", %{"tip_form" => params}, socket) do
1167+
Algora.Admin.alert("Tip intent: #{inspect(params)}", :critical)
1168+
{:noreply, redirect(socket, to: ~p"/auth/signup")}
1169+
end
1170+
11971171
@impl true
11981172
def handle_event("load_more", _params, socket) do
11991173
%{bounties: bounties} = socket.assigns

0 commit comments

Comments
 (0)