Skip to content

Commit fd16bef

Browse files
committed
add /claims/:id
1 parent 0378891 commit fd16bef

File tree

4 files changed

+204
-22
lines changed

4 files changed

+204
-22
lines changed

lib/algora_web/live/claim_live.ex

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
defmodule AlgoraWeb.ClaimLive do
2+
@moduledoc false
3+
use AlgoraWeb, :live_view
4+
5+
alias Algora.Bounties.Claim
6+
alias Algora.Repo
7+
8+
@impl true
9+
def mount(%{"id" => id}, _session, socket) do
10+
{:ok, claim} = Repo.fetch(Claim, id)
11+
12+
claim = Repo.preload(claim, [:user, source: [repository: [:user]], target: [repository: [:user], bounties: [:owner]]])
13+
14+
dbg(claim)
15+
{:ok, prize_pool} = claim.target.bounties |> Enum.map(& &1.amount) |> Money.sum()
16+
17+
{:ok,
18+
socket
19+
|> assign(:page_title, "Claim Details")
20+
|> assign(:claim, claim)
21+
|> assign(:target, claim.target)
22+
|> assign(:source, claim.source)
23+
|> assign(:user, claim.user)
24+
|> assign(:bounties, claim.target.bounties)
25+
|> assign(:prize_pool, prize_pool)}
26+
end
27+
28+
@impl true
29+
def render(assigns) do
30+
~H"""
31+
<div class="container mx-auto py-8 px-4">
32+
<div class="space-y-8">
33+
<%!-- Header with target issue and prize pool --%>
34+
<.header class="mb-8">
35+
<div class="space-y-2">
36+
<.link href={@target.url} class="text-xl font-semibold hover:underline" target="_blank">
37+
{@target.title}
38+
</.link>
39+
<div class="text-sm text-muted-foreground">
40+
{@source.repository.user.provider_login}/{@source.repository.name}#{@source.number}
41+
</div>
42+
</div>
43+
<:subtitle>
44+
<div class="mt-4 text-2xl font-bold text-success font-display">
45+
{Money.to_string!(@prize_pool)}
46+
</div>
47+
</:subtitle>
48+
<:actions>
49+
<.button variant="outline">
50+
<.icon name="tabler-clock" class="mr-2 h-4 w-4" />
51+
{@claim.status |> to_string() |> String.capitalize()}
52+
</.button>
53+
</:actions>
54+
</.header>
55+
56+
<%!-- Claimant and Sponsors Cards --%>
57+
<div class="grid gap-8 md:grid-cols-2">
58+
<%!-- Claimer Info --%>
59+
<.card>
60+
<.card_header>
61+
<.card_title>
62+
<div class="flex items-center gap-2">
63+
<.icon name="tabler-user" class="h-5 w-5 text-muted-foreground" /> Claimed By
64+
</div>
65+
</.card_title>
66+
</.card_header>
67+
<.card_content>
68+
<div class="flex items-center gap-4">
69+
<.avatar>
70+
<.avatar_image src={@user.avatar_url} />
71+
<.avatar_fallback>
72+
{String.first(@user.name)}
73+
</.avatar_fallback>
74+
</.avatar>
75+
<div>
76+
<p class="font-medium">{@user.name}</p>
77+
<p class="text-sm text-muted-foreground">@{@user.handle}</p>
78+
</div>
79+
</div>
80+
</.card_content>
81+
</.card>
82+
83+
<%!-- Bounty Sponsors Card --%>
84+
<.card>
85+
<.card_header>
86+
<.card_title>
87+
<div class="flex items-center gap-2">
88+
<.icon name="tabler-users" class="h-5 w-5 text-muted-foreground" /> Sponsors
89+
</div>
90+
</.card_title>
91+
</.card_header>
92+
<.card_content>
93+
<div class="divide-y divide-border">
94+
<%= for bounty <- @bounties do %>
95+
<div class="flex items-center justify-between py-4">
96+
<div class="flex items-center gap-4">
97+
<.avatar>
98+
<.avatar_image src={bounty.owner.avatar_url} />
99+
<.avatar_fallback>
100+
{String.first(bounty.owner.name)}
101+
</.avatar_fallback>
102+
</.avatar>
103+
<div>
104+
<p class="font-medium">{bounty.owner.name}</p>
105+
<p class="text-sm text-muted-foreground">@{bounty.owner.handle}</p>
106+
</div>
107+
</div>
108+
<.badge variant="secondary">
109+
{Money.to_string!(bounty.amount)}
110+
</.badge>
111+
</div>
112+
<% end %>
113+
</div>
114+
</.card_content>
115+
</.card>
116+
</div>
117+
118+
<%!-- Pull Request Details --%>
119+
<.card>
120+
<.card_header>
121+
<.card_title>
122+
<div class="flex items-center gap-2">
123+
<.icon name="tabler-git-pull-request" class="h-5 w-5 text-muted-foreground" />
124+
Pull Request
125+
</div>
126+
</.card_title>
127+
</.card_header>
128+
<.card_content>
129+
<div class="space-y-4">
130+
<.link href={@source.url} class="text-lg font-semibold hover:underline" target="_blank">
131+
{@source.title}
132+
</.link>
133+
<div class="text-sm text-muted-foreground">
134+
{@source.repository.user.provider_login}/{@source.repository.name}#{@source.number}
135+
</div>
136+
<div class="mt-4">
137+
{@source.description}
138+
</div>
139+
</div>
140+
</.card_content>
141+
</.card>
142+
</div>
143+
</div>
144+
"""
145+
end
146+
end

