Skip to content

Commit

Permalink
Merge pull request #1177 from animina-dating/beta-registration-filter…
Browse files Browse the repository at this point in the history
…-potentials

Created Algorithm for Potential Partners in Beta Register Page
  • Loading branch information
wintermeyer authored Dec 2, 2024
2 parents 3c53b10 + 5d281f2 commit aab5b4f
Show file tree
Hide file tree
Showing 4 changed files with 249 additions and 36 deletions.
21 changes: 21 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ config :animina, :ai_message_help_price, 20
# Configures whether to have ai automatically respond to messages
config :animina, :autoreply_messages_with_ai, false

# Configures default maximum age for potential partners
config :animina, :default_potential_partner_maximum_age, 100

# Configures default minimum age for potential partners
config :animina, :default_potential_partner_minimum_age, 18

# confugures the difference in age if no maximum or minimum age is set
config :animina, :default_partner_age_offset, 10

# Configures the maximum height for potential partners
config :animina, :default_potential_partner_maximum_height, 225

# Configures the minimum height for potential partners
config :animina, :default_potential_partner_minimum_height, 0

# Configures the maximum height difference for potential partners
config :animina, :default_partner_height_offset, 10

# Configures the default search range for potential partners in km
config :animina, :default_potential_partner_search_range_in_km, 10_000

