Skip to content

Commit 31acfbb

Browse files
committed
feat: update homepage timeline to list featured transactions
1 parent cd221e2 commit 31acfbb

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

lib/algora/settings/settings.ex

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,15 @@ defmodule Algora.Settings do
141141
def set_blocked_users(handles) when is_list(handles) do
142142
set("blocked_users", %{"handles" => handles})
143143
end
144+
145+
def get_featured_transactions do
146+
case get("featured_transactions") do
147+
%{"ids" => ids} when is_list(ids) -> ids
148+
_ -> nil
149+
end
150+
end
151+
152+
def set_featured_transactions(ids) when is_list(ids) do
153+
set("featured_transactions", %{"ids" => ids})
154+
end
144155
end

lib/algora_web/live/home_live.ex

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,10 @@ defmodule AlgoraWeb.HomeLive do
5656
featured_devs = Accounts.list_featured_developers()
5757
featured_collabs = list_featured_collabs()
5858

59-
transactions =
59+
tx_query =
6060
from(tx in Transaction,
6161
where: tx.type == :credit,
6262
where: not is_nil(tx.succeeded_at),
63-
where: tx.succeeded_at > ago(1, "week"),
6463
join: u in assoc(tx, :user),
6564
left_join: b in assoc(tx, :bounty),
6665
left_join: tip in assoc(tx, :tip),
@@ -71,19 +70,30 @@ defmodule AlgoraWeb.HomeLive do
7170
join: ltx in assoc(tx, :linked_transaction),
7271
join: ltx_user in assoc(ltx, :user),
7372
select: %{
73+
id: tx.id,
7474
succeeded_at: tx.succeeded_at,
7575
net_amount: tx.net_amount,
7676
bounty_id: b.id,
7777
tip_id: tip.id,
7878
user: u,
7979
ticket: %{t | repository: %{r | user: o}},
8080
linked_transaction: %{ltx | user: ltx_user}
81-
},
82-
order_by: [desc: tx.net_amount],
83-
limit: 5
81+
}
8482
)
85-
|> Repo.all()
86-
|> Enum.sort_by(& &1.succeeded_at, {:desc, DateTime})
83+
84+
tx_query =
85+
case Algora.Settings.get_featured_transactions() do
86+
ids when is_list(ids) and ids != [] ->
87+
where(tx_query, [tx], tx.id in ^ids)
88+
89+
_ ->
90+
tx_query
91+
|> where([tx], tx.succeeded_at > ago(1, "week"))
92+
|> order_by([tx], desc: tx.net_amount)
93+
|> limit(5)
94+
end
95+
96+
transactions = tx_query |> Repo.all() |> Enum.sort_by(& &1.succeeded_at, {:desc, DateTime})
8797

8898
case socket.assigns[:current_user] do
8999
%{handle: handle} = user when is_binary(handle) ->

0 commit comments

Comments
 (0)