Skip to content

Commit 69f8c0c

Browse files
committed
feat: render share your profile section if user has OSS contributions or bounties completed
1 parent 61c1707 commit 69f8c0c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/algora/workspace/workspace.ex

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,28 @@ defmodule Algora.Workspace do
637637
Repo.all(query)
638638
end
639639

640+
@spec count_user_contributions(list(String.t()), Keyword.t()) :: {:ok, list(map())} | {:error, term()}
641+
def count_user_contributions(ids, opts \\ []) do
642+
query =
643+
from uc in UserContribution,
644+
join: u in assoc(uc, :user),
645+
join: r in assoc(uc, :repository),
646+
join: repo_owner in assoc(r, :user),
647+
where: u.id in ^ids,
648+
where: not ilike(r.name, "%awesome%"),
649+
where: not ilike(r.name, "%algorithms%"),
650+
where: not ilike(repo_owner.provider_login, "%algorithms%"),
651+
where: repo_owner.type == :organization or r.stargazers_count > 200,
652+
# where: fragment("? && ?::citext[]", r.tech_stack, ^(opts[:tech_stack] || [])),
653+
order_by: [
654+
desc: fragment("CASE WHEN ? && ?::citext[] THEN 1 ELSE 0 END", r.tech_stack, ^(opts[:tech_stack] || [])),
655+
desc: r.stargazers_count
656+
],
657+
select_merge: %{user: u, repository: %{r | user: repo_owner}}
658+
659+
Repo.aggregate(query, :sum, :contribution_count) || 0
660+
end
661+
640662
@spec upsert_user_contribution(String.t(), String.t(), integer()) ::
641663
{:ok, UserContribution.t()} | {:error, Ecto.Changeset.t()}
642664
def upsert_user_contribution(user_id, repository_id, contribution_count) do

lib/algora_web/live/user/dashboard_live.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ defmodule AlgoraWeb.User.DashboardLive do
9494
|> assign(:settings_form, settings_form)
9595
|> assign(:availability_form, availability_form)
9696
|> assign(:total_earned, total_earned)
97+
|> assign(:total_contributions, Algora.Workspace.count_user_contributions([socket.assigns.current_user.id]))
9798
|> assign_bounties()
9899
|> assign_achievements()
99100

@@ -269,7 +270,7 @@ defmodule AlgoraWeb.User.DashboardLive do
269270
</nav>
270271
</div>
271272
<div
272-
:if={not incomplete?(@achievements, :earn_first_bounty_status)}
273+
:if={@total_contributions > 0 or not incomplete?(@achievements, :earn_first_bounty_status)}
273274
class="hidden lg:block pt-12"
274275
>
275276
<div class="flex items-center justify-between">

0 commit comments

Comments
 (0)