config :animina,
ecto_repos: [Animina.Repo],
generators: [timestamp_type: :utc_datetime]
Expand Down
38 changes: 21 additions & 17 deletions lib/animina_web/components/beta_registration_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule AniminaWeb.BetaRegistrationComponents do
<h2 class="text-2xl mt-3 font-semibold dark:text-white">
<%= with_locale(@language, fn -> %>
<%= gettext("Current Potential Partners:") %> 123
<%= gettext("Current Potential Partners:") %> <%= @number_of_potential_partners %>
<% end) %>
</h2>
Expand All @@ -37,7 +37,7 @@ defmodule AniminaWeb.BetaRegistrationComponents do
id="beta_user_registration_form"
for={@form}
class="space-y-6 mt-6 group "
phx-change="validate"
phx-change="validate_and_filter_potential_partners"
phx-submit="submit"
>
<h2 class="text-2xl mt-3 font-semibold dark:text-white">
Expand Down Expand Up @@ -209,7 +209,7 @@ defmodule AniminaWeb.BetaRegistrationComponents do
</span>
</label>
<div phx-feedback-for={@f[:height].name} class="mt-2 w-[100%]">
<%= text_input(@f, :height,
<%= number_input(@f, :height,
class:
"block w-full rounded-md border-0 py-1.5 text-gray-900 dark:bg-gray-700 dark:text-white shadow-sm ring-1 ring-inset placeholder:text-gray-400 focus:ring-2 focus:ring-inset sm:text-sm phx-no-feedback:ring-gray-300 phx-no-feedback:focus:ring-indigo-600 sm:leading-6 " <>
unless(get_field_errors(@f[:height], :height) == [],
Expand Down Expand Up @@ -319,28 +319,32 @@ defmodule AniminaWeb.BetaRegistrationComponents do
~H"""
<div>
<label
for="form_minimum_partner_age"
for="form_minimum_partner_height"
class="block text-sm font-medium leading-6 text-gray-900 dark:text-white"
>
<%= with_locale(@language, fn -> %>
<%= gettext("Minimum age") %>
<%= gettext("Minimum %{height}", height: "height") %>
<% end) %>
</label>
<div phx-feedback-for={@f[:minimum_partner_age].name} class="mt-2">
<%= select(@f, :minimum_partner_age, Enum.map(18..110, &{&1, &1}),
prompt: with_locale(@language, fn -> gettext("doesn't matter") end),
value: @f[:minimum_partner_age].value,
<div phx-feedback-for={@f[:minimum_partner_height].name} class="mt-2">
<%= select(
@f,
:minimum_partner_height,
[{with_locale(@language, fn -> gettext("doesn't matter") end), nil}] ++
Enum.map(140..210, &{"#{&1} cm", &1}),
class:
"block w-full rounded-md border-0 py-1.5 text-gray-900 dark:bg-gray-700 dark:text-white shadow-sm ring-1 ring-inset focus:ring-2 focus:ring-inset phx-no-feedback:ring-gray-300 phx-no-feedback:focus:ring-indigo-600 sm:text-sm sm:leading-6 " <>
unless(get_field_errors(@f[:minimum_partner_age], :minimum_partner_age) == [],
"block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset focus:ring-2 dark:bg-gray-700 dark:text-white focus:ring-inset phx-no-feedback:ring-gray-300 phx-no-feedback:focus:ring-indigo-600 sm:text-sm sm:leading-6 " <>
unless(
get_field_errors(@f[:minimum_partner_height], :minimum_partner_height) == [],
do: "ring-red-600 focus:ring-red-600",
else: "ring-gray-300 focus:ring-indigo-600"
)
),
autofocus: true
) %>
<.error :for={msg <- get_field_errors(@f[:minimum_partner_age], :minimum_partner_age)}>
<.error :for={msg <- get_field_errors(@f[:minimum_partner_height], :minimum_partner_height)}>
<%= with_locale(@language, fn -> %>
<%= gettext("Minimum age") <> " " <> msg %>
<%= gettext("Minimum height") <> " " <> msg %>
<% end) %>
</.error>
</div>
Expand All @@ -356,7 +360,7 @@ defmodule AniminaWeb.BetaRegistrationComponents do
class="block text-sm font-medium leading-6 text-gray-900 dark:text-white"
>
<%= with_locale(@language, fn -> %>
<%= gettext("Maximum height") %>
<%= gettext("Maximum %{height}", height: "height") %>
<% end) %>
</label>
<div phx-feedback-for={@f[:maximum_partner_height].name} class="mt-2">
Expand Down Expand Up @@ -392,7 +396,7 @@ defmodule AniminaWeb.BetaRegistrationComponents do
class="block text-sm font-medium leading-6 text-gray-900 dark:text-white"
>
<%= with_locale(@language, fn -> %>
<%= gettext("Minimum age") %>
<%= gettext("Minimum %{age}", age: "age") %>
<% end) %>
</label>
<div phx-feedback-for={@f[:minimum_partner_age].name} class="mt-2">
Expand Down Expand Up @@ -425,7 +429,7 @@ defmodule AniminaWeb.BetaRegistrationComponents do
class="block text-sm font-medium leading-6 text-gray-900 dark:text-white"
>
<%= with_locale(@language, fn -> %>
<%= gettext("Maximum age") %>
<%= gettext("Maximum %{age}", age: "age") %>
<% end) %>
</label>
<div phx-feedback-for={@f[:maximum_partner_age].name} class="mt-2">
Expand Down
35 changes: 34 additions & 1 deletion lib/animina_web/live/beta_register.ex
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
defmodule AniminaWeb.BetaRegisterLive do
use AniminaWeb, :live_view
alias Animina.Accounts.User
alias AniminaWeb.PotentialPartner
alias AshPhoenix.Form

@impl true
def mount(_params, %{"language" => language} = _session, socket) do
potential_partners =
PotentialPartner.potential_partners_on_registration(default_user_params())

socket =
socket
|> assign(language: language)
|> assign(current_user: nil)
|> assign(active_tab: "register")
|> assign(trigger_action: false)
|> assign(current_user_credit_points: 0)
|> assign(:number_of_potential_partners, Enum.count(potential_partners))
|> assign(:errors, [])
|> assign(
:form,
Expand All @@ -21,11 +26,39 @@ defmodule AniminaWeb.BetaRegisterLive do
{:ok, socket}
end

@impl true
def handle_event("validate_and_filter_potential_partners", %{"user" => user}, socket) do
potential_partners = PotentialPartner.potential_partners_on_registration(user)

{:noreply,
socket
|> assign(:number_of_potential_partners, Enum.count(potential_partners))}
end

defp default_user_params do
%{
"height" => "",
"maximum_partner_height" => "",
"minimum_partner_height" => "",
"maximum_partner_age" => "",
"minimum_partner_age" => "",
"gender" => "male",
"search_range" => "",
"zip_code" => "",
"birthday" => ""
}
end

@impl true
def render(assigns) do
~H"""
<div>
<.initial_form language={@language} form={@form} errors={@errors} />
<.initial_form
number_of_potential_partners={@number_of_potential_partners}
language={@language}
form={@form}
errors={@errors}
/>
</div>
"""
end
Expand Down
Loading

0 comments on commit aab5b4f

Please sign in to comment.