lib/algora_web/router.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ defmodule AlgoraWeb.Router do
140140
live "/trotw", TROTWLive
141141

142142
live "/open-source", OpenSourceLive, :index
143+
144+
live "/claims/:id", ClaimLive
143145
end
144146

145147
# Other scopes may use custom stacks.

priv/repo/seeds.exs

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ for {repo_name, issues} <- repos do
357357
for {issue_title, index} <- Enum.with_index(issues, 1) do
358358
issue =
359359
insert!(:ticket, %{
360+
type: :issue,
360361
repository_id: repo.id,
361362
title: issue_title,
362363
description: "We need help implementing this feature to improve our platform.",
@@ -378,36 +379,63 @@ for {repo_name, issues} <- repos do
378379
status: if(paid, do: :paid, else: :open)
379380
})
380381

381-
if not claimed do
382-
pied_piper_members
383-
|> Enum.take_random(Enum.random(0..(length(pied_piper_members) - 1)))
384-
|> Enum.each(fn member ->
385-
amount = Money.new!(Enum.random([500, 1000, 1500, 2000]), :USD)
386-
387-
insert!(:bounty, %{
388-
ticket_id: issue.id,
389-
owner_id: member.id,
390-
creator_id: member.id,
391-
amount: amount,
392-
status: :open
393-
})
394-
end)
395-
end
382+
pied_piper_members
383+
|> Enum.take_random(Enum.random(0..(length(pied_piper_members) - 1)))
384+
|> Enum.each(fn member ->
385+
amount = Money.new!(Enum.random([500, 1000, 1500, 2000]), :USD)
386+
387+
insert!(:bounty, %{
388+
ticket_id: issue.id,
389+
owner_id: member.id,
390+
creator_id: member.id,
391+
amount: amount,
392+
status: :open
393+
})
394+
end)
396395

397396
if claimed do
398397
pull_request =
399398
insert!(:ticket, %{
400-
user_id: carver.id,
401-
title: "Implementation for #{issue_title}",
402-
description: "Here's my solution to this issue.",
399+
type: :pull_request,
400+
repository_id: repo.id,
401+
title: "Fix memory leak in upload handler and optimize buffer allocation",
402+
description: """
403+
This PR addresses the memory leak in the file upload handler by:
404+
- Implementing proper buffer cleanup in the streaming pipeline
405+
- Adding automatic resource disposal using with-clauses
406+
- Optimizing memory allocation for large file uploads
407+
- Adding memory usage monitoring
408+
409+
Testing shows a 60% reduction in memory usage during sustained uploads.
410+
411+
Key changes:
412+
```python
413+
def process_upload(file_stream):
414+
try:
415+
with MemoryManager.track() as memory:
416+
for chunk in file_stream:
417+
# Optimize buffer allocation
418+
buffer = BytesIO(initial_size=chunk.size)
419+
compressed = middle_out.compress(chunk, buffer)
420+
yield compressed
421+
422+
memory.log_usage("Upload complete")
423+
finally:
424+
buffer.close()
425+
gc.collect() # Force cleanup
426+
```
427+
428+
Closes ##{index}
429+
""",
430+
number: index + length(issues),
403431
url: "https://github.com/piedpiper/#{repo_name}/pull/#{index}"
404432
})
405433

406434
claim =
407435
insert!(:claim, %{
408436
user_id: carver.id,
409-
target_id: pull_request.id,
410-
source_id: issue.id,
437+
target_id: issue.id,
438+
source_id: pull_request.id,
411439
type: :pull_request,
412440
status: if(paid, do: :paid, else: :pending),
413441
url: "https://github.com/piedpiper/#{repo_name}/pull/#{index}"

test/support/factory.ex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ defmodule Algora.Factory do
6666
twitter_url: "https://twitter.com/piedpiper",
6767
github_url: "https://github.com/piedpiper",
6868
discord_url: "https://discord.gg/piedpiper",
69-
slack_url: "https://piedpiper.slack.com"
69+
slack_url: "https://piedpiper.slack.com",
70+
provider: "github",
71+
provider_login: "piedpiper",
72+
provider_id: sequence(:provider_id, &"#{&1}")
7073
}
7174
end
7275

@@ -195,8 +198,11 @@ defmodule Algora.Factory do
195198
end
196199

197200
def claim_factory do
201+
id = Nanoid.generate()
202+
198203
%Algora.Bounties.Claim{
199-
id: Nanoid.generate(),
204+
id: id,
205+
group_id: id,
200206
type: :pull_request,
201207
status: :pending
202208
}

0 commit comments

Comments
 (0)