Skip to content

Commit f19b6f3

Browse files
committed
feat: add repository form to HomeLive for GitHub URL submission
- Introduced a new RepoForm module to handle GitHub repository URL input. - Implemented validation for the URL format to ensure it matches GitHub repository standards. - Added a form in the HomeLive view for users to submit their GitHub repository, enhancing user interaction. - Updated the mount function to include the new repo_form assignment for rendering.
1 parent 5fbf967 commit f19b6f3

File tree

2 files changed

+66
-141
lines changed

2 files changed

+66
-141
lines changed

lib/algora_web/live/home_live.ex

Lines changed: 65 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,35 @@ defmodule AlgoraWeb.HomeLive do
1515
alias Algora.Workspace
1616
alias AlgoraWeb.Components.Footer
1717
alias AlgoraWeb.Components.Header
18+
alias AlgoraWeb.Components.Logos
1819
alias AlgoraWeb.Components.Wordmarks
1920
alias AlgoraWeb.Data.PlatformStats
2021
alias AlgoraWeb.Forms.BountyForm
2122
alias AlgoraWeb.Forms.TipForm
2223

2324
require Logger
2425

26+
defmodule RepoForm do
27+
@moduledoc false
28+
use Ecto.Schema
29+
30+
import Ecto.Changeset
31+
32+
@primary_key false
33+
embedded_schema do
34+
field :url, :string
35+
end
36+
37+
def changeset(form, attrs) do
38+
form
39+
|> cast(attrs, [:url])
40+
|> validate_required([:url])
41+
|> validate_format(:url, ~r{^https?://github\.com/[^/]+/[^/\s]+$}i,
42+
message: "Must be a valid GitHub repository URL (e.g. github.com/owner/repo)"
43+
)
44+
end
45+
end
46+
2547
@impl true
2648
def mount(%{"country_code" => country_code}, _session, socket) do
2749
Gettext.put_locale(AlgoraWeb.Gettext, Algora.Util.locale_from_country_code(country_code))
@@ -46,6 +68,7 @@ defmodule AlgoraWeb.HomeLive do
4668
|> assign(:bounty_form, to_form(BountyForm.changeset(%BountyForm{}, %{})))
4769
# TODO: add url
4870
|> assign(:tip_form, to_form(TipForm.changeset(%TipForm{}, %{})))
71+
|> assign(:repo_form, to_form(RepoForm.changeset(%RepoForm{}, %{})))
4972
|> assign(:pending_action, nil)}
5073
end
5174

@@ -64,29 +87,29 @@ defmodule AlgoraWeb.HomeLive do
6487
<h1 class="font-display text-5xl font-semibold tracking-tight text-foreground sm:text-7xl">
6588
The open source Upwork for engineers
6689
</h1>
67-
<p class="mt-8 font-display text-lg font-medium text-muted-foreground sm:max-w-md sm:text-2xl/8 lg:max-w-none">
90+
<p class="mt-8 text-lg font-medium text-muted-foreground sm:max-w-md sm:text-2xl/8 lg:max-w-none">
6891
Discover GitHub bounties, contract work and jobs
6992
</p>
70-
<p class="mt-4 font-display text-lg font-medium text-muted-foreground sm:max-w-md sm:text-2xl/8 lg:max-w-none">
93+
<p class="mt-4 text-lg font-medium text-muted-foreground sm:max-w-md sm:text-2xl/8 lg:max-w-none">
7194
Hire the top 1% open source developers
7295
</p>
7396
<!-- CTA buttons -->
74-
<div class="mt-10 flex flex-col sm:flex-row text-center sm:items-center gap-6">
75-
<.button
76-
navigate={~p"/onboarding/org"}
77-
variant="default"
78-
class="px-12 py-8 text-xl font-semibold"
79-
>
80-
Companies
81-
</.button>
82-
<.button
83-
navigate={~p"/onboarding/dev"}
84-
variant="secondary"
85-
class="px-12 py-8 text-xl font-semibold"
86-
>
87-
Developers
88-
</.button>
89-
</div>
97+
<.form for={@repo_form} phx-submit="submit_repo" class="mt-10 w-full max-w-2xl">
98+
<div class="relative">
99+
<.input
100+
field={@repo_form[:url]}
101+
placeholder="https://github.com/your/repo"
102+
class="w-full h-16 text-xl sm:text-2xl pl-[3.75rem] pr-48 border-emerald-500 font-display"
103+
/>
104+
<Logos.github class="h-10 w-10 absolute left-3 top-3 text-muted-foreground/50" />
105+
<.button
106+
type="submit"
107+
class="absolute right-2 top-2 bottom-2 px-8 h-[3rem] text-xl font-semibold"
108+
>
109+
Get Started
110+
</.button>
111+
</div>
112+
</.form>
90113
</div>
91114
<!-- Featured devs -->
92115
<div class="mt-14 flex justify-start md:justify-center gap-8 lg:justify-start lg:mt-0 lg:pl-0 overflow-x-auto scrollbar-thin lg:overflow-x-visible">
@@ -112,129 +135,6 @@ defmodule AlgoraWeb.HomeLive do
112135
</div>
113136
</section>
114137
115-
<%!-- <section
116-
class="relative isolate overflow-hidden bg-gradient-to-br from-black to-background border-t py-16 sm:py-40"
117-
>
118-
<.pattern />
119-
<div class="mx-auto max-w-7xl px-6 lg:px-8">
120-
<h2 class="font-display text-3xl font-semibold tracking-tight text-foreground sm:text-6xl text-center mb-4">
121-
Fund GitHub Issues
122-
</h2>
123-
<p class="text-center font-medium text-base text-muted-foreground mb-16">
124-
Support open source development with bounties on GitHub issues
125-
</p>
126-
127-
<div class="grid grid-cols-1 gap-16">
128-
<.link
129-
href="https://github.com/zed-industries/zed/issues/4440"
130-
rel="noopener"
131-
class="relative flex items-center gap-x-4 rounded-xl bg-black p-6 ring-1 ring-border transition-colors"
132-
>
133-
<div class="flex -space-x-4">
134-
<img
135-
class="h-20 w-20 rounded-full z-0"
136-
src="https://github.com/zed-industries.png"
137-
alt="Zed"
138-
/>
139-
<img
140-
class="h-20 w-20 rounded-full z-10"
141-
src="https://github.com/schacon.png"
142-
alt="Scott Chacon"
143-
/>
144-
</div>
145-
<div class="text-base leading-6 flex-1">
146-
<div class="text-2xl font-semibold text-foreground">
147-
GitHub cofounder funds new feature in Zed Editor
148-
</div>
149-
<div class="text-lg font-medium text-muted-foreground">
150-
Zed Editor, Scott Chacon
151-
</div>
152-
</div>
153-
<.button size="lg" variant="secondary">
154-
<Logos.github class="size-4 mr-4 -ml-2" /> View issue
155-
</.button>
156-
</.link>
157-
158-
<.link
159-
href="https://github.com/PX4/PX4-Autopilot/issues/22464"
160-
rel="noopener"
161-
class="relative flex items-center gap-x-4 rounded-xl bg-black p-6 ring-1 ring-border transition-colors"
162-
>
163-
<div class="flex items-center -space-x-6">
164-
<img
165-
class="h-20 w-20 rounded-full z-0"
166-
src="https://pbs.twimg.com/profile_images/1277333515412045824/Xys6F_6E_400x400.jpg"
167-
alt="Alex Klimaj"
168-
/>
169-
<img class="h-16 w-16 z-20" src="https://github.com/PX4.png" alt="PX4" />
170-
<img
171-
class="h-20 w-20 rounded-full z-10"
172-
src="https://pbs.twimg.com/profile_images/1768744461243387905/AHYQnqY9_400x400.jpg"
173-
alt="Andrew Wilkins"
174-
/>
175-
</div>
176-
<div class="text-base leading-6 flex-1">
177-
<div class="text-2xl font-semibold text-foreground">
178-
DefenceTech CEOs fund obstacle avoidance in PX4 Drone Autopilot
179-
</div>
180-
<div class="text-lg font-medium text-muted-foreground">
181-
Alex Klimaj, Founder of ARK Electronics & Andrew Wilkins, CEO of Ascend Engineering
182-
</div>
183-
</div>
184-
<.button size="lg" variant="secondary">
185-
<Logos.github class="size-4 mr-4 -ml-2" /> View issue
186-
</.button>
187-
</.link>
188-
189-
<div class="relative grid grid-cols-5 items-center w-full gap-x-4 rounded-xl bg-black p-12 ring-2 ring-success/20 transition-colors">
190-
<div class="col-span-2 text-base leading-6 flex-1">
191-
<div class="text-3xl font-semibold text-foreground">
192-
Fund any issue <span class="text-success">in seconds</span>
193-
</div>
194-
<div class="text-lg font-medium text-muted-foreground">
195-
Help improve the OSS you love and rely on
196-
</div>
197-
<div class="pt-1 col-span-3 text-sm text-muted-foreground space-y-0.5">
198-
<div>
199-
<.icon name="tabler-check" class="h-4 w-4 mr-1 text-success-400" />
200-
Pay when PRs are merged
201-
</div>
202-
<div>
203-
<.icon name="tabler-check" class="h-4 w-4 mr-1 text-success-400" />
204-
Pool bounties with other sponsors
205-
</div>
206-
<div>
207-
<.icon name="tabler-check" class="h-4 w-4 mr-1 text-success-400" />
208-
Algora handles invoices, payouts, compliance & 1099s
209-
</div>
210-
</div>
211-
</div>
212-
<.form
213-
for={@bounty_form}
214-
phx-submit="create_bounty"
215-
class="col-span-3 grid grid-cols-3 gap-6 w-full"
216-
>
217-
<.input
218-
label="URL"
219-
field={@bounty_form[:url]}
220-
placeholder="https://github.com/owner/repo/issues/1337"
221-
/>
222-
<.input
223-
label="Amount"
224-
icon="tabler-currency-dollar"
225-
field={@bounty_form[:amount]}
226-
class="placeholder:text-success"
227-
/>
228-
<div class="flex flex-col items-center gap-2">
229-
<div class="text-sm text-muted-foreground">No credit card required</div>
230-
<.button size="lg" class="w-full">Fund issue</.button>
231-
</div>
232-
</.form>
233-
</div>
234-
</div>
235-
</div>
236-
</section> --%>
237-
238138
<section class="relative isolate overflow-hidden bg-gradient-to-br from-black to-background border-t py-16 sm:py-40">
239139
<.pattern />
240140
<div class="mx-auto max-w-7xl px-6 lg:px-8">
@@ -918,6 +818,30 @@ defmodule AlgoraWeb.HomeLive do
918818
end
919819
end
920820

821+
@impl true
822+
def handle_event("submit_repo", %{"repo_form" => params}, socket) do
823+
changeset =
824+
%RepoForm{}
825+
|> RepoForm.changeset(params)
826+
|> Map.put(:action, :validate)
827+
828+
if changeset.valid? do
829+
# Extract owner and repo from URL
830+
url = get_field(changeset, :url)
831+
832+
case Regex.run(~r{github\.com/([^/]+)/([^/\s]+)}, url) do
833+
[_, owner, repo] ->
834+
{:noreply, push_navigate(socket, to: ~p"/go/#{owner}/#{repo}")}
835+
836+
_ ->
837+
{:noreply,
838+
assign(socket, :repo_form, to_form(RepoForm.add_error(changeset, :url, "Invalid GitHub repository URL")))}
839+
end
840+
else
841+
{:noreply, assign(socket, :repo_form, to_form(changeset))}
842+
end
843+
end
844+
921845
@impl true
922846
def handle_info({:authenticated, user}, socket) do
923847
socket = assign(socket, :current_user, user)

lib/algora_web/live/org/dashboard_live.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,7 @@ defmodule AlgoraWeb.Org.DashboardLive do
12741274
placeholder="https://github.com/owner/repo/issues/123"
12751275
helptext="We'll add a comment to the issue to notify the developer."
12761276
/>
1277+
<%!-- # TODO: implement --%>
12771278
<.input
12781279
label="Review (optional)"
12791280
field={@tip_form[:message]}

0 commit comments

Comments
 (0)