From 83b1c0800f5b5d4c740b437cd2f5e57d5022e5c0 Mon Sep 17 00:00:00 2001 From: Maqbool Date: Mon, 21 Aug 2023 16:16:54 +0530 Subject: [PATCH 1/4] Upgrade to LiveView 0.18.0 --- config/config.exs | 7 +- config/test.exs | 2 +- lib/fitness/accounts.ex | 2 +- lib/fitness/accounts/services/chart_data.ex | 1 - .../accounts/services/player_scores.ex | 23 +++- lib/fitness/accounts/user.ex | 13 ++- lib/fitness/exercises.ex | 4 +- lib/fitness/exercises/finder/search_term.ex | 4 - lib/fitness/workout_templates.ex | 3 +- .../services/workout_item_logic.ex | 22 ++-- lib/fitness/workout_templates/workout_item.ex | 10 +- lib/fitness_web.ex | 5 +- .../controllers/user_session_controller.ex | 1 - .../live/exercise_live/form_component.ex | 4 +- .../exercise_live/form_component.html.heex | 4 +- lib/fitness_web/live/exercise_live/index.ex | 3 +- .../live/exercise_live/index.html.heex | 16 +-- .../live/exercise_live/show.html.heex | 13 ++- lib/fitness_web/live/live_helpers.ex | 10 +- .../live/profile_live/score_board_live.ex | 9 +- .../profile_live/update_user_profile_form.ex | 16 +-- .../live/profile_live/user_profile_live.ex | 5 +- lib/fitness_web/live/user_auth_live.ex | 6 +- .../check_boxes_live_component.ex | 23 ++-- .../workout_template_live/form_component.ex | 28 ++--- .../form_component.html.heex | 9 +- .../live/workout_template_live/index.ex | 1 - .../workout_template_live/index.html.heex | 24 ++-- .../live/workout_template_live/show.ex | 2 +- .../live/workout_template_live/show.html.heex | 22 ++-- .../workout_item_form.ex | 6 +- .../workout_template_live/workout_zone.ex | 33 +++--- lib/fitness_web/router.ex | 10 +- .../templates/layout/root.html.heex | 6 +- .../user_confirmation/edit.html.heex | 2 +- .../templates/user_confirmation/new.html.heex | 2 +- .../templates/user_registration/new.html.heex | 3 +- .../user_reset_password/edit.html.heex | 5 +- .../user_reset_password/new.html.heex | 6 +- .../templates/user_session/new.html.heex | 5 +- .../templates/user_settings/edit.html.heex | 35 +++--- mix.exs | 4 +- mix.lock | 24 ++-- .../20230417211058_create_workout_items.exs | 4 +- priv/repo/seeds.exs | 108 ++++++++++++++++-- test/fitness/accounts_test.exs | 16 ++- test/fitness/exercises_test.exs | 19 ++- test/fitness/workout_templates_test.exs | 4 +- .../user_reset_password_controller_test.exs | 2 +- test/fitness_web/live/exercise_live_test.exs | 12 +- .../live/workout_template_live_test.exs | 60 +++++++--- 51 files changed, 408 insertions(+), 250 deletions(-) diff --git a/config/config.exs b/config/config.exs index 7d9ed28..6142657 100644 --- a/config/config.exs +++ b/config/config.exs @@ -17,8 +17,9 @@ config :fitness, FitnessWeb.Endpoint, pubsub_server: Fitness.PubSub, live_view: [signing_salt: "vOF6D4CD"] - - config :tailwind, version: "3.3.1", default: [ +config :tailwind, + version: "3.3.1", + default: [ args: ~w( --config=tailwind.config.js --input=css/app.css @@ -27,7 +28,7 @@ config :fitness, FitnessWeb.Endpoint, cd: Path.expand("../assets", __DIR__) ] - config :chartkick, json_serializer: Jason +config :chartkick, json_serializer: Jason # Configures the mailer # diff --git a/config/test.exs b/config/test.exs index ed881aa..d00970b 100644 --- a/config/test.exs +++ b/config/test.exs @@ -27,7 +27,7 @@ config :fitness, FitnessWeb.Endpoint, config :fitness, Fitness.Mailer, adapter: Swoosh.Adapters.Test # Print only warnings and errors during test -config :logger, level: :warn +config :logger, level: :warning # Initialize plugs at runtime for faster test compilation config :phoenix, :plug_init_mode, :runtime diff --git a/lib/fitness/accounts.ex b/lib/fitness/accounts.ex index 769a869..07de7c1 100644 --- a/lib/fitness/accounts.ex +++ b/lib/fitness/accounts.ex @@ -8,7 +8,6 @@ defmodule Fitness.Accounts do alias Fitness.Accounts.{User, UserToken, UserNotifier} - def is_admin?(user) do user.is_admin end @@ -16,6 +15,7 @@ defmodule Fitness.Accounts do def list_of_users do Repo.all(User) end + ## Database getters @doc """ diff --git a/lib/fitness/accounts/services/chart_data.ex b/lib/fitness/accounts/services/chart_data.ex index 3a16c3b..7797d1f 100644 --- a/lib/fitness/accounts/services/chart_data.ex +++ b/lib/fitness/accounts/services/chart_data.ex @@ -1,5 +1,4 @@ defmodule Fitness.Accounts.Services.ChartData do - alias Fitness.WorkoutTemplates def all_complete_workout_chart_data(current_user_id) do diff --git a/lib/fitness/accounts/services/player_scores.ex b/lib/fitness/accounts/services/player_scores.ex index 8fb3510..76def8f 100644 --- a/lib/fitness/accounts/services/player_scores.ex +++ b/lib/fitness/accounts/services/player_scores.ex @@ -3,16 +3,19 @@ defmodule Fitness.Accounts.Services.PlayerScores do alias Fitness.WorkoutTemplates def update_new_player_score_and_broadcast_score_board(current_user, workout_templates) do - list_of_workout_template_is_finish_and_is_belong_to_user = - Enum.filter(workout_templates, fn each -> each.is_finished == true and each.user_id == current_user.id end) + Enum.filter(workout_templates, fn each -> + each.is_finished == true and each.user_id == current_user.id + end) total_workout_template_score = Enum.reduce(list_of_workout_template_is_finish_and_is_belong_to_user, 0, fn each, acc -> acc + each.workout_template_score end) - Accounts.update_user_player_score(current_user, %{"player_score" => "#{total_workout_template_score}"}) + Accounts.update_user_player_score(current_user, %{ + "player_score" => "#{total_workout_template_score}" + }) update_users = Accounts.list_of_users() update_workout_template = WorkoutTemplates.list_workout_templates() @@ -23,8 +26,16 @@ defmodule Fitness.Accounts.Services.PlayerScores do end) end - defp broadcast_score_board(updated_users, update_workout_template, updated_player_score, user_id) do - Phoenix.PubSub.broadcast(Fitness.PubSub, "score_board", - {:update_users, {updated_users, update_workout_template, updated_player_score, user_id}}) + defp broadcast_score_board( + updated_users, + update_workout_template, + updated_player_score, + user_id + ) do + Phoenix.PubSub.broadcast( + Fitness.PubSub, + "score_board", + {:update_users, {updated_users, update_workout_template, updated_player_score, user_id}} + ) end end diff --git a/lib/fitness/accounts/user.ex b/lib/fitness/accounts/user.ex index a6dee61..5670b22 100644 --- a/lib/fitness/accounts/user.ex +++ b/lib/fitness/accounts/user.ex @@ -55,7 +55,10 @@ defmodule Fitness.Accounts.User do defp validate_username(changeset) do changeset |> validate_required([:username]) - |> validate_format(:username, ~r/^[a-zA-Z0-9!#$_:+-?]+$/, message: "A username should consist of both letters and numbers, and should not contain any spaces") + |> validate_format(:username, ~r/^[a-zA-Z0-9!#$_:+-?]+$/, + message: + "A username should consist of both letters and numbers, and should not contain any spaces" + ) |> validate_length(:username, min: 5, max: 40) |> unsafe_validate_unique(:username, Fitness.Repo) |> unique_constraint(:username) @@ -64,7 +67,10 @@ defmodule Fitness.Accounts.User do defp validate_name(changeset) do changeset |> validate_required([:name]) - |> validate_format(:name, ~r/\A[a-zA-Z ]+\z/, message: "A name must be made up of only letters and should not include any symbols or numbers.") + |> validate_format(:name, ~r/\A[a-zA-Z ]+\z/, + message: + "A name must be made up of only letters and should not include any symbols or numbers." + ) |> validate_length(:name, max: 40) end @@ -109,7 +115,6 @@ defmodule Fitness.Accounts.User do end def name_changeset(user, attrs) do - user |> cast(attrs, [:name]) |> validate_name() @@ -126,11 +131,9 @@ defmodule Fitness.Accounts.User do %{changes: %{image: _}} = changeset -> changeset %{} = changeset -> add_error(changeset, :image, "did not change") end - end def player_score_changeset(user, attrs) do - user |> cast(attrs, [:player_score]) |> case do diff --git a/lib/fitness/exercises.ex b/lib/fitness/exercises.ex index ff3602a..46b0c27 100644 --- a/lib/fitness/exercises.ex +++ b/lib/fitness/exercises.ex @@ -19,8 +19,8 @@ defmodule Fitness.Exercises do """ def list_exercises(search_query) do - exercises = Repo.all(Exercise) - SearchTerm.filter_by_search_term(exercises, search_query) + exercises = Repo.all(Exercise) + SearchTerm.filter_by_search_term(exercises, search_query) end def list_exercises do diff --git a/lib/fitness/exercises/finder/search_term.ex b/lib/fitness/exercises/finder/search_term.ex index 7d3dc40..7d62dc3 100644 --- a/lib/fitness/exercises/finder/search_term.ex +++ b/lib/fitness/exercises/finder/search_term.ex @@ -1,8 +1,5 @@ defmodule Fitness.Exercises.Finder.SearchTerm do - def filter_by_search_term(exercises, search_query) do - - found_search_query = case search_query do "" -> @@ -31,5 +28,4 @@ defmodule Fitness.Exercises.Finder.SearchTerm do found_search_query end - end diff --git a/lib/fitness/workout_templates.ex b/lib/fitness/workout_templates.ex index 54277e7..4615ed6 100644 --- a/lib/fitness/workout_templates.ex +++ b/lib/fitness/workout_templates.ex @@ -38,14 +38,13 @@ defmodule Fitness.WorkoutTemplates do """ def get_workout_template!(id) do Repo.get!(WorkoutTemplate, id) - |> Repo.preload(workout_items: from(w in WorkoutItem, order_by: w.id)) + |> Repo.preload(:workout_items) end def get_workout_item!(id) do Repo.get!(WorkoutItem, id) end - @doc """ Creates a workout_template. diff --git a/lib/fitness/workout_templates/services/workout_item_logic.ex b/lib/fitness/workout_templates/services/workout_item_logic.ex index fb59e98..f1f9e03 100644 --- a/lib/fitness/workout_templates/services/workout_item_logic.ex +++ b/lib/fitness/workout_templates/services/workout_item_logic.ex @@ -1,10 +1,8 @@ defmodule Fitness.WorkoutTemplates.Services.WorkoutItemLogic do alias Fitness.WorkoutTemplates - # calculate single workout template score def update_workout_template_score(workout_template) do - list_of_complete_workout_items = Enum.filter(workout_template.workout_items, fn each -> each.check_box == true @@ -13,21 +11,21 @@ defmodule Fitness.WorkoutTemplates.Services.WorkoutItemLogic do if length(list_of_complete_workout_items) == length(workout_template.workout_items) do total_score = Enum.reduce(list_of_complete_workout_items, 0, fn _each, acc -> acc + 20 end) - WorkoutTemplates.update_workout_template(workout_template, %{ - "workout_template_score" => "#{total_score + 50}", - "is_finished" => "true" - }) + WorkoutTemplates.update_workout_template(workout_template, %{ + "workout_template_score" => "#{total_score + 50}", + "is_finished" => "true" + }) - true + true else total_score = Enum.reduce(list_of_complete_workout_items, 0, fn _each, acc -> acc + 20 end) - WorkoutTemplates.update_workout_template(workout_template, %{ - "workout_template_score" => "#{total_score}", - "is_finished" => "true" - }) + WorkoutTemplates.update_workout_template(workout_template, %{ + "workout_template_score" => "#{total_score}", + "is_finished" => "true" + }) - false + false end end diff --git a/lib/fitness/workout_templates/workout_item.ex b/lib/fitness/workout_templates/workout_item.ex index acfc15d..82d6118 100644 --- a/lib/fitness/workout_templates/workout_item.ex +++ b/lib/fitness/workout_templates/workout_item.ex @@ -17,7 +17,15 @@ defmodule Fitness.WorkoutTemplates.WorkoutItem do @doc false def changeset(workout, attrs) do workout - |> cast(attrs, [:sets, :weight, :weight_unit, :check_box, :reps, :exercise_id, :workout_template_id]) + |> cast(attrs, [ + :sets, + :weight, + :weight_unit, + :check_box, + :reps, + :exercise_id, + :workout_template_id + ]) |> validate_required([:sets, :weight, :weight_unit, :reps, :workout_template_id, :exercise_id]) end end diff --git a/lib/fitness_web.ex b/lib/fitness_web.ex index 2b5e20c..5a3176f 100644 --- a/lib/fitness_web.ex +++ b/lib/fitness_web.ex @@ -45,7 +45,7 @@ defmodule FitnessWeb do def live_view do quote do use Phoenix.LiveView, - layout: {FitnessWeb.LayoutView, "live.html"} + layout: {FitnessWeb.LayoutView, :live} unquote(view_helpers()) end @@ -90,7 +90,8 @@ defmodule FitnessWeb do use Phoenix.HTML # Import LiveView and .heex helpers (live_render, live_patch, <.form>, etc) - import Phoenix.LiveView.Helpers + + import Phoenix.Component import FitnessWeb.LiveHelpers # Import basic rendering functionality (render, render_layout, etc) diff --git a/lib/fitness_web/controllers/user_session_controller.ex b/lib/fitness_web/controllers/user_session_controller.ex index 6f6e159..7afae3b 100644 --- a/lib/fitness_web/controllers/user_session_controller.ex +++ b/lib/fitness_web/controllers/user_session_controller.ex @@ -12,7 +12,6 @@ defmodule FitnessWeb.UserSessionController do %{"email" => email, "password" => password} = user_params if user = Accounts.get_user_by_email_and_password(email, password) do - conn |> UserAuth.log_in_user(user, user_params) else diff --git a/lib/fitness_web/live/exercise_live/form_component.ex b/lib/fitness_web/live/exercise_live/form_component.ex index baa8355..de065f3 100644 --- a/lib/fitness_web/live/exercise_live/form_component.ex +++ b/lib/fitness_web/live/exercise_live/form_component.ex @@ -33,7 +33,7 @@ defmodule FitnessWeb.ExerciseLive.FormComponent do {:noreply, socket |> put_flash(:info, "Exercise updated successfully") - |> push_redirect(to: socket.assigns.return_to)} + |> push_navigate(to: socket.assigns.return_to)} {:error, %Ecto.Changeset{} = changeset} -> {:noreply, assign(socket, :changeset, changeset)} @@ -46,7 +46,7 @@ defmodule FitnessWeb.ExerciseLive.FormComponent do {:noreply, socket |> put_flash(:info, "Exercise created successfully") - |> push_redirect(to: socket.assigns.return_to)} + |> push_navigate(to: socket.assigns.return_to)} {:error, %Ecto.Changeset{} = changeset} -> {:noreply, assign(socket, changeset: changeset)} diff --git a/lib/fitness_web/live/exercise_live/form_component.html.heex b/lib/fitness_web/live/exercise_live/form_component.html.heex index beee999..86ee988 100644 --- a/lib/fitness_web/live/exercise_live/form_component.html.heex +++ b/lib/fitness_web/live/exercise_live/form_component.html.heex @@ -5,7 +5,7 @@

<%= @title %>

<.form - let={f} + :let={f} for={@changeset} id="exercise-form" phx-target={@myself} @@ -60,4 +60,4 @@ <%= submit "Create Exercise", class: "bg-green-400 hover:bg-green-600 text-white font-poppins py-2 px-4 rounded", phx_disable_with: "Saving..." %> - \ No newline at end of file + diff --git a/lib/fitness_web/live/exercise_live/index.ex b/lib/fitness_web/live/exercise_live/index.ex index d4b83d3..6b05be8 100644 --- a/lib/fitness_web/live/exercise_live/index.ex +++ b/lib/fitness_web/live/exercise_live/index.ex @@ -7,10 +7,9 @@ defmodule FitnessWeb.ExerciseLive.Index do @impl true def mount(_params, session, socket) do - if session["user_token"] do current_user = Accounts.get_user_by_session_token(session["user_token"]) - + case current_user do nil -> {:ok, assign(socket, exercises: Exercises.list_exercises(), search: "")} diff --git a/lib/fitness_web/live/exercise_live/index.html.heex b/lib/fitness_web/live/exercise_live/index.html.heex index 098aede..3036c18 100644 --- a/lib/fitness_web/live/exercise_live/index.html.heex +++ b/lib/fitness_web/live/exercise_live/index.html.heex @@ -10,7 +10,7 @@ exercise={@exercise} return_to={Routes.exercise_index_path(@socket, :index)} /> - + <% end %>
@@ -26,13 +26,13 @@ <%= if assigns[:user] do %>
- <%= live_patch "New Exercise", to: Routes.exercise_index_path(@socket, :new), class: "bg-blue-500 hover:bg-blue-700 text-white font-poppins py-2 px-4 rounded" %> + <.link patch={Routes.exercise_index_path(@socket, :new)} class="bg-blue-500 hover:bg-blue-700 text-white font-poppins py-2 px-4 rounded" >New Exercise
<% end %>
<%= for exercise <- @exercises do %> -
+
<%= link "#{exercise.level}", to: "#", phx_click: "search", phx_value_search: exercise.level %> @@ -45,9 +45,13 @@ <%= link "#{exercise.type}", to: "#", phx_click: "search", phx_value_search: exercise.type %>
- <%= live_redirect "Show", to: Routes.exercise_show_path(@socket, :show, exercise), class: "text-blue-500 font-poppins hover:underline" %> + + <.link navigate={Routes.exercise_show_path(@socket, :show, exercise)} class="text-blue-500 font-poppins hover:underline">Show + + + <%= if assigns[:is_admin] do %> - <%= live_patch "Edit", to: Routes.exercise_index_path(@socket, :edit, exercise), class: "text-blue-500 font-poppins hover:underline" %> + <.link patch={Routes.exercise_index_path(@socket, :edit, exercise)} class="text-blue-500 font-poppins hover:underline" >Edit <%= link "Delete", to: "#", phx_click: "delete", phx_value_id: exercise.id, data: [confirm: "Are you sure?"], class: "text-blue-500 font-poppins hover:underline" %> <% end %>
@@ -57,5 +61,3 @@
- - diff --git a/lib/fitness_web/live/exercise_live/show.html.heex b/lib/fitness_web/live/exercise_live/show.html.heex index 6f8bfcc..a84e0ed 100644 --- a/lib/fitness_web/live/exercise_live/show.html.heex +++ b/lib/fitness_web/live/exercise_live/show.html.heex @@ -13,15 +13,19 @@ <% end %>
-
+
<%= @exercise.level %> <%= if assigns[:is_admin] do %> - <%= live_patch "Edit", to: Routes.exercise_show_path(@socket, :edit, @exercise), class: "text-blue-500 font-poppins hover:underline" %> + <.link patch={Routes.exercise_show_path(@socket, :edit, @exercise)} class="text-blue-500 font-poppins hover:underline">Edit <% end %> - <%= live_redirect "Back to List", to: Routes.exercise_index_path(@socket, :index), class: "text-blue-500 font-poppins hover:underline" %> + + <.link navigate={Routes.exercise_index_path(@socket, :index)} class="text-blue-500 font-poppins hover:underline">Back to List + + +
@@ -35,8 +39,7 @@ <%= @exercise.type %>

<%= @exercise.description %>

- +
- diff --git a/lib/fitness_web/live/live_helpers.ex b/lib/fitness_web/live/live_helpers.ex index 746f8d8..010f698 100644 --- a/lib/fitness_web/live/live_helpers.ex +++ b/lib/fitness_web/live/live_helpers.ex @@ -1,6 +1,5 @@ defmodule FitnessWeb.LiveHelpers do - import Phoenix.LiveView - import Phoenix.LiveView.Helpers + import Phoenix.Component alias Phoenix.LiveView.JS @@ -36,12 +35,7 @@ defmodule FitnessWeb.LiveHelpers do phx-key="escape" > <%= if @return_to do %> - <%= live_patch "X", - to: @return_to, - id: "close", - class: "phx-modal-close", - phx_click: hide_modal() - %> + <.link id="close" patch={@return_to} class="phx-modal-close" phx_click={hide_modal()}>X <% else %> x <% end %> diff --git a/lib/fitness_web/live/profile_live/score_board_live.ex b/lib/fitness_web/live/profile_live/score_board_live.ex index 09d8516..2ab38dc 100644 --- a/lib/fitness_web/live/profile_live/score_board_live.ex +++ b/lib/fitness_web/live/profile_live/score_board_live.ex @@ -16,7 +16,6 @@ defmodule FitnessWeb.ScoreBoardLive do |> assign(:user_id, 0) |> assign(:workout_templates, WorkoutTemplates.list_workout_templates()) - {:ok, socket} end @@ -75,8 +74,11 @@ defmodule FitnessWeb.ScoreBoardLive do end @impl true - def handle_info({:update_users, {updated_users, update_workout_template, updated_player_score, updated_user_id}}, socket) do - + def handle_info( + {:update_users, + {updated_users, update_workout_template, updated_player_score, updated_user_id}}, + socket + ) do socket = socket |> assign(player_score: updated_player_score) @@ -84,7 +86,6 @@ defmodule FitnessWeb.ScoreBoardLive do |> assign(users: updated_users) |> assign(user_id: updated_user_id) - {:noreply, socket} end end diff --git a/lib/fitness_web/live/profile_live/update_user_profile_form.ex b/lib/fitness_web/live/profile_live/update_user_profile_form.ex index 5248215..2d1f9a7 100644 --- a/lib/fitness_web/live/profile_live/update_user_profile_form.ex +++ b/lib/fitness_web/live/profile_live/update_user_profile_form.ex @@ -19,7 +19,7 @@ defmodule FitnessWeb.ProfileLive.UpdateUserProfileForm do

Edit Profile

<.form - let={f} + :let={f} for={:profile} phx-target={@myself} id="update_profile" @@ -62,7 +62,10 @@ defmodule FitnessWeb.ProfileLive.UpdateUserProfileForm do @impl true def handle_event("remove", _params, socket) do - Accounts.update_user_image(socket.assigns.current_user, %{"image" => "/images/user-profile.svg"}) + Accounts.update_user_image(socket.assigns.current_user, %{ + "image" => "/images/user-profile.svg" + }) + {:noreply, socket} end @@ -77,15 +80,14 @@ defmodule FitnessWeb.ProfileLive.UpdateUserProfileForm do end) |> List.to_string() - - if uploaded_file != "" do - Accounts.update_user_image(socket.assigns.current_user, %{"image" => uploaded_file}) - end + if uploaded_file != "" do + Accounts.update_user_image(socket.assigns.current_user, %{"image" => uploaded_file}) + end Accounts.update_user_name(socket.assigns.current_user, %{"name" => updated_name}) {:noreply, socket - |> push_redirect(to: "/profile")} + |> push_navigate(to: "/profile")} end end diff --git a/lib/fitness_web/live/profile_live/user_profile_live.ex b/lib/fitness_web/live/profile_live/user_profile_live.ex index 708b3ab..f60e802 100644 --- a/lib/fitness_web/live/profile_live/user_profile_live.ex +++ b/lib/fitness_web/live/profile_live/user_profile_live.ex @@ -9,7 +9,10 @@ defmodule FitnessWeb.UserProfileLive do socket |> assign(:page_title, "User Profile") |> assign(:kebab_menu, :off) - |> assign(:chart_data, ChartData.all_complete_workout_chart_data(socket.assigns[:current_user].id)) + |> assign( + :chart_data, + ChartData.all_complete_workout_chart_data(socket.assigns[:current_user].id) + ) {:ok, socket} end diff --git a/lib/fitness_web/live/user_auth_live.ex b/lib/fitness_web/live/user_auth_live.ex index 9844bc9..a40a65a 100644 --- a/lib/fitness_web/live/user_auth_live.ex +++ b/lib/fitness_web/live/user_auth_live.ex @@ -1,14 +1,12 @@ defmodule FitnessWeb.UserAuthLive do - import Phoenix.LiveView + import Phoenix.Component alias Fitness.Accounts def on_mount(:user, _params, %{"user_token" => user_token} = _session, socket) do - socket = socket |> assign(:current_user, Accounts.get_user_by_session_token(user_token)) - - {:cont, socket} + {:cont, socket} end end diff --git a/lib/fitness_web/live/workout_template_live/check_boxes_live_component.ex b/lib/fitness_web/live/workout_template_live/check_boxes_live_component.ex index 3f8fc28..6c801a1 100644 --- a/lib/fitness_web/live/workout_template_live/check_boxes_live_component.ex +++ b/lib/fitness_web/live/workout_template_live/check_boxes_live_component.ex @@ -1,23 +1,19 @@ defmodule FitnessWeb.WorkoutTemplateLive.CheckBoxesLiveComponent do use FitnessWeb, :live_component - alias Fitness.WorkoutTemplates - alias Fitness.WorkoutTemplates.WorkoutItem - alias Fitness.Exercises - @impl true def update(assigns, socket) do - {:ok, - socket - |> assign(:workout_template, assigns.workout_template) - |> assign(:changeset, assigns.changeset) - |> assign(:update_param, %{}) - |> assign(:time, ~T[00:00:00]) - |> assign(:timer_status, assigns.timer_status) - |> assign(:workout_start, assigns.workout_start)} + socket + |> assign(:workout_template, assigns.workout_template) + |> assign(:changeset, assigns.changeset) + |> assign(:update_param, %{}) + |> assign(:time, ~T[00:00:00]) + |> assign(:timer_status, assigns.timer_status) + |> assign(:workout_start, assigns.workout_start)} end + @impl true def render(assigns) do ~H"""
@@ -50,7 +46,7 @@ defmodule FitnessWeb.WorkoutTemplateLive.CheckBoxesLiveComponent do <%= for workout_item <- each_list do%> <.form - let={f} + :let={f} for={@changeset} id={"created-workout-item-#{workout_item.id}"} > @@ -94,5 +90,4 @@ defmodule FitnessWeb.WorkoutTemplateLive.CheckBoxesLiveComponent do """ end - end diff --git a/lib/fitness_web/live/workout_template_live/form_component.ex b/lib/fitness_web/live/workout_template_live/form_component.ex index e6e9680..ab5afe8 100644 --- a/lib/fitness_web/live/workout_template_live/form_component.ex +++ b/lib/fitness_web/live/workout_template_live/form_component.ex @@ -2,7 +2,6 @@ defmodule FitnessWeb.WorkoutTemplateLive.FormComponent do use FitnessWeb, :live_component alias Fitness.WorkoutTemplates - alias FitnessWeb.WorkoutTemplateLive.WorkoutItemForm @impl true def update(%{workout_template: workout_template} = assigns, socket) do @@ -15,7 +14,7 @@ defmodule FitnessWeb.WorkoutTemplateLive.FormComponent do end @impl true - def handle_event("validate", %{"workout_template" => workout_template_params} , socket) do + def handle_event("validate", %{"workout_template" => workout_template_params}, socket) do changeset = socket.assigns.workout_template |> WorkoutTemplates.change_workout_template(workout_template_params) @@ -25,34 +24,37 @@ defmodule FitnessWeb.WorkoutTemplateLive.FormComponent do end def handle_event("save", %{"workout_template" => workout_template_params}, socket) do - save_workout_template(socket, socket.assigns.action, workout_template_params) end - defp save_workout_template(socket, :edit, workout_template_params) do - case WorkoutTemplates.update_workout_template(socket.assigns.workout_template, workout_template_params) do + case WorkoutTemplates.update_workout_template( + socket.assigns.workout_template, + workout_template_params + ) do {:ok, workout_template} -> {:noreply, socket |> put_flash(:info, "Workout template updated successfully") - |> push_redirect(to: "/workout_templates/#{workout_template.id}")} + |> push_navigate(to: "/workout_templates/#{workout_template.id}")} - {:error, %Ecto.Changeset{} = changeset} -> + {:error, %Ecto.Changeset{} = changeset} -> {:noreply, assign(socket, :changeset, changeset)} - end end + end defp save_workout_template(socket, :new, workout_template_params) do - case WorkoutTemplates.create_workout_template(Map.put(workout_template_params,"user_id", socket.assigns.user_id)) do + case WorkoutTemplates.create_workout_template( + Map.put(workout_template_params, "user_id", socket.assigns.user_id) + ) do {:ok, workout_template} -> {:noreply, - socket - |> put_flash(:info, "Workout template created successfully") - |> push_redirect(to: "/workout_templates/#{workout_template.id}")} + socket + |> put_flash(:info, "Workout template created successfully") + |> push_navigate(to: "/workout_templates/#{workout_template.id}")} {:error, %Ecto.Changeset{} = changeset} -> - {:noreply, assign(socket, changeset: changeset)} + {:noreply, assign(socket, changeset: changeset)} end end end diff --git a/lib/fitness_web/live/workout_template_live/form_component.html.heex b/lib/fitness_web/live/workout_template_live/form_component.html.heex index 8747378..982c045 100644 --- a/lib/fitness_web/live/workout_template_live/form_component.html.heex +++ b/lib/fitness_web/live/workout_template_live/form_component.html.heex @@ -1,14 +1,14 @@

<%= @title %>

- + <.form - let={f} + :let={f} for={@changeset} id="workout_template-form" phx-target={@myself} phx-change="validate" phx-submit="save"> - +
<%= submit "Save", class: "bg-blue-500 hover:bg-blue-700 font-poppins text-white py-2 px-4 rounded focus:outline-none focus:shadow-outline", phx_disable_with: "Saving..." %>
@@ -17,6 +17,5 @@ <%= text_input f, :name, class: "w-full font-poppins border rounded py-2 px-3 leading-tight focus:outline-none focus:shadow-outline", placeholder: "Enter workout name" %> <%= error_tag f, :name %>
- +
- \ No newline at end of file diff --git a/lib/fitness_web/live/workout_template_live/index.ex b/lib/fitness_web/live/workout_template_live/index.ex index c402c50..266a50e 100644 --- a/lib/fitness_web/live/workout_template_live/index.ex +++ b/lib/fitness_web/live/workout_template_live/index.ex @@ -3,7 +3,6 @@ defmodule FitnessWeb.WorkoutTemplateLive.Index do alias Fitness.WorkoutTemplates alias Fitness.WorkoutTemplates.WorkoutTemplate - alias Fitness.Accounts @impl true def mount(_params, _session, socket) do diff --git a/lib/fitness_web/live/workout_template_live/index.html.heex b/lib/fitness_web/live/workout_template_live/index.html.heex index 49861e0..66bc552 100644 --- a/lib/fitness_web/live/workout_template_live/index.html.heex +++ b/lib/fitness_web/live/workout_template_live/index.html.heex @@ -1,6 +1,6 @@

Listing Workout templates

- + <%= if @live_action in [:new, :edit] do %> <.modal return_to={Routes.workout_template_index_path(@socket, :index)}> <.live_component @@ -15,19 +15,19 @@ <% end %> - +
- <%= live_patch "New Workout", to: Routes.workout_template_index_path(@socket, :new), class: "bg-blue-500 font-poppins hover:bg-blue-600 text-white rounded-lg px-3 py-2" %> -
- + <.link patch={Routes.workout_template_index_path(@socket, :new)} class="bg-blue-500 font-poppins hover:bg-blue-600 text-white rounded-lg px-3 py-2" >New Workout +
+ <%= if length(@workout_templates) >= 1 do %> <% user_template_owner = Enum.filter(@workout_templates, fn each -> each.user_id == assigns[:current_user].id end) %> - +
<% workout_templates_list_is_finished_false = Enum.reject(user_template_owner, fn each -> each.is_finished == true end) %> <%= for workout_template <- Enum.reverse(workout_templates_list_is_finished_false) do %>
- + @@ -45,14 +45,14 @@ <% end %>
- - <%= live_redirect "Show", to: Routes.workout_template_show_path(@socket, :show, workout_template), class: "bg-blue-500 hover:bg-blue-600 text-white rounded-lg font-poppins px-4 py-2 mr-2 " %> + + <.link navigate={Routes.workout_template_show_path(@socket, :show, workout_template)} class="bg-blue-500 hover:bg-blue-600 text-white rounded-lg font-poppins px-4 py-2 mr-2 ">Show <%= if assigns[:current_user] do %> - <%= live_patch "Edit", to: Routes.workout_template_index_path(@socket, :edit, workout_template), class: "text-orange-400 font-poppins text-xl hover:underline" %> + <.link patch={Routes.workout_template_index_path(@socket, :edit, workout_template)} class="text-orange-400 font-poppins text-xl hover:underline">Edit <% end %>
<% end %> -
+
<% end %> - \ No newline at end of file + diff --git a/lib/fitness_web/live/workout_template_live/show.ex b/lib/fitness_web/live/workout_template_live/show.ex index 25bd1e3..43db1dc 100644 --- a/lib/fitness_web/live/workout_template_live/show.ex +++ b/lib/fitness_web/live/workout_template_live/show.ex @@ -2,7 +2,7 @@ defmodule FitnessWeb.WorkoutTemplateLive.Show do use FitnessWeb, :live_view alias Fitness.WorkoutTemplates - alias Fitness.Accounts + alias Fitness.WorkoutTemplates.WorkoutItem alias Fitness.Exercises alias Fitness.WorkoutTemplates.ComplexQuery diff --git a/lib/fitness_web/live/workout_template_live/show.html.heex b/lib/fitness_web/live/workout_template_live/show.html.heex index 563e3a0..fe2c6c6 100644 --- a/lib/fitness_web/live/workout_template_live/show.html.heex +++ b/lib/fitness_web/live/workout_template_live/show.html.heex @@ -1,7 +1,7 @@

<%= String.upcase(@workout_template.name) %>

- +
<%= if length(@workout_template.workout_items) >= 6 do %> @@ -12,14 +12,14 @@ <% else %> - + <% end %> - +
<%= if @workout_template.workout_items == [] do %>
<%= if assigns[:current_user] do %> - + <% end %>
<% end %> @@ -36,14 +36,14 @@ /> <% end %> - + <%= if @workout_template.workout_items != [] do %> - +
<% list_of_same_exercise = Enum.group_by(@workout_template.workout_items, fn each -> each.exercise_id end) |> Map.values() %> - + <%= for each_list <- list_of_same_exercise do %> <% [workout_item_map | _] = each_list %>
@@ -64,7 +64,7 @@ <% last_workout_item = Enum.at(each_list, -1) %> <%= for workout_item <- each_list do%> <.form - let={f} + :let={f} for={@changeset} id={"created-workout-item-#{workout_item.id}"} phx-change="workout-update"> @@ -108,12 +108,12 @@ <% end %>
<% end %> - + <%= if @workout_template.workout_items != [] do %>
<%= if assigns[:current_user] do %> - + <% end %>
<% end %> -
\ No newline at end of file +
diff --git a/lib/fitness_web/live/workout_template_live/workout_item_form.ex b/lib/fitness_web/live/workout_template_live/workout_item_form.ex index b48d9b4..b24ddd4 100644 --- a/lib/fitness_web/live/workout_template_live/workout_item_form.ex +++ b/lib/fitness_web/live/workout_template_live/workout_item_form.ex @@ -33,7 +33,7 @@ defmodule FitnessWeb.WorkoutTemplateLive.WorkoutItemForm do

Add New Exercises

<.form - let={f} + :let={f} for={@changeset} id="new-workout-item" phx-target={@myself} @@ -87,7 +87,7 @@ defmodule FitnessWeb.WorkoutTemplateLive.WorkoutItemForm do [current | _tail] = WorkoutItemLogic.updated_workout_items_list(current_exercise_id, workout_items_list) - + {:noreply, assign(socket, sets_number: current.sets_number, @@ -108,7 +108,7 @@ defmodule FitnessWeb.WorkoutTemplateLive.WorkoutItemForm do {:ok, workout_item} -> socket = socket - |> push_redirect(to: "/workout_templates/#{workout_item.workout_template_id}") + |> push_navigate(to: "/workout_templates/#{workout_item.workout_template_id}") {:noreply, socket} diff --git a/lib/fitness_web/live/workout_template_live/workout_zone.ex b/lib/fitness_web/live/workout_template_live/workout_zone.ex index 6cc8803..7301378 100644 --- a/lib/fitness_web/live/workout_template_live/workout_zone.ex +++ b/lib/fitness_web/live/workout_template_live/workout_zone.ex @@ -3,14 +3,14 @@ defmodule FitnessWeb.WorkoutTemplateLive.WorkoutZone do alias Fitness.WorkoutTemplates alias Fitness.WorkoutTemplates.WorkoutItem - alias Fitness.Exercises + alias FitnessWeb.WorkoutTemplateLive.CheckBoxesLiveComponent - alias Fitness.Accounts + alias Fitness.WorkoutTemplates.Services.WorkoutItemLogic alias Fitness.Accounts.Services.PlayerScores @impl true - def mount(params, session, socket) do + def mount(params, _session, socket) do changeset = WorkoutTemplates.change_workout_item(%WorkoutItem{}) workout_template = WorkoutTemplates.get_workout_template!(params["id"]) @@ -27,6 +27,7 @@ defmodule FitnessWeb.WorkoutTemplateLive.WorkoutZone do |> assign(:check_complete_checkbox_list, check_complete_checkbox_list)} end + @impl true def render(assigns) do ~H""" @@ -67,7 +68,7 @@ defmodule FitnessWeb.WorkoutTemplateLive.WorkoutZone do
- <%= live_redirect "Edit", to: Routes.workout_template_show_path(@socket, :show, @workout_template) %> + <.link navigate={Routes.workout_template_show_path(@socket, :show, @workout_template)}>Edit
<% else %>
@@ -75,7 +76,7 @@ defmodule FitnessWeb.WorkoutTemplateLive.WorkoutZone do The timer is lost by you
<% end %> @@ -103,8 +104,6 @@ defmodule FitnessWeb.WorkoutTemplateLive.WorkoutZone do @impl true def handle_params(%{"id" => id}, _, socket) do - changeset = WorkoutTemplates.change_workout_item(%WorkoutItem{}) - {:noreply, socket |> assign(:workout_template, WorkoutTemplates.get_workout_template!(id))} @@ -113,7 +112,11 @@ defmodule FitnessWeb.WorkoutTemplateLive.WorkoutZone do # update my checkboxes @impl true - def handle_event("workout_complete", %{"id" => id, "value" => check_box_value} = params, socket) do + def handle_event( + "workout_complete", + %{"id" => id, "value" => check_box_value} = _params, + socket + ) do id = String.to_integer(id) check_box_value = String.to_atom(check_box_value) @@ -123,7 +126,7 @@ defmodule FitnessWeb.WorkoutTemplateLive.WorkoutZone do end @impl true - def handle_event("workout_complete", %{"id" => id} = params, socket) do + def handle_event("workout_complete", %{"id" => id} = _params, socket) do id = String.to_integer(id) check_box_value = false @@ -142,29 +145,31 @@ defmodule FitnessWeb.WorkoutTemplateLive.WorkoutZone do current_user = socket.assigns.current_user WorkoutItemLogic.duplicate_workout_template(workout_template) - PlayerScores.update_new_player_score_and_broadcast_score_board(current_user, workout_templates) + + PlayerScores.update_new_player_score_and_broadcast_score_board( + current_user, + workout_templates + ) redirect_value = WorkoutItemLogic.update_workout_template_score(workout_template) socket = case redirect_value do true -> - socket |> put_flash( :bonus, "Well done #{String.upcase(current_user.name)} for finishing your workout! ๐Ÿฅณ You earned โœจ50โœจ bonus ๐ŸŽ‰ points for completing all of your sets. Keep up the great work! ๐Ÿ‘" ) - |> push_redirect(to: "/activity_history") + |> push_navigate(to: "/activity_history") false -> - socket |> put_flash( :loss, "Congratulations #{String.upcase(current_user.name)} for completing your workout! However, ๐Ÿ˜ž you lost 50 bonus points because you missed some sets. Try your best next time ๐Ÿ‘" ) - |> push_redirect(to: "/activity_history") + |> push_navigate(to: "/activity_history") end {:noreply, assign(socket, :timer_status, :stopped)} diff --git a/lib/fitness_web/router.ex b/lib/fitness_web/router.ex index ee1a2a8..1cd9fe6 100644 --- a/lib/fitness_web/router.ex +++ b/lib/fitness_web/router.ex @@ -23,7 +23,6 @@ defmodule FitnessWeb.Router do pipe_through [:browser, :require_authenticated_user] live_session :user, on_mount: {UserAuthLive, :user} do - live "/exercises/new", ExerciseLive.Index, :new live "/exercises/:id/edit", ExerciseLive.Index, :edit live "/exercises/:id/show/edit", ExerciseLive.Show, :edit @@ -36,9 +35,12 @@ defmodule FitnessWeb.Router do live "/workout_templates/new", WorkoutTemplateLive.Index, :new live "/workout_templates/:id", WorkoutTemplateLive.Show, :show live "/workout_templates/:id/edit", WorkoutTemplateLive.Index, :edit - live "/workout_templates/:id/show/workout_zone", WorkoutTemplateLive.WorkoutZone, :workout_zone - live "/workout_templates/:id/show/edit", WorkoutTemplateLive.Show, :edit + live "/workout_templates/:id/show/workout_zone", + WorkoutTemplateLive.WorkoutZone, + :workout_zone + + live "/workout_templates/:id/show/edit", WorkoutTemplateLive.Show, :edit end end @@ -53,8 +55,6 @@ defmodule FitnessWeb.Router do live "/exercises/:id", ExerciseLive.Show, :show end - - # Other scopes may use custom stacks. # scope "/api", FitnessWeb do # pipe_through :api diff --git a/lib/fitness_web/templates/layout/root.html.heex b/lib/fitness_web/templates/layout/root.html.heex index 3499f9b..9015334 100644 --- a/lib/fitness_web/templates/layout/root.html.heex +++ b/lib/fitness_web/templates/layout/root.html.heex @@ -5,7 +5,9 @@ - <%= live_title_tag assigns[:page_title] || "Fitness", suffix: " ยท Phoenix Framework" %> + <.live_title > + <%= assigns[:page_title] || "Fitness" %> + @@ -20,7 +22,7 @@ <% else %> <% end %> - +
PROFILE ACTIVITY HISTORY diff --git a/lib/fitness_web/templates/user_confirmation/edit.html.heex b/lib/fitness_web/templates/user_confirmation/edit.html.heex index e9bf443..593d10c 100644 --- a/lib/fitness_web/templates/user_confirmation/edit.html.heex +++ b/lib/fitness_web/templates/user_confirmation/edit.html.heex @@ -1,6 +1,6 @@

Confirm account

-<.form let={_f} for={:user} action={Routes.user_confirmation_path(@conn, :update, @token)}> +<.form :let={_f} for={%{}} as={:user} action={Routes.user_confirmation_path(@conn, :update, @token)}>
<%= submit "Confirm my account" %>
diff --git a/lib/fitness_web/templates/user_confirmation/new.html.heex b/lib/fitness_web/templates/user_confirmation/new.html.heex index 4d9bee3..e9582cb 100644 --- a/lib/fitness_web/templates/user_confirmation/new.html.heex +++ b/lib/fitness_web/templates/user_confirmation/new.html.heex @@ -1,6 +1,6 @@

Resend confirmation instructions

-<.form let={f} for={:user} action={Routes.user_confirmation_path(@conn, :create)}> +<.form :let={f} for={%{}} as={:user} action={Routes.user_confirmation_path(@conn, :create)}> <%= label f, :email %> <%= email_input f, :email, required: true %> diff --git a/lib/fitness_web/templates/user_registration/new.html.heex b/lib/fitness_web/templates/user_registration/new.html.heex index af4fb3c..4ff0c63 100644 --- a/lib/fitness_web/templates/user_registration/new.html.heex +++ b/lib/fitness_web/templates/user_registration/new.html.heex @@ -3,7 +3,7 @@

Register

-<.form let={f} for={@changeset} action={Routes.user_registration_path(@conn, :create)} class="max-w-md mx-auto"> +<.form :let={f} for={@changeset} action={Routes.user_registration_path(@conn, :create)} class="max-w-md mx-auto"> <%= if @changeset.action do %>

Oops, something went wrong! Please check the errors below.

@@ -47,4 +47,3 @@
- diff --git a/lib/fitness_web/templates/user_reset_password/edit.html.heex b/lib/fitness_web/templates/user_reset_password/edit.html.heex index 5dc70fe..f1c0751 100644 --- a/lib/fitness_web/templates/user_reset_password/edit.html.heex +++ b/lib/fitness_web/templates/user_reset_password/edit.html.heex @@ -1,7 +1,7 @@

Reset password

- <.form class="bg-white font-poppins shadow-md rounded px-8 pt-6 pb-8 mb-4" let={f} for={@changeset} action={Routes.user_reset_password_path(@conn, :update, @token)}> + <.form class="bg-white font-poppins shadow-md rounded px-8 pt-6 pb-8 mb-4" :let={f} for={@changeset} action={Routes.user_reset_password_path(@conn, :update, @token)}> <%= if @changeset.action do %>

Oops, something went wrong! Please check the errors below.

@@ -27,7 +27,7 @@

- Don't have an account? <%= link "Sign up", to: Routes.user_registration_path(@conn, :new), class: "font-medium font-poppins text-blue-500 hover:text-blue-600" %> + Don't have an account? <%= link "Sign up", to: Routes.user_registration_path(@conn, :new), class: "font-medium font-poppins text-blue-500 hover:text-blue-600" %>

@@ -35,4 +35,3 @@ Forgot your password? <%= link "Reset it", to: Routes.user_reset_password_path(@conn, :new), class: "font-medium font-poppins text-blue-500 hover:text-blue-600" %>

- diff --git a/lib/fitness_web/templates/user_reset_password/new.html.heex b/lib/fitness_web/templates/user_reset_password/new.html.heex index cc8882b..93735f0 100644 --- a/lib/fitness_web/templates/user_reset_password/new.html.heex +++ b/lib/fitness_web/templates/user_reset_password/new.html.heex @@ -2,7 +2,7 @@

Forgot your password?

- <.form let={f} for={:user} action={Routes.user_reset_password_path(@conn, :create)} class="bg-white font-poppins rounded px-8 pt-6 pb-8 mb-4"> + <.form :let={f} for={%{}} as={:user} action={Routes.user_reset_password_path(@conn, :create)} class="bg-white font-poppins rounded px-8 pt-6 pb-8 mb-4">
<%= label f, :email, class: "font-semibold font-poppins" %> <%= email_input f, :email, required: true, class: "shadow font-poppins appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" %> @@ -19,10 +19,8 @@

- Don't have an account? <%= link "Sign up", to: Routes.user_registration_path(@conn, :new), class: "font-medium font-poppins font-poppins text-blue-500 hover:text-blue-600" %> + Don't have an account? <%= link "Sign up", to: Routes.user_registration_path(@conn, :new), class: "font-medium font-poppins font-poppins text-blue-500 hover:text-blue-600" %>

- - diff --git a/lib/fitness_web/templates/user_session/new.html.heex b/lib/fitness_web/templates/user_session/new.html.heex index 5948b6d..5c8b671 100644 --- a/lib/fitness_web/templates/user_session/new.html.heex +++ b/lib/fitness_web/templates/user_session/new.html.heex @@ -2,7 +2,7 @@

Log in

- <.form let={f} for={@conn} action={Routes.user_session_path(@conn, :create)} as={:user} class="space-y-4"> + <.form :let={f} for={@conn} action={Routes.user_session_path(@conn, :create)} as={:user} class="space-y-4"> <%= if @error_message do %>

<%= @error_message %>

@@ -26,7 +26,7 @@

- Don't have an account? <%= link "Sign up", to: Routes.user_registration_path(@conn, :new), class: "font-medium font-poppins text-blue-500 hover:text-blue-600" %> + Don't have an account? <%= link "Sign up", to: Routes.user_registration_path(@conn, :new), class: "font-medium font-poppins text-blue-500 hover:text-blue-600" %>

@@ -35,4 +35,3 @@

- diff --git a/lib/fitness_web/templates/user_settings/edit.html.heex b/lib/fitness_web/templates/user_settings/edit.html.heex index b2386a4..359fa35 100644 --- a/lib/fitness_web/templates/user_settings/edit.html.heex +++ b/lib/fitness_web/templates/user_settings/edit.html.heex @@ -1,73 +1,72 @@ - -
- + +
+

# Change email

- - <.form let={f} for={@email_changeset} action={Routes.user_settings_path(@conn, :update)} id="update_email"> + + <.form :let={f} for={@email_changeset} action={Routes.user_settings_path(@conn, :update)} id="update_email"> <%= if @email_changeset.action do %>

Oops, something went wrong! Please check the errors below.

<% end %> - + <%= hidden_input f, :action, name: "action", value: "update_email" %>
<%= label f, :email, class: "text-sm font-poppins font-medium" %> <%= email_input f, :email, required: true, class: "form-input rounded-md font-poppins shadow-sm block w-full" %> <%= error_tag f, :email %>
- +
<%= label f, :current_password, for: "current_password_for_email", class: "text-sm font-poppins font-medium" %> <%= password_input f, :current_password, required: true, name: "current_password", placeholder: "********", id: "current_password_for_email", class: "form-input font-poppins rounded-md shadow-sm block w-full" %> <%= error_tag f, :current_password %>
- +
<%= submit "Change email", class: "w-full font-poppins px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-gradient-to-r from-purple-400 to-pink-600 hover:from-purple-500 hover:to-pink-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" %>
- +
- +

# Change password

- - <.form let={f} for={@password_changeset} action={Routes.user_settings_path(@conn, :update)} id="update_password"> + + <.form :let={f} for={@password_changeset} action={Routes.user_settings_path(@conn, :update)} id="update_password"> <%= if @password_changeset.action do %>

Oops, something went wrong! Please check the errors below.

<% end %> - + <%= hidden_input f, :action, name: "action", value: "update_password" %> -
+
<%= label f, :password, "New password", class: "text-sm font-poppins font-medium" %> <%= password_input f, :password, required: true, placeholder: "********", class: "form-input font-poppins rounded-md shadow-sm block w-full" %> <%= error_tag f, :password %>
- <%= label f, :password_confirmation, "Confirm new password", class: "text-sm font-poppins font-medium" %> + <%= label f, :password_confirmation, "Confirm new password", class: "text-sm font-poppins font-medium" %> <%= password_input f, :password_confirmation, required: true, placeholder: "********", class: "form-input font-poppins rounded-md shadow-sm block w-full" %> <%= error_tag f, :password_confirmation %>
- +
<%= label f, :current_password, for: "current_password_for_password", class: "text-sm font-poppins font-medium" %> <%= password_input f, :current_password, required: true, placeholder: "********", class: "form-input font-poppins font-poppins rounded-md shadow-sm block w-full", name: "current_password", id: "current_password_for_password" %> <%= error_tag f, :current_password %>
- +
<%= submit "Change password", class: "w-full font-poppins px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-gradient-to-r from-purple-400 to-pink-600 hover:from-purple-500 hover:to-pink-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" %>
- \ No newline at end of file diff --git a/mix.exs b/mix.exs index 4113d88..c079ce7 100644 --- a/mix.exs +++ b/mix.exs @@ -40,9 +40,9 @@ defmodule Fitness.MixProject do {:postgrex, ">= 0.0.0"}, {:phoenix_html, "~> 3.0"}, {:phoenix_live_reload, "~> 1.2", only: :dev}, - {:phoenix_live_view, "~> 0.17.5"}, + {:phoenix_live_view, "~> 0.18.18"}, {:floki, ">= 0.30.0", only: :test}, - {:phoenix_live_dashboard, "~> 0.6"}, + {:phoenix_live_dashboard, "~> 0.7"}, {:esbuild, "~> 0.4", runtime: Mix.env() == :dev}, {:swoosh, "~> 1.3"}, {:telemetry_metrics, "~> 0.6"}, diff --git a/mix.lock b/mix.lock index 2ced981..6d7e00e 100644 --- a/mix.lock +++ b/mix.lock @@ -1,17 +1,17 @@ %{ "bcrypt_elixir": {:hex, :bcrypt_elixir, "3.0.1", "9be815469e6bfefec40fa74658ecbbe6897acfb57614df1416eeccd4903f602c", [:make, :mix], [{:comeonin, "~> 5.3", [hex: :comeonin, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "486bb95efb645d1efc6794c1ddd776a186a9a713abf06f45708a6ce324fb96cf"}, - "castore": {:hex, :castore, "1.0.1", "240b9edb4e9e94f8f56ab39d8d2d0a57f49e46c56aced8f873892df8ff64ff5a", [:mix], [], "hexpm", "b4951de93c224d44fac71614beabd88b71932d0b1dea80d2f80fb9044e01bbb3"}, + "castore": {:hex, :castore, "1.0.3", "7130ba6d24c8424014194676d608cb989f62ef8039efd50ff4b3f33286d06db8", [:mix], [], "hexpm", "680ab01ef5d15b161ed6a95449fac5c6b8f60055677a8e79acf01b27baa4390b"}, "chartkick": {:hex, :chartkick, "1.0.0", "8f640a746ebb90f5975ad0096da872023bc5c9ccf5d6d5654c4fed11c32b9686", [:mix], [{:elixir_uuid, "~> 1.2", [hex: :elixir_uuid, repo: "hexpm", optional: false]}], "hexpm", "219e4b95a9b89723a2155ba0f4928c4789a6f67a49d478f3fa9f92793c37231a"}, "comeonin": {:hex, :comeonin, "5.3.3", "2c564dac95a35650e9b6acfe6d2952083d8a08e4a89b93a481acb552b325892e", [:mix], [], "hexpm", "3e38c9c2cb080828116597ca8807bb482618a315bfafd98c90bc22a821cc84df"}, "connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"}, - "cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"}, + "cowboy": {:hex, :cowboy, "2.10.0", "ff9ffeff91dae4ae270dd975642997afe2a1179d94b1887863e43f681a203e26", [:make, :rebar3], [{:cowlib, "2.12.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "3afdccb7183cc6f143cb14d3cf51fa00e53db9ec80cdcd525482f5e99bc41d6b"}, "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, - "cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"}, + "cowlib": {:hex, :cowlib, "2.12.1", "a9fa9a625f1d2025fe6b462cb865881329b5caff8f1854d1cbc9f9533f00e1e1", [:make, :rebar3], [], "hexpm", "163b73f6367a7341b33c794c4e88e7dbfe6498ac42dcd69ef44c5bc5507c8db0"}, "db_connection": {:hex, :db_connection, "2.4.3", "3b9aac9f27347ec65b271847e6baeb4443d8474289bd18c1d6f4de655b70c94d", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c127c15b0fa6cfb32eed07465e05da6c815b032508d4ed7c116122871df73c12"}, - "decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"}, + "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, "earmark": {:hex, :earmark, "1.4.37", "56ce845c543393aa3f9b294c818c3d783452a4a67e4ab18c4303a954a8b59363", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "d86d5e12868db86d5321b00e62a4bbcb4150346e4acc9a90a041fb188a5cb106"}, "earmark_parser": {:hex, :earmark_parser, "1.4.31", "a93921cdc6b9b869f519213d5bc79d9e218ba768d7270d46fdcf1c01bacff9e2", [:mix], [], "hexpm", "317d367ee0335ef037a87e46c91a2269fef6306413f731e8ec11fc45a7efd059"}, - "ecto": {:hex, :ecto, "3.9.5", "9f0aa7ae44a1577b651c98791c6988cd1b69b21bc724e3fd67090b97f7604263", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d4f3115d8cbacdc0bfa4b742865459fb1371d0715515842a1fb17fe31920b74c"}, + "ecto": {:hex, :ecto, "3.9.6", "2f420c173efcb2e22fa4f8fc41e75e02b3c5bd4cffef12085cae5418c12e530d", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "df17bc06ba6f78a7b764e4a14ef877fe5f4499332c5a105ace11fe7013b72c84"}, "ecto_sql": {:hex, :ecto_sql, "3.9.2", "34227501abe92dba10d9c3495ab6770e75e79b836d114c41108a4bf2ce200ad5", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.9.2", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "1eb5eeb4358fdbcd42eac11c1fbd87e3affd7904e639d77903c1358b2abd3f70"}, "elixir_make": {:hex, :elixir_make, "0.7.6", "67716309dc5d43e16b5abbd00c01b8df6a0c2ab54a8f595468035a50189f9169", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}], "hexpm", "5a0569756b0f7873a77687800c164cca6dfc03a09418e6fcf853d78991f49940"}, "elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"}, @@ -21,19 +21,19 @@ "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, "floki": {:hex, :floki, "0.34.2", "5fad07ef153b3b8ec110b6b155ec3780c4b2c4906297d0b4be1a7162d04a7e02", [:mix], [], "hexpm", "26b9d50f0f01796bc6be611ca815c5e0de034d2128e39cc9702eee6b66a4d1c8"}, "gettext": {:hex, :gettext, "0.22.1", "e7942988383c3d9eed4bdc22fc63e712b655ae94a672a27e4900e3d4a2c43581", [:mix], [{:expo, "~> 0.4.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "ad105b8dab668ee3f90c0d3d94ba75e9aead27a62495c101d94f2657a190ac5d"}, - "jason": {:hex, :jason, "1.4.0", "e855647bc964a44e2f67df589ccf49105ae039d4179db7f6271dfd3843dc27e6", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "79a3791085b2a0f743ca04cec0f7be26443738779d09302e01318f97bdb82121"}, + "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, "makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"}, "makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"}, - "mime": {:hex, :mime, "2.0.3", "3676436d3d1f7b81b5a2d2bd8405f412c677558c81b1c92be58c00562bb59095", [:mix], [], "hexpm", "27a30bf0db44d25eecba73755acf4068cbfe26a4372f9eb3e4ea3a45956bff6b"}, + "mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"}, "nimble_parsec": {:hex, :nimble_parsec, "1.3.0", "9e18a119d9efc3370a3ef2a937bf0b24c088d9c4bf0ba9d7c3751d49d347d035", [:mix], [], "hexpm", "7977f183127a7cbe9346981e2f480dc04c55ffddaef746bd58debd566070eef8"}, "phoenix": {:hex, :phoenix, "1.6.16", "e5bdd18c7a06da5852a25c7befb72246de4ddc289182285f8685a40b7b5f5451", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0 or ~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e15989ff34f670a96b95ef6d1d25bad0d9c50df5df40b671d8f4a669e050ac39"}, "phoenix_ecto": {:hex, :phoenix_ecto, "4.4.0", "0672ed4e4808b3fbed494dded89958e22fb882de47a97634c0b13e7b0b5f7720", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "09864e558ed31ee00bd48fcc1d4fc58ae9678c9e81649075431e69dbabb43cc1"}, - "phoenix_html": {:hex, :phoenix_html, "3.3.1", "4788757e804a30baac6b3fc9695bf5562465dd3f1da8eb8460ad5b404d9a2178", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "bed1906edd4906a15fd7b412b85b05e521e1f67c9a85418c55999277e553d0d3"}, - "phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.6.5", "1495bb014be12c9a9252eca04b9af54246f6b5c1e4cd1f30210cd00ec540cf8e", [:mix], [{:ecto, "~> 3.6.2 or ~> 3.7", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_mysql_extras, "~> 0.3", [hex: :ecto_mysql_extras, repo: "hexpm", optional: true]}, {:ecto_psql_extras, "~> 0.7", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.17.7", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "ef4fa50dd78364409039c99cf6f98ab5209b4c5f8796c17f4db118324f0db852"}, + "phoenix_html": {:hex, :phoenix_html, "3.3.2", "d6ce982c6d8247d2fc0defe625255c721fb8d5f1942c5ac051f6177bffa5973f", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "44adaf8e667c1c20fb9d284b6b0fa8dc7946ce29e81ce621860aa7e96de9a11d"}, + "phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.7.2", "97cc4ff2dba1ebe504db72cb45098cb8e91f11160528b980bd282cc45c73b29c", [:mix], [{:ecto, "~> 3.6.2 or ~> 3.7", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_mysql_extras, "~> 0.5", [hex: :ecto_mysql_extras, repo: "hexpm", optional: true]}, {:ecto_psql_extras, "~> 0.7", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.18.3", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6 or ~> 1.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "0e5fdf063c7a3b620c566a30fcf68b7ee02e5e46fe48ee46a6ec3ba382dc05b7"}, "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.4.1", "2aff698f5e47369decde4357ba91fc9c37c6487a512b41732818f2204a8ef1d3", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "9bffb834e7ddf08467fe54ae58b5785507aaba6255568ae22b4d46e2bb3615ab"}, - "phoenix_live_view": {:hex, :phoenix_live_view, "0.17.14", "5ec615d4d61bf9d4755f158bd6c80372b715533fe6d6219e12d74fb5eedbeac1", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.0 or ~> 1.7.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.1", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "afeb6ba43ce329a6f7fc1c9acdfc6d3039995345f025febb7f409a92f6faebd3"}, - "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.1", "ba04e489ef03763bf28a17eb2eaddc2c20c6d217e2150a61e3298b0f4c2012b5", [:mix], [], "hexpm", "81367c6d1eea5878ad726be80808eb5a787a23dee699f96e72b1109c57cdd8d9"}, - "phoenix_template": {:hex, :phoenix_template, "1.0.1", "85f79e3ad1b0180abb43f9725973e3b8c2c3354a87245f91431eec60553ed3ef", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "157dc078f6226334c91cb32c1865bf3911686f8bcd6bcff86736f6253e6993ee"}, + "phoenix_live_view": {:hex, :phoenix_live_view, "0.18.18", "1f38fbd7c363723f19aad1a04b5490ff3a178e37daaf6999594d5f34796c47fc", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.15 or ~> 1.7.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.3", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a5810d0472f3189ede6d2a95bda7f31c6113156b91784a3426cb0ab6a6d85214"}, + "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.3", "3168d78ba41835aecad272d5e8cd51aa87a7ac9eb836eabc42f6e57538e3731d", [:mix], [], "hexpm", "bba06bc1dcfd8cb086759f0edc94a8ba2bc8896d5331a1e2c2902bf8e36ee502"}, + "phoenix_template": {:hex, :phoenix_template, "1.0.3", "32de561eefcefa951aead30a1f94f1b5f0379bc9e340bb5c667f65f1edfa4326", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "16f4b6588a4152f3cc057b9d0c0ba7e82ee23afa65543da535313ad8d25d8e2c"}, "phoenix_view": {:hex, :phoenix_view, "2.0.2", "6bd4d2fd595ef80d33b439ede6a19326b78f0f1d8d62b9a318e3d9c1af351098", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}], "hexpm", "a929e7230ea5c7ee0e149ffcf44ce7cf7f4b6d2bfe1752dd7c084cdff152d36f"}, "plug": {:hex, :plug, "1.14.2", "cff7d4ec45b4ae176a227acd94a7ab536d9b37b942c8e8fa6dfc0fff98ff4d80", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "842fc50187e13cf4ac3b253d47d9474ed6c296a8732752835ce4a86acdf68d13"}, "plug_cowboy": {:hex, :plug_cowboy, "2.6.1", "9a3bbfceeb65eff5f39dab529e5cd79137ac36e913c02067dba3963a26efe9b2", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "de36e1a21f451a18b790f37765db198075c25875c64834bcc82d90b309eb6613"}, diff --git a/priv/repo/migrations/20230417211058_create_workout_items.exs b/priv/repo/migrations/20230417211058_create_workout_items.exs index e7caa0e..a32c109 100644 --- a/priv/repo/migrations/20230417211058_create_workout_items.exs +++ b/priv/repo/migrations/20230417211058_create_workout_items.exs @@ -9,7 +9,9 @@ defmodule Fitness.Repo.Migrations.CreateWorkoutItems do add :reps, :integer add :check_box, :boolean, default: false, null: false add :exercise_id, references(:exercises, on_delete: :delete_all), null: false - add :workout_template_id, references(:workout_templates, on_delete: :delete_all), null: false + + add :workout_template_id, references(:workout_templates, on_delete: :delete_all), + null: false timestamps() end diff --git a/priv/repo/seeds.exs b/priv/repo/seeds.exs index b066dcc..c89db31 100644 --- a/priv/repo/seeds.exs +++ b/priv/repo/seeds.exs @@ -13,21 +13,105 @@ alias Fitness.Exercises alias Fitness.Accounts - File.read!("priv/repo/list_of_exercises.txt") |> :erlang.binary_to_term() |> Enum.uniq() |> Enum.each(fn workout -> Exercises.create_exercise(workout) end) +Accounts.register_user(%{ + email: "test@test.com", + password: "test@test.com", + is_admin: true, + username: "Admin001", + name: "Admin" +}) + +Accounts.register_user(%{ + email: "test@test1.com", + password: "mak12345", + is_admin: false, + username: "puppies-lover", + name: "Andervrs", + player_score: "1001" +}) + +Accounts.register_user(%{ + email: "test@test2.com", + password: "mak12345", + is_admin: false, + username: "Full-stack-developer", + name: "Alfred", + player_score: "800" +}) + +Accounts.register_user(%{ + email: "test@test3.com", + password: "mak12345", + is_admin: false, + username: "Captain-America", + name: "john", + player_score: "1000" +}) + +Accounts.register_user(%{ + email: "test@test4.com", + password: "mak12345", + is_admin: false, + username: "Rhythm-Rider", + name: "Einer", + player_score: "700" +}) + +Accounts.register_user(%{ + email: "test@test5.com", + password: "mak12345", + is_admin: false, + username: "Richie-Rich", + name: "yusef", + player_score: "900" +}) + +Accounts.register_user(%{ + email: "test@test6.com", + password: "mak12345", + is_admin: false, + username: "The-Label-Man", + name: "eddie", + player_score: "10000" +}) + +Accounts.register_user(%{ + email: "test@test7.com", + password: "mak12345", + is_admin: false, + username: "The-Wizard", + name: "brook", + player_score: "5000" +}) + +Accounts.register_user(%{ + email: "test@test8.com", + password: "mak12345", + is_admin: false, + username: "Albert-Einstein", + name: "steve", + player_score: "600" +}) + +Accounts.register_user(%{ + email: "test@test9.com", + password: "mak12345", + is_admin: false, + username: "The-Bird-Man", + name: "marko", + player_score: "500" +}) -Accounts.register_user(%{email: "test@test.com", password: "test@test.com", is_admin: true, username: "Admin001", name: "Admin"}) -Accounts.register_user(%{email: "test@test1.com", password: "mak12345", is_admin: false, username: "puppies-lover", name: "Andervrs", player_score: "1001"}) -Accounts.register_user(%{email: "test@test2.com", password: "mak12345", is_admin: false, username: "Full-stack-developer", name: "Alfred", player_score: "800"}) -Accounts.register_user(%{email: "test@test3.com", password: "mak12345", is_admin: false, username: "Captain-America", name: "john", player_score: "1000"}) -Accounts.register_user(%{email: "test@test4.com", password: "mak12345", is_admin: false, username: "Rhythm-Rider", name: "Einer", player_score: "700"}) -Accounts.register_user(%{email: "test@test5.com", password: "mak12345", is_admin: false, username: "Richie-Rich", name: "yusef", player_score: "900"}) -Accounts.register_user(%{email: "test@test6.com", password: "mak12345", is_admin: false, username: "The-Label-Man", name: "eddie", player_score: "10000"}) -Accounts.register_user(%{email: "test@test7.com", password: "mak12345", is_admin: false, username: "The-Wizard", name: "brook", player_score: "5000"}) -Accounts.register_user(%{email: "test@test8.com", password: "mak12345", is_admin: false, username: "Albert-Einstein", name: "steve", player_score: "600"}) -Accounts.register_user(%{email: "test@test9.com", password: "mak12345", is_admin: false, username: "The-Bird-Man", name: "marko", player_score: "500"}) -Accounts.register_user(%{email: "test@test10.com", password: "mak12345", is_admin: false, username: "Elixir-Newbie", name: "mohsin",player_score: "2000"}) +Accounts.register_user(%{ + email: "test@test10.com", + password: "mak12345", + is_admin: false, + username: "Elixir-Newbie", + name: "mohsin", + player_score: "2000" +}) diff --git a/test/fitness/accounts_test.exs b/test/fitness/accounts_test.exs index b5868fc..ea5db29 100644 --- a/test/fitness/accounts_test.exs +++ b/test/fitness/accounts_test.exs @@ -59,13 +59,23 @@ defmodule Fitness.AccountsTest do end test "validates email and password when given" do - {:error, changeset} = Accounts.register_user(%{email: "not valid", password: "1", name: "not valid123", username: "not valid"}) + {:error, changeset} = + Accounts.register_user(%{ + email: "not valid", + password: "1", + name: "not valid123", + username: "not valid" + }) assert %{ email: ["must have the @ sign and no spaces"], password: ["should be at least 6 character(s)"], - name: ["A name must be made up of only letters and should not include any symbols or numbers."], - username: ["A username should consist of both letters and numbers, and should not contain any spaces"] + name: [ + "A name must be made up of only letters and should not include any symbols or numbers." + ], + username: [ + "A username should consist of both letters and numbers, and should not contain any spaces" + ] } = errors_on(changeset) end diff --git a/test/fitness/exercises_test.exs b/test/fitness/exercises_test.exs index 7349a76..7f0a6b0 100644 --- a/test/fitness/exercises_test.exs +++ b/test/fitness/exercises_test.exs @@ -21,7 +21,15 @@ defmodule Fitness.ExercisesTest do end test "create_exercise/1 with valid data creates a exercise" do - valid_attrs = %{description: "some description", gif_url: "some gif_url", level: "some level", name: "some name", type: "some type", equipment: "some equipment",body_part: "some body part"} + valid_attrs = %{ + description: "some description", + gif_url: "some gif_url", + level: "some level", + name: "some name", + type: "some type", + equipment: "some equipment", + body_part: "some body part" + } assert {:ok, %Exercise{} = exercise} = Exercises.create_exercise(valid_attrs) assert exercise.description == "some description" @@ -39,7 +47,14 @@ defmodule Fitness.ExercisesTest do test "update_exercise/2 with valid data updates the exercise" do exercise = exercise_fixture() - update_attrs = %{description: "some updated description", gif_url: "some updated gif_url", level: "some updated level", name: "some updated name", type: "some updated type"} + + update_attrs = %{ + description: "some updated description", + gif_url: "some updated gif_url", + level: "some updated level", + name: "some updated name", + type: "some updated type" + } assert {:ok, %Exercise{} = exercise} = Exercises.update_exercise(exercise, update_attrs) assert exercise.description == "some updated description" diff --git a/test/fitness/workout_templates_test.exs b/test/fitness/workout_templates_test.exs index 5cba24d..b75b21b 100644 --- a/test/fitness/workout_templates_test.exs +++ b/test/fitness/workout_templates_test.exs @@ -30,10 +30,10 @@ defmodule Fitness.WorkoutTemplatesTest do user = user_fixture() valid_attrs = %{name: "some name", user_id: user.id} - assert {:ok, %WorkoutTemplate{} = workout_template} = + assert {:ok, %WorkoutTemplate{} = workout_template} = WorkoutTemplates.create_workout_template(valid_attrs) - assert workout_template.name == "some name" + assert workout_template.name == "some name" end test "create_workout_template/1 with invalid data returns error changeset" do diff --git a/test/fitness_web/controllers/user_reset_password_controller_test.exs b/test/fitness_web/controllers/user_reset_password_controller_test.exs index 0d40786..5ae4ac1 100644 --- a/test/fitness_web/controllers/user_reset_password_controller_test.exs +++ b/test/fitness_web/controllers/user_reset_password_controller_test.exs @@ -12,7 +12,7 @@ defmodule FitnessWeb.UserResetPasswordControllerTest do describe "GET /users/reset_password" do test "renders the reset password page", %{conn: conn} do conn = get(conn, Routes.user_reset_password_path(conn, :new)) - response = html_response(conn, 200) + response = html_response(conn, 200) assert response =~ "Forgot your password?" end end diff --git a/test/fitness_web/live/exercise_live_test.exs b/test/fitness_web/live/exercise_live_test.exs index f357042..c8a1339 100644 --- a/test/fitness_web/live/exercise_live_test.exs +++ b/test/fitness_web/live/exercise_live_test.exs @@ -25,7 +25,15 @@ defmodule FitnessWeb.ExerciseLiveTest do equipment: "Others", body_part: "Others" } - @invalid_attrs %{description: nil, gif_url: nil, level: "Others", name: nil, type: "Others", equipment: "Others", body_part: "Others"} + @invalid_attrs %{ + description: nil, + gif_url: nil, + level: "Others", + name: nil, + type: "Others", + equipment: "Others", + body_part: "Others" + } setup %{conn: conn} do conn = @@ -104,7 +112,6 @@ defmodule FitnessWeb.ExerciseLiveTest do end test "deletes exercise in listing", %{conn: conn, exercise: exercise, user: user} do - conn = conn |> log_in_user(user) {:ok, index_live, _html} = live(conn, Routes.exercise_index_path(conn, :index)) @@ -127,7 +134,6 @@ defmodule FitnessWeb.ExerciseLiveTest do {:ok, show_live, _html} = live(conn, Routes.exercise_show_path(conn, :show, exercise)) - assert show_live |> element("a", "Edit") |> render_click() =~ "Edit Exercise" diff --git a/test/fitness_web/live/workout_template_live_test.exs b/test/fitness_web/live/workout_template_live_test.exs index 2da4a5a..f260ba6 100644 --- a/test/fitness_web/live/workout_template_live_test.exs +++ b/test/fitness_web/live/workout_template_live_test.exs @@ -18,7 +18,11 @@ defmodule FitnessWeb.WorkoutTemplateLiveTest do describe "Index" do setup [:create_workout_template] - test "lists all workout_templates", %{conn: conn, workout_template: workout_template, user: user} do + test "lists all workout_templates", %{ + conn: conn, + workout_template: workout_template, + user: user + } do conn = conn |> log_in_user(user) {:ok, _index_live, html} = live(conn, Routes.workout_template_index_path(conn, :index)) @@ -33,30 +37,36 @@ defmodule FitnessWeb.WorkoutTemplateLiveTest do {:ok, index_live, _html} = live(conn, Routes.workout_template_index_path(conn, :index)) assert index_live |> element("a", "New Workout") |> render_click() =~ - "New Workout template" + "New Workout template" assert_patch(index_live, Routes.workout_template_index_path(conn, :new)) assert index_live - |> form("#workout_template-form", workout_template: @invalid_attrs) - |> render_change() =~ "can't be blank" + |> form("#workout_template-form", workout_template: @invalid_attrs) + |> render_change() =~ "can't be blank" {:error, {:live_redirect, %{to: location}}} = index_live |> form("#workout_template-form", workout_template: @create_attrs) |> render_submit() - {:ok, _, html} = live(conn, location) + {:ok, _, html} = live(conn, location) assert html =~ "SOME NAME" end - test "updates workout_template in listing", %{conn: conn, workout_template: workout_template, user: user} do + test "updates workout_template in listing", %{ + conn: conn, + workout_template: workout_template, + user: user + } do conn = conn |> log_in_user(user) {:ok, index_live, _html} = live(conn, Routes.workout_template_index_path(conn, :index)) - assert index_live |> element("#workout_template-#{workout_template.id} a", "Edit") |> render_click() =~ + assert index_live + |> element("#workout_template-#{workout_template.id} a", "Edit") + |> render_click() =~ "Edit Workout template" assert_patch(index_live, Routes.workout_template_index_path(conn, :edit, workout_template)) @@ -75,12 +85,19 @@ defmodule FitnessWeb.WorkoutTemplateLiveTest do assert html =~ "SOME UPDATED NAME" end - test "deletes workout_template in listing", %{conn: conn, workout_template: workout_template, user: user} do + test "deletes workout_template in listing", %{ + conn: conn, + workout_template: workout_template, + user: user + } do conn = conn |> log_in_user(user) {:ok, index_live, _html} = live(conn, Routes.workout_template_index_path(conn, :index)) - assert index_live |> element("#workout_template-#{workout_template.id} a", "Delete") |> render_click() + assert index_live + |> element("#workout_template-#{workout_template.id} a", "Delete") + |> render_click() + refute has_element?(index_live, "#workout_template-#{workout_template.id}") end end @@ -88,22 +105,33 @@ defmodule FitnessWeb.WorkoutTemplateLiveTest do describe "Show" do setup [:create_workout_template] - test "displays workout_template", %{conn: conn, workout_template: workout_template, user: user} do + test "displays workout_template", %{ + conn: conn, + workout_template: workout_template, + user: user + } do conn = conn |> log_in_user(user) - {:ok, _show_live, html} = live(conn, Routes.workout_template_show_path(conn, :show, workout_template)) + + {:ok, _show_live, html} = + live(conn, Routes.workout_template_show_path(conn, :show, workout_template)) assert html =~ "Show Workout template" assert html =~ String.upcase(workout_template.name) end - test "Add workout_items within modal", %{conn: conn, workout_template: workout_template, user: user} do - conn = conn |> log_in_user(user) + test "Add workout_items within modal", %{ + conn: conn, + workout_template: workout_template, + user: user + } do + conn = conn |> log_in_user(user) - {:ok, show_live, _html} = live(conn, Routes.workout_template_show_path(conn, :show, workout_template)) + {:ok, show_live, _html} = + live(conn, Routes.workout_template_show_path(conn, :show, workout_template)) - assert show_live |> element("a", "ADD EXERCISE") |> render_click() =~ "Add New Exercises" + assert show_live |> element("a", "ADD EXERCISE") |> render_click() =~ "Add New Exercises" - assert_patch(show_live, Routes.workout_template_show_path(conn, :edit, workout_template)) + assert_patch(show_live, Routes.workout_template_show_path(conn, :edit, workout_template)) # assert show_live # |> form("#workout_items_form", workout_items: @invalid_attrs_workout_items) From cd558ceefa7da54c265dba34b0f644f69e885c34 Mon Sep 17 00:00:00 2001 From: Maqbool Date: Mon, 21 Aug 2023 16:31:18 +0530 Subject: [PATCH 2/4] upgrade liveview 0.19.5 --- lib/fitness_web/live/profile_live/update_user_profile_form.ex | 4 ++-- mix.exs | 4 ++-- mix.lock | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/fitness_web/live/profile_live/update_user_profile_form.ex b/lib/fitness_web/live/profile_live/update_user_profile_form.ex index 2d1f9a7..f86e356 100644 --- a/lib/fitness_web/live/profile_live/update_user_profile_form.ex +++ b/lib/fitness_web/live/profile_live/update_user_profile_form.ex @@ -28,7 +28,7 @@ defmodule FitnessWeb.ProfileLive.UpdateUserProfileForm do <%= for entry <- @uploads.user_image.entries do %>
- <%= live_img_preview entry, class: "w-48 h-48 pb-4 rounded" %> + <.live_img_preview entry={entry} class="w-48 h-48 pb-4 rounded" />
<% end %>
@@ -38,7 +38,7 @@ defmodule FitnessWeb.ProfileLive.UpdateUserProfileForm do
diff --git a/mix.exs b/mix.exs index c079ce7..b9d42da 100644 --- a/mix.exs +++ b/mix.exs @@ -40,9 +40,9 @@ defmodule Fitness.MixProject do {:postgrex, ">= 0.0.0"}, {:phoenix_html, "~> 3.0"}, {:phoenix_live_reload, "~> 1.2", only: :dev}, - {:phoenix_live_view, "~> 0.18.18"}, + {:phoenix_live_view, "~> 0.19.0"}, {:floki, ">= 0.30.0", only: :test}, - {:phoenix_live_dashboard, "~> 0.7"}, + {:phoenix_live_dashboard, "~> 0.8"}, {:esbuild, "~> 0.4", runtime: Mix.env() == :dev}, {:swoosh, "~> 1.3"}, {:telemetry_metrics, "~> 0.6"}, diff --git a/mix.lock b/mix.lock index 6d7e00e..bd3b058 100644 --- a/mix.lock +++ b/mix.lock @@ -29,9 +29,9 @@ "phoenix": {:hex, :phoenix, "1.6.16", "e5bdd18c7a06da5852a25c7befb72246de4ddc289182285f8685a40b7b5f5451", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0 or ~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e15989ff34f670a96b95ef6d1d25bad0d9c50df5df40b671d8f4a669e050ac39"}, "phoenix_ecto": {:hex, :phoenix_ecto, "4.4.0", "0672ed4e4808b3fbed494dded89958e22fb882de47a97634c0b13e7b0b5f7720", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "09864e558ed31ee00bd48fcc1d4fc58ae9678c9e81649075431e69dbabb43cc1"}, "phoenix_html": {:hex, :phoenix_html, "3.3.2", "d6ce982c6d8247d2fc0defe625255c721fb8d5f1942c5ac051f6177bffa5973f", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "44adaf8e667c1c20fb9d284b6b0fa8dc7946ce29e81ce621860aa7e96de9a11d"}, - "phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.7.2", "97cc4ff2dba1ebe504db72cb45098cb8e91f11160528b980bd282cc45c73b29c", [:mix], [{:ecto, "~> 3.6.2 or ~> 3.7", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_mysql_extras, "~> 0.5", [hex: :ecto_mysql_extras, repo: "hexpm", optional: true]}, {:ecto_psql_extras, "~> 0.7", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.18.3", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6 or ~> 1.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "0e5fdf063c7a3b620c566a30fcf68b7ee02e5e46fe48ee46a6ec3ba382dc05b7"}, + "phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.8.1", "c4f2a2d3b26e6ca684d162ccf18aaeed8bed2181896e0393d0a2959789482e51", [:mix], [{:ecto, "~> 3.6.2 or ~> 3.7", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_mysql_extras, "~> 0.5", [hex: :ecto_mysql_extras, repo: "hexpm", optional: true]}, {:ecto_psql_extras, "~> 0.7", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:ecto_sqlite3_extras, "~> 1.1.7 or ~> 1.2.0", [hex: :ecto_sqlite3_extras, repo: "hexpm", optional: true]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.19.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6 or ~> 1.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "1ca0f954274ce1916f771f86b3d49a91d3447e7c32d171660676095c5f30abe9"}, "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.4.1", "2aff698f5e47369decde4357ba91fc9c37c6487a512b41732818f2204a8ef1d3", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "9bffb834e7ddf08467fe54ae58b5785507aaba6255568ae22b4d46e2bb3615ab"}, - "phoenix_live_view": {:hex, :phoenix_live_view, "0.18.18", "1f38fbd7c363723f19aad1a04b5490ff3a178e37daaf6999594d5f34796c47fc", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.15 or ~> 1.7.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.3", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a5810d0472f3189ede6d2a95bda7f31c6113156b91784a3426cb0ab6a6d85214"}, + "phoenix_live_view": {:hex, :phoenix_live_view, "0.19.5", "6e730595e8e9b8c5da230a814e557768828fd8dfeeb90377d2d8dbb52d4ec00a", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.15 or ~> 1.7.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.3", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b2eaa0dd3cfb9bd7fb949b88217df9f25aed915e986a28ad5c8a0d054e7ca9d3"}, "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.3", "3168d78ba41835aecad272d5e8cd51aa87a7ac9eb836eabc42f6e57538e3731d", [:mix], [], "hexpm", "bba06bc1dcfd8cb086759f0edc94a8ba2bc8896d5331a1e2c2902bf8e36ee502"}, "phoenix_template": {:hex, :phoenix_template, "1.0.3", "32de561eefcefa951aead30a1f94f1b5f0379bc9e340bb5c667f65f1edfa4326", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "16f4b6588a4152f3cc057b9d0c0ba7e82ee23afa65543da535313ad8d25d8e2c"}, "phoenix_view": {:hex, :phoenix_view, "2.0.2", "6bd4d2fd595ef80d33b439ede6a19326b78f0f1d8d62b9a318e3d9c1af351098", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}], "hexpm", "a929e7230ea5c7ee0e149ffcf44ce7cf7f4b6d2bfe1752dd7c084cdff152d36f"}, From c1f3363b3b9007e512ebb25f71c5f910155ea8dc Mon Sep 17 00:00:00 2001 From: Maqbool Date: Mon, 21 Aug 2023 16:57:07 +0530 Subject: [PATCH 3/4] upgrad to phoenix 1.9.0 --- .formatter.exs | 7 +- lib/fitness_web.ex | 14 + lib/fitness_web/endpoint.ex | 2 +- .../exercise_live/form_component.html.heex | 93 ++++-- .../live/exercise_live/index.html.heex | 156 ++++++--- .../live/exercise_live/show.html.heex | 43 ++- lib/fitness_web/live/live_helpers.ex | 4 +- .../live/profile_live/Activity_history.ex | 78 +++-- .../live/profile_live/score_board_live.ex | 93 ++++-- .../profile_live/update_user_profile_form.ex | 69 ++-- .../live/profile_live/user_profile_live.ex | 140 ++++++--- .../check_boxes_live_component.ex | 153 +++++---- .../form_component.html.heex | 46 +-- .../workout_template_live/index.html.heex | 116 ++++--- .../live/workout_template_live/show.html.heex | 295 +++++++++++------- .../workout_item_form.ex | 87 ++++-- .../workout_template_live/workout_zone.ex | 165 ++++++---- .../templates/layout/_user_menu.html.heex | 20 +- .../templates/layout/app.html.heex | 8 +- .../templates/layout/live.html.heex | 38 ++- .../templates/layout/root.html.heex | 194 ++++++++++-- .../templates/page/index.html.heex | 155 ++++++--- .../user_confirmation/edit.html.heex | 14 +- .../templates/user_confirmation/new.html.heex | 11 +- .../templates/user_registration/new.html.heex | 104 +++--- .../user_reset_password/edit.html.heex | 52 ++- .../user_reset_password/new.html.heex | 33 +- .../templates/user_session/new.html.heex | 53 +++- .../templates/user_settings/edit.html.heex | 148 +++++---- mix.exs | 3 +- mix.lock | 4 +- test/fitness_web/live/exercise_live_test.exs | 1 - test/support/conn_case.ex | 2 + 33 files changed, 1627 insertions(+), 774 deletions(-) diff --git a/.formatter.exs b/.formatter.exs index 8a6391c..ef8840c 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -1,5 +1,6 @@ [ - import_deps: [:ecto, :phoenix], - inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"], - subdirectories: ["priv/*/migrations"] + import_deps: [:ecto, :ecto_sql, :phoenix], + subdirectories: ["priv/*/migrations"], + plugins: [Phoenix.LiveView.HTMLFormatter], + inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"] ] diff --git a/lib/fitness_web.ex b/lib/fitness_web.ex index 5a3176f..d1de340 100644 --- a/lib/fitness_web.ex +++ b/lib/fitness_web.ex @@ -17,6 +17,8 @@ defmodule FitnessWeb do and import those modules here. """ + def static_paths, do: ~w(assets fonts images videos favicon.ico robots.txt) + def controller do quote do use Phoenix.Controller, namespace: FitnessWeb @@ -24,6 +26,8 @@ defmodule FitnessWeb do import Plug.Conn import FitnessWeb.Gettext alias FitnessWeb.Router.Helpers, as: Routes + + unquote(verified_routes()) end end @@ -100,6 +104,16 @@ defmodule FitnessWeb do import FitnessWeb.ErrorHelpers import FitnessWeb.Gettext alias FitnessWeb.Router.Helpers, as: Routes + unquote(verified_routes()) + end + end + + def verified_routes do + quote do + use Phoenix.VerifiedRoutes, + endpoint: FitnessWeb.Endpoint, + router: FitnessWeb.Router, + statics: FitnessWeb.static_paths() end end diff --git a/lib/fitness_web/endpoint.ex b/lib/fitness_web/endpoint.ex index 14b19c1..e1a44aa 100644 --- a/lib/fitness_web/endpoint.ex +++ b/lib/fitness_web/endpoint.ex @@ -20,7 +20,7 @@ defmodule FitnessWeb.Endpoint do at: "/", from: :fitness, gzip: false, - only: ~w(assets fonts images favicon.ico robots.txt) + only: FitnessWeb.static_paths() # Code reloading can be explicitly enabled under the # :code_reloader configuration of your endpoint. diff --git a/lib/fitness_web/live/exercise_live/form_component.html.heex b/lib/fitness_web/live/exercise_live/form_component.html.heex index 86ee988..b4f4fc5 100644 --- a/lib/fitness_web/live/exercise_live/form_component.html.heex +++ b/lib/fitness_web/live/exercise_live/form_component.html.heex @@ -1,8 +1,7 @@ - - -
-

<%= @title %>

+

+ <%= @title %> +

<.form :let={f} @@ -10,54 +9,92 @@ id="exercise-form" phx-target={@myself} phx-change="validate" - phx-submit="save"> - + phx-submit="save" + >
- <%= label f, :name, class: "font-semibold mb-1 text-gray-700" %> - <%= text_input f, :name, class: "rounded-lg border-gray-300 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-400" %> - <%= error_tag f, :name %> + <%= label(f, :name, class: "font-semibold mb-1 text-gray-700") %> + <%= text_input(f, :name, + class: + "rounded-lg border-gray-300 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-400" + ) %> + <%= error_tag(f, :name) %>
- <%= label f, :body_part, class: "font-semibold mb-1 text-gray-700" %> - <%= select f, :body_part, ["Others","chest","back", "legs", "arms","Abdominals", "Shoulders", "Glutes", "Triceps", "Hamstrings"], class: "rounded-lg border-gray-300 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-400" %> - <%= error_tag f, :body_part %> + <%= label(f, :body_part, class: "font-semibold mb-1 text-gray-700") %> + <%= select( + f, + :body_part, + [ + "Others", + "chest", + "back", + "legs", + "arms", + "Abdominals", + "Shoulders", + "Glutes", + "Triceps", + "Hamstrings" + ], + class: + "rounded-lg border-gray-300 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-400" + ) %> + <%= error_tag(f, :body_part) %>
- <%= label f, :equipment, class: "font-semibold mb-1 text-gray-700" %> - <%= select f, :equipment, ["Others", "Machine", "Barbell", "Dumbbell", "Body Only"], class: "rounded-lg border-gray-300 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-400" %> - <%= error_tag f, :equipment %> + <%= label(f, :equipment, class: "font-semibold mb-1 text-gray-700") %> + <%= select(f, :equipment, ["Others", "Machine", "Barbell", "Dumbbell", "Body Only"], + class: + "rounded-lg border-gray-300 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-400" + ) %> + <%= error_tag(f, :equipment) %>
- <%= label f, :description, class: "font-semibold mb-1 text-gray-700" %> - <%= textarea f, :description, class: "rounded-lg border-gray-300 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-400" %> - <%= error_tag f, :description %> + <%= label(f, :description, class: "font-semibold mb-1 text-gray-700") %> + <%= textarea(f, :description, + class: + "rounded-lg border-gray-300 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-400" + ) %> + <%= error_tag(f, :description) %>
- <%= label f, :gif_url, class: "font-semibold mb-1 text-gray-700" %> - <%= text_input f, :gif_url, class: "rounded-lg border-gray-300 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-400" %> - <%= error_tag f, :gif_url %> + <%= label(f, :gif_url, class: "font-semibold mb-1 text-gray-700") %> + <%= text_input(f, :gif_url, + class: + "rounded-lg border-gray-300 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-400" + ) %> + <%= error_tag(f, :gif_url) %>
- <%= label f, :level, class: "font-semibold mb-1 text-gray-700" %> - <%= select f, :level, ["Others", "Beginner", "Intermediate", "Expert"],class: "rounded-lg border-gray-300 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-400" %> - <%= error_tag f, :level %> + <%= label(f, :level, class: "font-semibold mb-1 text-gray-700") %> + <%= select(f, :level, ["Others", "Beginner", "Intermediate", "Expert"], + class: + "rounded-lg border-gray-300 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-400" + ) %> + <%= error_tag(f, :level) %>
- <%= label f, :type, class: "font-semibold mb-1 text-gray-700" %> - <%= select f, :type, ["Others", "strength", "cardio", "power-lifting", "stretching"], class: "rounded-lg border-gray-300 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-400" %> - <%= error_tag f, :type %> + <%= label(f, :type, class: "font-semibold mb-1 text-gray-700") %> + <%= select(f, :type, ["Others", "strength", "cardio", "power-lifting", "stretching"], + class: + "rounded-lg border-gray-300 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-400" + ) %> + <%= error_tag(f, :type) %>
- <%= submit "Create Exercise", class: "bg-green-400 hover:bg-green-600 text-white font-poppins py-2 px-4 rounded", phx_disable_with: "Saving..." %> + <%= submit("Create Exercise", + class: "bg-green-400 hover:bg-green-600 text-white font-poppins py-2 px-4 rounded", + phx_disable_with: "Saving..." + ) %>
diff --git a/lib/fitness_web/live/exercise_live/index.html.heex b/lib/fitness_web/live/exercise_live/index.html.heex index 3036c18..d2b015f 100644 --- a/lib/fitness_web/live/exercise_live/index.html.heex +++ b/lib/fitness_web/live/exercise_live/index.html.heex @@ -1,63 +1,127 @@
- -<%= if @live_action in [:new, :edit] do %> + <%= if @live_action in [:new, :edit] do %> <.modal return_to={Routes.exercise_index_path(@socket, :index)}> - <.live_component + <.live_component module={FitnessWeb.ExerciseLive.FormComponent} id={@exercise.id || :new} title={@page_title} action={@live_action} exercise={@exercise} return_to={Routes.exercise_index_path(@socket, :index)} - /> + /> -<% end %> + <% end %> - - <%= text_input :search, :text, autocomplete: "off", placeholder: "Search Exercises", value: @search, class: "flex-grow outline-none pl-10 font-poppins rounded" %> -
- - - - -
- <%= submit "" %> - +
+ <%= text_input(:search, :text, + autocomplete: "off", + placeholder: "Search Exercises", + value: @search, + class: "flex-grow outline-none pl-10 font-poppins rounded" + ) %> +
+ + + + +
+ <%= submit("") %> +
-<%= if assigns[:user] do %> -
- <.link patch={Routes.exercise_index_path(@socket, :new)} class="bg-blue-500 hover:bg-blue-700 text-white font-poppins py-2 px-4 rounded" >New Exercise -
-<% end %> + <%= if assigns[:user] do %> +
+ <.link + patch={Routes.exercise_index_path(@socket, :new)} + class="bg-blue-500 hover:bg-blue-700 text-white font-poppins py-2 px-4 rounded" + > + New Exercise + +
+ <% end %> -
- <%= for exercise <- @exercises do %> -
-
- - <%= link "#{exercise.level}", to: "#", phx_click: "search", phx_value_search: exercise.level %> -
-
-

<%= exercise.name %>

-
- <%= link "#{exercise.body_part}", to: "#", phx_click: "search", phx_value_search: exercise.body_part %> - <%= link "#{exercise.equipment}", to: "#", phx_click: "search", phx_value_search: exercise.equipment %> - <%= link "#{exercise.type}", to: "#", phx_click: "search", phx_value_search: exercise.type %> -
-
- - <.link navigate={Routes.exercise_show_path(@socket, :show, exercise)} class="text-blue-500 font-poppins hover:underline">Show +
+ <%= for exercise <- @exercises do %> +
+
+ + + <%= link("#{exercise.level}", + to: "#", + phx_click: "search", + phx_value_search: exercise.level + ) %> +
+
+

<%= exercise.name %>

+
+ + <%= link("#{exercise.body_part}", + to: "#", + phx_click: "search", + phx_value_search: exercise.body_part + ) %> + + + <%= link("#{exercise.equipment}", + to: "#", + phx_click: "search", + phx_value_search: exercise.equipment + ) %> + + + <%= link("#{exercise.type}", + to: "#", + phx_click: "search", + phx_value_search: exercise.type + ) %> + +
+
+ + <.link + navigate={Routes.exercise_show_path(@socket, :show, exercise)} + class="text-blue-500 font-poppins hover:underline" + > + Show + + - - <%= if assigns[:is_admin] do %> - <.link patch={Routes.exercise_index_path(@socket, :edit, exercise)} class="text-blue-500 font-poppins hover:underline" >Edit - <%= link "Delete", to: "#", phx_click: "delete", phx_value_id: exercise.id, data: [confirm: "Are you sure?"], class: "text-blue-500 font-poppins hover:underline" %> - <% end %> + <%= if assigns[:is_admin] do %> + + <.link + patch={Routes.exercise_index_path(@socket, :edit, exercise)} + class="text-blue-500 font-poppins hover:underline" + > + Edit + + + + <%= link("Delete", + to: "#", + phx_click: "delete", + phx_value_id: exercise.id, + data: [confirm: "Are you sure?"], + class: "text-blue-500 font-poppins hover:underline" + ) %> + + <% end %> +
-
- <% end %> -
- + <% end %> +
diff --git a/lib/fitness_web/live/exercise_live/show.html.heex b/lib/fitness_web/live/exercise_live/show.html.heex index a84e0ed..c2306fd 100644 --- a/lib/fitness_web/live/exercise_live/show.html.heex +++ b/lib/fitness_web/live/exercise_live/show.html.heex @@ -1,4 +1,3 @@ - <%= if @live_action in [:edit] do %> <.modal return_to={Routes.exercise_show_path(@socket, :show, @exercise)}> <.live_component @@ -17,29 +16,45 @@
<%= @exercise.level %> <%= if assigns[:is_admin] do %> - - <.link patch={Routes.exercise_show_path(@socket, :edit, @exercise)} class="text-blue-500 font-poppins hover:underline">Edit - + + <.link + patch={Routes.exercise_show_path(@socket, :edit, @exercise)} + class="text-blue-500 font-poppins hover:underline" + > + Edit + + <% end %> - <.link navigate={Routes.exercise_index_path(@socket, :index)} class="text-blue-500 font-poppins hover:underline">Back to List + <.link + navigate={Routes.exercise_index_path(@socket, :index)} + class="text-blue-500 font-poppins hover:underline" + > + Back to List + - -
- -
-
+ +
+

<%= @exercise.name %>

- <%= @exercise.body_part %> - <%= @exercise.equipment %> - <%= @exercise.type %> + + <%= @exercise.body_part %> + + + <%= @exercise.equipment %> + + + <%= @exercise.type %> +

<%= @exercise.description %>

-
diff --git a/lib/fitness_web/live/live_helpers.ex b/lib/fitness_web/live/live_helpers.ex index 010f698..a4a1d4a 100644 --- a/lib/fitness_web/live/live_helpers.ex +++ b/lib/fitness_web/live/live_helpers.ex @@ -35,7 +35,9 @@ defmodule FitnessWeb.LiveHelpers do phx-key="escape" > <%= if @return_to do %> - <.link id="close" patch={@return_to} class="phx-modal-close" phx_click={hide_modal()}>X + <.link id="close" patch={@return_to} class="phx-modal-close" phx_click={hide_modal()}> + X + <% else %> x <% end %> diff --git a/lib/fitness_web/live/profile_live/Activity_history.ex b/lib/fitness_web/live/profile_live/Activity_history.ex index d1247c8..a665d46 100644 --- a/lib/fitness_web/live/profile_live/Activity_history.ex +++ b/lib/fitness_web/live/profile_live/Activity_history.ex @@ -11,50 +11,68 @@ defmodule FitnessWeb.WorkoutTemplateLive.ActivityHistory do @impl true def render(assigns) do ~H""" -

History

- <%= if length(@workout_templates) >= 1 do %> - <% user_template_owner = Enum.filter(@workout_templates, fn each -> each.user_id == assigns[:current_user].id end) %> - + <%= if length(@workout_templates) >= 1 do %> + <% user_template_owner = + Enum.filter(@workout_templates, fn each -> each.user_id == assigns[:current_user].id end) %> - <% workout_template_are_finished = Enum.filter(user_template_owner, fn each -> each.is_finished == true end) %> -
+ <% workout_template_are_finished = + Enum.filter(user_template_owner, fn each -> each.is_finished == true end) %> +

- - - <%= length(workout_template_are_finished) %> Workouts + + + + + <%= length(workout_template_are_finished) %> Workouts

-
-
+
+
<%= for workout_template <- Enum.reverse(workout_template_are_finished) do %> -
- +
- -

<%= Calendar.strftime(workout_template.updated_at, "%B %-d, %Y") %>

- <%= String.upcase(workout_template.name) %> +

+ <%= Calendar.strftime(workout_template.updated_at, "%B %-d, %Y") %> +

+ + <%= String.upcase(workout_template.name) %> +

- - Score: <%= workout_template.workout_template_score %> + + + + Score: <%= workout_template.workout_template_score %> +

- <% list_of_same_exercise = Enum.group_by(workout_template.workout_items, fn each -> each.exercise_id end) |> Map.values() %> + <% list_of_same_exercise = + Enum.group_by(workout_template.workout_items, fn each -> each.exercise_id end) + |> Map.values() %> <%= for each_list <- list_of_same_exercise do %> - <% [workout_item_map | _] = each_list %> - <% each_list = Enum.filter(each_list, fn each -> each.check_box == true end) %> -
- <%= length(each_list) %> โœ• <%= Fitness.Exercises.get_exercise!(workout_item_map.exercise_id).name %> (<%= Fitness.Exercises.get_exercise!(workout_item_map.exercise_id).body_part %>) -
- <% end %> -
+ <% [workout_item_map | _] = each_list %> + <% each_list = Enum.filter(each_list, fn each -> each.check_box == true end) %> +
+ + <%= length(each_list) %> โœ• <%= Fitness.Exercises.get_exercise!( + workout_item_map.exercise_id + ).name %> (<%= Fitness.Exercises.get_exercise!(workout_item_map.exercise_id).body_part %>) + +
<% end %>
- <% end %> - -
- + <% end %> +
+ <% end %> +
""" end diff --git a/lib/fitness_web/live/profile_live/score_board_live.ex b/lib/fitness_web/live/profile_live/score_board_live.ex index 2ab38dc..4a36bec 100644 --- a/lib/fitness_web/live/profile_live/score_board_live.ex +++ b/lib/fitness_web/live/profile_live/score_board_live.ex @@ -22,54 +22,97 @@ defmodule FitnessWeb.ScoreBoardLive do @impl true def render(assigns) do ~H""" -

Scoreboard

<% users_have_some_player_score = Enum.reject(@users, fn each -> each.player_score == 0 end) %> - <% user_by_order_score = Enum.sort_by(users_have_some_player_score, &-(&1.player_score)) %> + <% user_by_order_score = Enum.sort_by(users_have_some_player_score, &(-&1.player_score)) %> <% rank = Enum.with_index(user_by_order_score) %> <%= for {user, rank} <- rank do %>
- <%= if rank == 0 do %> -

#Rank <%= rank + 1 %>

- <% else %> - <%= if rank == 1 do %> -

#Rank <%= rank + 1 %>

- <% else %> - <%= if rank == 2 do %> -

#Rank <%= rank + 1 %>

- <% else %> -

#Rank <%= rank + 1 %>

- <% end %> - <% end %> - <% end %> + <%= if rank == 0 do %> +

+ #Rank <%= rank + 1 %> +

+ <% else %> + <%= if rank == 1 do %> +

+ #Rank <%= rank + 1 %> +

+ <% else %> + <%= if rank == 2 do %> +

+ #Rank <%= rank + 1 %> +

+ <% else %> +

#Rank <%= rank + 1 %>

+ <% end %> + <% end %> + <% end %>
-

<%= Calendar.strftime(user.updated_at, "%B %-d, %Y") %>

- <% user_workout_template = Enum.filter(@workout_templates, fn each -> each.user_id == user.id and each.is_finished == true end) %> - <%= length(user_workout_template) %> โœ• workout complete +

+ <%= Calendar.strftime(user.updated_at, "%B %-d, %Y") %> +

+ <% user_workout_template = + Enum.filter(@workout_templates, fn each -> + each.user_id == user.id and each.is_finished == true + end) %> + + <%= length(user_workout_template) %> โœ• workout complete +
- <%= if user.id == @user_id do %> -

Total Score:

-

<%= @player_score %>

+ <%= if user.id == @user_id do %> +

Total Score:

+

<%= @player_score %>

<% else %> -

Total Score:

-

<%= user.player_score %>

+

Total Score:

+

<%= user.player_score %>

<% end %>
<% end %>
- """ end diff --git a/lib/fitness_web/live/profile_live/update_user_profile_form.ex b/lib/fitness_web/live/profile_live/update_user_profile_form.ex index f86e356..6b14da0 100644 --- a/lib/fitness_web/live/profile_live/update_user_profile_form.ex +++ b/lib/fitness_web/live/profile_live/update_user_profile_form.ex @@ -18,40 +18,53 @@ defmodule FitnessWeb.ProfileLive.UpdateUserProfileForm do

Edit Profile

- <.form - :let={f} - for={:profile} - phx-target={@myself} - id="update_profile" - phx-change="update" - phx-submit="update_new_changes"> - - <%= for entry <- @uploads.user_image.entries do %> + <.form + :let={f} + for={:profile} + phx-target={@myself} + id="update_profile" + phx-change="update" + phx-submit="update_new_changes" + > + <%= for entry <- @uploads.user_image.entries do %>
- <.live_img_preview entry={entry} class="w-48 h-48 pb-4 rounded" /> -
- <% end %> -
- <%= label f, :name, class: "block text-gray-700 font-bold mb-2" %> - <%= text_input f, :name, class: "w-full font-poppins border rounded py-2 px-3 leading-tight focus:outline-none focus:shadow-outline", placeholder: "Edit name" %> + <.live_img_preview entry={entry} class="w-48 h-48 pb-4 rounded" />
-
+ <% end %> +
+ <%= label(f, :name, class: "block text-gray-700 font-bold mb-2") %> + <%= text_input(f, :name, + class: + "w-full font-poppins border rounded py-2 px-3 leading-tight focus:outline-none focus:shadow-outline", + placeholder: "Edit name" + ) %> +
+
-
- -
-
+ +
+ - <%= submit "Save", class: "bg-blue-500 hover:bg-blue-700 font-poppins text-white py-2 px-4 rounded focus:outline-none focus:shadow-outline", phx_disable_with: "Saving..." %> -
- -
- + <%= submit("Save", + class: + "bg-blue-500 hover:bg-blue-700 font-poppins text-white py-2 px-4 rounded focus:outline-none focus:shadow-outline", + phx_disable_with: "Saving..." + ) %> +
+ +
""" end diff --git a/lib/fitness_web/live/profile_live/user_profile_live.ex b/lib/fitness_web/live/profile_live/user_profile_live.ex index f60e802..50994a8 100644 --- a/lib/fitness_web/live/profile_live/user_profile_live.ex +++ b/lib/fitness_web/live/profile_live/user_profile_live.ex @@ -20,60 +20,122 @@ defmodule FitnessWeb.UserProfileLive do @impl true def render(assigns) do ~H""" -
- + + + + + + + + + +

Profile

- user profile pic + user profile pic
<%= if @kebab_menu == :off do %> - - <%= assigns[:current_user].name %> - + + <%= assigns[:current_user].name %> + + <% else %> - - <%= assigns[:current_user].name %> - - <.modal> - <.live_component id={assigns[:current_user].id} module={FitnessWeb.ProfileLive.UpdateUserProfileForm} current_user={assigns[:current_user]} /> - + + <%= assigns[:current_user].name %> + + + <.modal> + <.live_component + id={assigns[:current_user].id} + module={FitnessWeb.ProfileLive.UpdateUserProfileForm} + current_user={assigns[:current_user]} + /> + <% end %> - @<%= assigns[:current_user].username %> + @<%= assigns[:current_user].username %> - -
-
T
-
O
-
T
-
A
-
L
-
-
- <%= assigns[:current_user].player_score %> -
-
+ +
+
T
+
O
+
T
+
A
+
L
+
+
+ <%= assigns[:current_user].player_score %> +
+
+
+
+ Training Volume + Current Weight +
- - -
- Training Volume - Current Weight -
- -
- <% bar_data = Jason.encode!([["Total Sets", @chart_data.total_sets],["Total Reps", @chart_data.total_reps],["Total Weight", @chart_data.total_weight] ]) %> - <%= raw Chartkick.bar_chart bar_data, stacked: true, colors: ["#FF5733"] %> - - <% datetime_data = Jason.encode!(%{"2023-03-10 00:00:00 -0800": 45, "2023-06-10 00:00:00 -0800": 56, "2023-04-10 00:00:00 -0800": 54, "2023-09-10 00:00:00 -0200": 64, "2023-01-10 00:00:00 -0800": 84, "2023-07-10 00:00:00 -0800": 74, "2023-02-10 00:00:00 -0800": 64}) %> - <%= raw Chartkick.area_chart datetime_data, colors: ["#58D68D"] %> -
+
+ <% bar_data = + Jason.encode!([ + ["Total Sets", @chart_data.total_sets], + ["Total Reps", @chart_data.total_reps], + ["Total Weight", @chart_data.total_weight] + ]) %> + <%= raw(Chartkick.bar_chart(bar_data, stacked: true, colors: ["#FF5733"])) %> + <% datetime_data = + Jason.encode!(%{ + "2023-03-10 00:00:00 -0800": 45, + "2023-06-10 00:00:00 -0800": 56, + "2023-04-10 00:00:00 -0800": 54, + "2023-09-10 00:00:00 -0200": 64, + "2023-01-10 00:00:00 -0800": 84, + "2023-07-10 00:00:00 -0800": 74, + "2023-02-10 00:00:00 -0800": 64 + }) %> + <%= raw(Chartkick.area_chart(datetime_data, colors: ["#58D68D"])) %> +
""" end diff --git a/lib/fitness_web/live/workout_template_live/check_boxes_live_component.ex b/lib/fitness_web/live/workout_template_live/check_boxes_live_component.ex index 6c801a1..88f5dbd 100644 --- a/lib/fitness_web/live/workout_template_live/check_boxes_live_component.ex +++ b/lib/fitness_web/live/workout_template_live/check_boxes_live_component.ex @@ -17,77 +17,104 @@ defmodule FitnessWeb.WorkoutTemplateLive.CheckBoxesLiveComponent do def render(assigns) do ~H"""
+ <%= if @workout_template.workout_items != [] do %> +
+
+ <% list_of_same_exercise = + Enum.group_by(@workout_template.workout_items, fn each -> each.exercise_id end) + |> Map.values() %> - <%= if @workout_template.workout_items != [] do %> -
+ <%= for each_list <- list_of_same_exercise do %> + <% [workout_item_map | _] = each_list %> +
+ + + + + + + + + + + <%= for workout_item <- each_list do %> + <.form :let={f} for={@changeset} id={"created-workout-item-#{workout_item.id}"}> + + + + -
- <% list_of_same_exercise = Enum.group_by(@workout_template.workout_items, fn each -> each.exercise_id end) |> Map.values() %> +
- <%= for each_list <- list_of_same_exercise do %> - <% [workout_item_map | _] = each_list %> - + + + <% end %> + +
SetsRepsWeight
+ <%= workout_item.sets %> + + <%= workout_item.reps %> + + <%= workout_item.weight %> + + <%= workout_item.weight_unit %> + + <%= if @workout_start != :not_begin do %> + + <% else %> + + + + + + + + + + + <% end %> +
+
+ <% end %>
- - - - - - - - - - - <%= for workout_item <- each_list do%> - <.form - :let={f} - for={@changeset} - id={"created-workout-item-#{workout_item.id}"} - > - - - - - - - - - - - <% end %> - -
SetsRepsWeight
- <%= workout_item.sets %> - - <%= workout_item.reps %> - - <%= workout_item.weight %> - - <%= workout_item.weight_unit %> - - <%= if @workout_start != :not_begin do %> - - <% else %> - - <% end %> -
<% end %> -
-
- <% end %> - """ end end diff --git a/lib/fitness_web/live/workout_template_live/form_component.html.heex b/lib/fitness_web/live/workout_template_live/form_component.html.heex index 982c045..ce1d25a 100644 --- a/lib/fitness_web/live/workout_template_live/form_component.html.heex +++ b/lib/fitness_web/live/workout_template_live/form_component.html.heex @@ -1,21 +1,29 @@
-

<%= @title %>

+

<%= @title %>

- <.form - :let={f} - for={@changeset} - id="workout_template-form" - phx-target={@myself} - phx-change="validate" - phx-submit="save"> - -
- <%= submit "Save", class: "bg-blue-500 hover:bg-blue-700 font-poppins text-white py-2 px-4 rounded focus:outline-none focus:shadow-outline", phx_disable_with: "Saving..." %> -
-
- <%= label f, :name, class: "block text-gray-700 font-bold mb-2" %> - <%= text_input f, :name, class: "w-full font-poppins border rounded py-2 px-3 leading-tight focus:outline-none focus:shadow-outline", placeholder: "Enter workout name" %> - <%= error_tag f, :name %> -
- -
+ <.form + :let={f} + for={@changeset} + id="workout_template-form" + phx-target={@myself} + phx-change="validate" + phx-submit="save" + > +
+ <%= submit("Save", + class: + "bg-blue-500 hover:bg-blue-700 font-poppins text-white py-2 px-4 rounded focus:outline-none focus:shadow-outline", + phx_disable_with: "Saving..." + ) %> +
+
+ <%= label(f, :name, class: "block text-gray-700 font-bold mb-2") %> + <%= text_input(f, :name, + class: + "w-full font-poppins border rounded py-2 px-3 leading-tight focus:outline-none focus:shadow-outline", + placeholder: "Enter workout name" + ) %> + <%= error_tag(f, :name) %> +
+ + diff --git a/lib/fitness_web/live/workout_template_live/index.html.heex b/lib/fitness_web/live/workout_template_live/index.html.heex index 66bc552..268b2f8 100644 --- a/lib/fitness_web/live/workout_template_live/index.html.heex +++ b/lib/fitness_web/live/workout_template_live/index.html.heex @@ -1,58 +1,90 @@
-

Listing Workout templates

- -<%= if @live_action in [:new, :edit] do %> - <.modal return_to={Routes.workout_template_index_path(@socket, :index)}> - <.live_component - module={FitnessWeb.WorkoutTemplateLive.FormComponent} - id={@workout_template.id || :new} - user_id={@current_user.id} - title={@page_title} - action={@live_action} - workout_template={@workout_template} - return_to={Routes.workout_template_index_path(@socket, :index)} - /> - -<% end %> +

+ Listing Workout templates +

+ <%= if @live_action in [:new, :edit] do %> + <.modal return_to={Routes.workout_template_index_path(@socket, :index)}> + <.live_component + module={FitnessWeb.WorkoutTemplateLive.FormComponent} + id={@workout_template.id || :new} + user_id={@current_user.id} + title={@page_title} + action={@live_action} + workout_template={@workout_template} + return_to={Routes.workout_template_index_path(@socket, :index)} + /> + + <% end %>
- <.link patch={Routes.workout_template_index_path(@socket, :new)} class="bg-blue-500 font-poppins hover:bg-blue-600 text-white rounded-lg px-3 py-2" >New Workout + <.link + patch={Routes.workout_template_index_path(@socket, :new)} + class="bg-blue-500 font-poppins hover:bg-blue-600 text-white rounded-lg px-3 py-2" + > + New Workout +
- <%= if length(@workout_templates) >= 1 do %> - <% user_template_owner = Enum.filter(@workout_templates, fn each -> each.user_id == assigns[:current_user].id end) %> + <%= if length(@workout_templates) >= 1 do %> + <% user_template_owner = + Enum.filter(@workout_templates, fn each -> each.user_id == assigns[:current_user].id end) %> -
- <% workout_templates_list_is_finished_false = Enum.reject(user_template_owner, fn each -> each.is_finished == true end) %> +
+ <% workout_templates_list_is_finished_false = + Enum.reject(user_template_owner, fn each -> each.is_finished == true end) %> <%= for workout_template <- Enum.reverse(workout_templates_list_is_finished_false) do %> -
- +
- No pain, no gain + No pain, no gain
<%= if assigns[:current_user] do %> - - <% end %> -
-
- - <.link navigate={Routes.workout_template_show_path(@socket, :show, workout_template)} class="bg-blue-500 hover:bg-blue-600 text-white rounded-lg font-poppins px-4 py-2 mr-2 ">Show - <%= if assigns[:current_user] do %> - <.link patch={Routes.workout_template_index_path(@socket, :edit, workout_template)} class="text-orange-400 font-poppins text-xl hover:underline">Edit +
-
+ + <% end %> +
+
+ + <.link + navigate={Routes.workout_template_show_path(@socket, :show, workout_template)} + class="bg-blue-500 hover:bg-blue-600 text-white rounded-lg font-poppins px-4 py-2 mr-2 " + > + Show + + + <%= if assigns[:current_user] do %> + + <.link + patch={Routes.workout_template_index_path(@socket, :edit, workout_template)} + class="text-orange-400 font-poppins text-xl hover:underline" + > + Edit + + <% end %>
- <% end %> +
+ <% end %>
+ <% end %> +
diff --git a/lib/fitness_web/live/workout_template_live/show.html.heex b/lib/fitness_web/live/workout_template_live/show.html.heex index fe2c6c6..baa8ba8 100644 --- a/lib/fitness_web/live/workout_template_live/show.html.heex +++ b/lib/fitness_web/live/workout_template_live/show.html.heex @@ -1,119 +1,200 @@
+

+ <%= String.upcase(@workout_template.name) %> +

-

<%= String.upcase(@workout_template.name) %>

- -
- <%= if length(@workout_template.workout_items) >= 6 do %> - - - - - Start Workout - - - <% else %> +
+ <%= if length(@workout_template.workout_items) >= 6 do %> + + + + + + + + + Start Workout + + + + <% else %> + <% end %> + + + +
+ <%= if @workout_template.workout_items == [] do %> +
+ <%= if assigns[:current_user] do %> + + + <% end %> - -
- <%= if @workout_template.workout_items == [] do %> -
- <%= if assigns[:current_user] do %> - - <% end %> -
-<% end %> +
+ <% end %> - <%= if @live_action in [:edit] do %> - <.modal return_to={Routes.workout_template_show_path(@socket, :show, @workout_template)}> + <%= if @live_action in [:edit] do %> + <.modal return_to={Routes.workout_template_show_path(@socket, :show, @workout_template)}> <.live_component - module={FitnessWeb.WorkoutTemplateLive.WorkoutItemForm} - id={@workout_template.id} - title={@page_title} - action={@live_action} - workout_template={@workout_template} - return_to={Routes.workout_template_show_path(@socket, :show, @workout_template)} + module={FitnessWeb.WorkoutTemplateLive.WorkoutItemForm} + id={@workout_template.id} + title={@page_title} + action={@live_action} + workout_template={@workout_template} + return_to={Routes.workout_template_show_path(@socket, :show, @workout_template)} /> - - <% end %> - - <%= if @workout_template.workout_items != [] do %> - + + <% end %> + <%= if @workout_template.workout_items != [] do %> +
+ <% list_of_same_exercise = + Enum.group_by(@workout_template.workout_items, fn each -> each.exercise_id end) + |> Map.values() %> -
- <% list_of_same_exercise = Enum.group_by(@workout_template.workout_items, fn each -> each.exercise_id end) |> Map.values() %> - - <%= for each_list <- list_of_same_exercise do %> - <% [workout_item_map | _] = each_list %> -
- - - - - - - - - - <% last_workout_item = Enum.at(each_list, -1) %> - <%= for workout_item <- each_list do%> - <.form - :let={f} - for={@changeset} - id={"created-workout-item-#{workout_item.id}"} - phx-change="workout-update"> - - - - - - - - - - + <%= for each_list <- list_of_same_exercise do %> + <% [workout_item_map | _] = each_list %> +
SetsRepsWeight
- <%= hidden_input f, :sets, disabled: false, value: workout_item.sets %> - <%= hidden_input f, :workout_template_id, disabled: false, value: workout_item.workout_template_id %> - <%= workout_item.sets %> - - <%= hidden_input f, :exercise_id, disabled: false, value: workout_item.exercise_id %> - <%= number_input f, :reps, disabled: false, value: workout_item.reps, class: "form-input font-poppins rounded-md shadow-sm mt-1 block w-full" %> - <%= error_tag f, :reps %> - - <%= hidden_input f, :id, value: workout_item.id %> - <%= number_input f, :weight, step: "any", value: workout_item.weight, class: "form-input font-poppins rounded-md shadow-sm mt-1 block w-full" %> - <%= error_tag f, :weight %> - - <%= hidden_input f, :weight_unit, disabled: false, value: workout_item.weight_unit %> - <%= workout_item.weight_unit %> - - -
+ + + + + + + + <% last_workout_item = Enum.at(each_list, -1) %> + <%= for workout_item <- each_list do %> + <.form + :let={f} + for={@changeset} + id={"created-workout-item-#{workout_item.id}"} + phx-change="workout-update" + > + + + + + + + + + + + <% end %> +
SetsRepsWeight
+ <%= hidden_input(f, :sets, disabled: false, value: workout_item.sets) %> + <%= hidden_input(f, :workout_template_id, + disabled: false, + value: workout_item.workout_template_id + ) %> + <%= workout_item.sets %> + + <%= hidden_input(f, :exercise_id, + disabled: false, + value: workout_item.exercise_id + ) %> + <%= number_input(f, :reps, + disabled: false, + value: workout_item.reps, + class: "form-input font-poppins rounded-md shadow-sm mt-1 block w-full" + ) %> + <%= error_tag(f, :reps) %> + + <%= hidden_input(f, :id, value: workout_item.id) %> + <%= number_input(f, :weight, + step: "any", + value: workout_item.weight, + class: "form-input font-poppins rounded-md shadow-sm mt-1 block w-full" + ) %> + <%= error_tag(f, :weight) %> + + <%= hidden_input(f, :weight_unit, + disabled: false, + value: workout_item.weight_unit + ) %> + <%= workout_item.weight_unit %> + + +
+
+ +
+
<% end %> - -
- -
-
- <% end %> -
- <% end %> +
+ <% end %> -<%= if @workout_template.workout_items != [] do %> -
- <%= if assigns[:current_user] do %> - - <% end %> -
-<% end %> + <%= if @workout_template.workout_items != [] do %> +
+ <%= if assigns[:current_user] do %> + + + + <% end %> +
+ <% end %> diff --git a/lib/fitness_web/live/workout_template_live/workout_item_form.ex b/lib/fitness_web/live/workout_template_live/workout_item_form.ex index b24ddd4..36cb19c 100644 --- a/lib/fitness_web/live/workout_template_live/workout_item_form.ex +++ b/lib/fitness_web/live/workout_template_live/workout_item_form.ex @@ -27,10 +27,10 @@ defmodule FitnessWeb.WorkoutTemplateLive.WorkoutItemForm do @impl true def render(assigns) do ~H""" - -
-

Add New Exercises

+

+ Add New Exercises +

<.form :let={f} @@ -38,42 +38,75 @@ defmodule FitnessWeb.WorkoutTemplateLive.WorkoutItemForm do id="new-workout-item" phx-target={@myself} phx-change="updated_workout-item" - phx-submit="add_new_exercise"> - - + phx-submit="add_new_exercise" + >
- - <%= select f, :exercise_id, Enum.map(@exercises, fn exercise -> {exercise.name, exercise.id} end), value: @exercise_id, prompt: "Select an exercise", class: "form-select font-poppins block w-full rounded-md shadow-sm py-2 px-3 text-gray-700 bg-white focus:outline-none focus:ring focus:ring-blue-200 focus:border-blue-500 sm:text-sm" %> - <%= error_tag f, :exercise_id %> + + <%= select( + f, + :exercise_id, + Enum.map(@exercises, fn exercise -> {exercise.name, exercise.id} end), + value: @exercise_id, + prompt: "Select an exercise", + class: + "form-select font-poppins block w-full rounded-md shadow-sm py-2 px-3 text-gray-700 bg-white focus:outline-none focus:ring focus:ring-blue-200 focus:border-blue-500 sm:text-sm" + ) %> + <%= error_tag(f, :exercise_id) %>
-
- - <%= number_input f, :sets, value: @sets_number, disabled: true, class: "form-input font-poppins rounded-md shadow-sm mt-1 block w-full" %> - <%= error_tag f, :sets %> -
- -
- - <%= number_input f, :reps, value: @current_reps, disabled: false, class: "form-input font-poppins rounded-md shadow-sm mt-1 block w-full" %> - <%= error_tag f, :reps %> -
+
+ + <%= number_input(f, :sets, + value: @sets_number, + disabled: true, + class: "form-input font-poppins rounded-md shadow-sm mt-1 block w-full" + ) %> + <%= error_tag(f, :sets) %> +
-
- -
- <%= number_input f, :weight, value: @current_weight, step: "any", class: "form-input font-poppins rounded-md shadow-sm mt-1 block w-full" %> - <%= error_tag f, :weight %> - <%= select f, :weight_unit, ["kg", "lbs"], class: "form-select ml-2 rounded-md shadow-sm py-0 px-6 font-poppins text-gray-700 bg-white focus:outline-none focus:ring focus:ring-blue-200 focus:border-blue-500 sm:text-sm" %> +
+ + <%= number_input(f, :reps, + value: @current_reps, + disabled: false, + class: "form-input font-poppins rounded-md shadow-sm mt-1 block w-full" + ) %> + <%= error_tag(f, :reps) %>
+ +
+ +
+ <%= number_input(f, :weight, + value: @current_weight, + step: "any", + class: "form-input font-poppins rounded-md shadow-sm mt-1 block w-full" + ) %> + <%= error_tag(f, :weight) %> + <%= select(f, :weight_unit, ["kg", "lbs"], + class: + "form-select ml-2 rounded-md shadow-sm py-0 px-6 font-poppins text-gray-700 bg-white focus:outline-none focus:ring focus:ring-blue-200 focus:border-blue-500 sm:text-sm" + ) %> +
- <%= submit "ADD EXERCISE", phx_disable_with: "Adding...", class: "bg-green-400 hover:bg-green-600 text-white font-poppins py-2 px-4 rounded" %> + <%= submit("ADD EXERCISE", + phx_disable_with: "Adding...", + class: "bg-green-400 hover:bg-green-600 text-white font-poppins py-2 px-4 rounded" + ) %>
diff --git a/lib/fitness_web/live/workout_template_live/workout_zone.ex b/lib/fitness_web/live/workout_template_live/workout_zone.ex index 7301378..a9549a9 100644 --- a/lib/fitness_web/live/workout_template_live/workout_zone.ex +++ b/lib/fitness_web/live/workout_template_live/workout_zone.ex @@ -30,75 +30,108 @@ defmodule FitnessWeb.WorkoutTemplateLive.WorkoutZone do @impl true def render(assigns) do ~H""" - -

<%= String.upcase(@workout_template.name) %>

- - <%= if @workout_template.workout_items != [] do %> -
-
-

<%= @time |> Time.truncate(:second) |> Time.to_string() %>

-
-
- <% end %> - -
- <%= if @workout_template.workout_items != [] do %> - <%= if @timer_status != :running do %> - - - - - - - Start Workout - - <% else %> -
-

๐Ÿ’ช

- -
- <% end %> - <% else %> - - <% end %> - - <%= if @timer_status != :running do %> -
- +

+ <%= String.upcase(@workout_template.name) %> +

+ + <%= if @workout_template.workout_items != [] do %> +
+
+

+ <%= @time |> Time.truncate(:second) |> Time.to_string() %> +

+
+
+ <% end %> + +
+ <%= if @workout_template.workout_items != [] do %> + <%= if @timer_status != :running do %> + + - <.link navigate={Routes.workout_template_show_path(@socket, :show, @workout_template)}>Edit -
- <% else %> -
- + <% else %> +
+

+ ๐Ÿ’ช +

+ - -
- <% end %> -
- -
- <.live_component module={CheckBoxesLiveComponent} id={"check-boxes"} timer_status={@timer_status} workout_start={@workout_start} changeset={@changeset} workout_template={@workout_template} /> -
- - <%= if @timer_status == :running do %> -
- <% %> - <%= if @check_complete_checkbox_list != [] do %> - - - <% end %>
- <% end %> + <% end %> + <% else %> + + <% end %> + + <%= if @timer_status != :running do %> +
+ + + <.link navigate={Routes.workout_template_show_path(@socket, :show, @workout_template)}> + Edit + + +
+ <% else %> +
+ + +
+ <% end %> +
+ +
+ <.live_component + module={CheckBoxesLiveComponent} + id="check-boxes" + timer_status={@timer_status} + workout_start={@workout_start} + changeset={@changeset} + workout_template={@workout_template} + /> +
+ + <%= if @timer_status == :running do %> +
+ <% %> + <%= if @check_complete_checkbox_list != [] do %> + + + <% end %> +
+ <% end %> """ end diff --git a/lib/fitness_web/templates/layout/_user_menu.html.heex b/lib/fitness_web/templates/layout/_user_menu.html.heex index e8b0e06..ce68b33 100644 --- a/lib/fitness_web/templates/layout/_user_menu.html.heex +++ b/lib/fitness_web/templates/layout/_user_menu.html.heex @@ -1,10 +1,14 @@
    -<%= if @current_user do %> - - - -<% else %> - - -<% end %> + <%= if @current_user do %> + + + + <% else %> + + + <% end %>
diff --git a/lib/fitness_web/templates/layout/app.html.heex b/lib/fitness_web/templates/layout/app.html.heex index 600c3ed..a6153d0 100644 --- a/lib/fitness_web/templates/layout/app.html.heex +++ b/lib/fitness_web/templates/layout/app.html.heex @@ -1,5 +1,9 @@
- - + + <%= @inner_content %>
diff --git a/lib/fitness_web/templates/layout/live.html.heex b/lib/fitness_web/templates/layout/live.html.heex index 883ff17..78a3699 100644 --- a/lib/fitness_web/templates/layout/live.html.heex +++ b/lib/fitness_web/templates/layout/live.html.heex @@ -1,19 +1,39 @@
- + phx-value-key="info" + > + <%= live_flash(@flash, :info) %> +

- + phx-value-key="error" + > + <%= live_flash(@flash, :error) %> +

- + phx-value-key="info" + > + <%= live_flash(@flash, :bonus) %> +

- + phx-value-key="error" + > + <%= live_flash(@flash, :loss) %> +

<%= @inner_content %> -
\ No newline at end of file + diff --git a/lib/fitness_web/templates/layout/root.html.heex b/lib/fitness_web/templates/layout/root.html.heex index 9015334..ed8ebfc 100644 --- a/lib/fitness_web/templates/layout/root.html.heex +++ b/lib/fitness_web/templates/layout/root.html.heex @@ -1,45 +1,177 @@ - - - - - <.live_title > + + + + + <.live_title> <%= assigns[:page_title] || "Fitness" %> - - - - + + + +
-
+ + <%= render("_user_menu.html", assigns) %> <%= @inner_content %> diff --git a/lib/fitness_web/templates/page/index.html.heex b/lib/fitness_web/templates/page/index.html.heex index 5359b98..04d755f 100644 --- a/lib/fitness_web/templates/page/index.html.heex +++ b/lib/fitness_web/templates/page/index.html.heex @@ -1,53 +1,116 @@ Welcome to Muscle Mind - - + +
-

Welcome to the Muscle Mind web application

-

Get fit, stay healthy, and achieve your goals with our app

+

+ Welcome to the Muscle Mind web application +

+

+ Get fit, stay healthy, and achieve your goals with our app +

<%= if assigns[:current_user] do %> - + <% else %> -
- - - - - - - - - - - - - - - - - - - - -
-
-
-
-
-
+
+ + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+
-
-

Already have an account? Log in

+

+ Already have an account? + Log in +

<% end %>
- \ No newline at end of file + diff --git a/lib/fitness_web/templates/user_confirmation/edit.html.heex b/lib/fitness_web/templates/user_confirmation/edit.html.heex index 593d10c..32199d4 100644 --- a/lib/fitness_web/templates/user_confirmation/edit.html.heex +++ b/lib/fitness_web/templates/user_confirmation/edit.html.heex @@ -1,12 +1,18 @@

Confirm account

-<.form :let={_f} for={%{}} as={:user} action={Routes.user_confirmation_path(@conn, :update, @token)}> +<.form + :let={_f} + for={%{}} + as={:user} + action={Routes.user_confirmation_path(@conn, :update, @token)} +>
- <%= submit "Confirm my account" %> + <%= submit("Confirm my account") %>

- <%= link "Register", to: Routes.user_registration_path(@conn, :new) %> | - <%= link "Log in", to: Routes.user_session_path(@conn, :new) %> + <%= link("Register", to: Routes.user_registration_path(@conn, :new)) %> | <%= link("Log in", + to: Routes.user_session_path(@conn, :new) + ) %>

diff --git a/lib/fitness_web/templates/user_confirmation/new.html.heex b/lib/fitness_web/templates/user_confirmation/new.html.heex index e9582cb..5cfec84 100644 --- a/lib/fitness_web/templates/user_confirmation/new.html.heex +++ b/lib/fitness_web/templates/user_confirmation/new.html.heex @@ -1,15 +1,16 @@

Resend confirmation instructions

<.form :let={f} for={%{}} as={:user} action={Routes.user_confirmation_path(@conn, :create)}> - <%= label f, :email %> - <%= email_input f, :email, required: true %> + <%= label(f, :email) %> + <%= email_input(f, :email, required: true) %>
- <%= submit "Resend confirmation instructions" %> + <%= submit("Resend confirmation instructions") %>

- <%= link "Register", to: Routes.user_registration_path(@conn, :new) %> | - <%= link "Log in", to: Routes.user_session_path(@conn, :new) %> + <%= link("Register", to: Routes.user_registration_path(@conn, :new)) %> | <%= link("Log in", + to: Routes.user_session_path(@conn, :new) + ) %>

diff --git a/lib/fitness_web/templates/user_registration/new.html.heex b/lib/fitness_web/templates/user_registration/new.html.heex index 4ff0c63..4e03bd4 100644 --- a/lib/fitness_web/templates/user_registration/new.html.heex +++ b/lib/fitness_web/templates/user_registration/new.html.heex @@ -1,49 +1,73 @@
-
-

Register

+
+

Register

+ <.form + :let={f} + for={@changeset} + action={Routes.user_registration_path(@conn, :create)} + class="max-w-md mx-auto" + > + <%= if @changeset.action do %> +
+

Oops, something went wrong! Please check the errors below.

+
+ <% end %> -<.form :let={f} for={@changeset} action={Routes.user_registration_path(@conn, :create)} class="max-w-md mx-auto"> - <%= if @changeset.action do %> -
-

Oops, something went wrong! Please check the errors below.

-
- <% end %> +
+ <%= label(f, :email, class: "block font-poppins font-medium text-sm text-gray-700") %> + <%= email_input(f, :email, + required: true, + class: + "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" + ) %> + <%= error_tag(f, :email) %> +
+
+ <%= label(f, :full_name, class: "block font-poppins font-medium text-sm text-gray-700") %> + <%= text_input(f, :name, + required: true, + class: + "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" + ) %> + <%= error_tag(f, :name) %> +
-
- <%= label f, :email, class: "block font-poppins font-medium text-sm text-gray-700" %> - <%= email_input f, :email, required: true, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" %> - <%= error_tag f, :email %> -
+
+ <%= label(f, :username, class: "block font-poppins font-medium text-sm text-gray-700") %> + <%= text_input(f, :username, + required: true, + class: + "mt-1 font-poppins block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" + ) %> + <%= error_tag(f, :username) %> +
-
- <%= label f, :full_name, class: "block font-poppins font-medium text-sm text-gray-700" %> - <%= text_input f, :name, required: true, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" %> - <%= error_tag f, :name %> -
- -
- <%= label f, :username, class: "block font-poppins font-medium text-sm text-gray-700" %> - <%= text_input f, :username, required: true, class: "mt-1 font-poppins block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" %> - <%= error_tag f, :username %> -
+
+ <%= label(f, :password, class: "block font-poppins font-medium text-sm text-gray-700") %> + <%= password_input(f, :password, + required: true, + class: + "mt-1 font-poppins block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" + ) %> + <%= error_tag(f, :password) %> +
-
- <%= label f, :password, class: "block font-poppins font-medium text-sm text-gray-700" %> - <%= password_input f, :password, required: true, class: "mt-1 font-poppins block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" %> - <%= error_tag f, :password %> + + +
+

+ Already have an account? <%= link("Log in", + to: Routes.user_session_path(@conn, :new), + class: "font-bold text-blue-500 hover:text-blue-700" + ) %>
+

+
- - - -
-

- Already have an account? - <%= link "Log in", to: Routes.user_session_path(@conn, :new), class: "font-bold text-blue-500 hover:text-blue-700" %>
-

-
-
diff --git a/lib/fitness_web/templates/user_reset_password/edit.html.heex b/lib/fitness_web/templates/user_reset_password/edit.html.heex index f1c0751..60e2ebc 100644 --- a/lib/fitness_web/templates/user_reset_password/edit.html.heex +++ b/lib/fitness_web/templates/user_reset_password/edit.html.heex @@ -1,37 +1,63 @@

Reset password

- <.form class="bg-white font-poppins shadow-md rounded px-8 pt-6 pb-8 mb-4" :let={f} for={@changeset} action={Routes.user_reset_password_path(@conn, :update, @token)}> + <.form + :let={f} + class="bg-white font-poppins shadow-md rounded px-8 pt-6 pb-8 mb-4" + for={@changeset} + action={Routes.user_reset_password_path(@conn, :update, @token)} + > <%= if @changeset.action do %>
-

Oops, something went wrong! Please check the errors below.

+

+ Oops, something went wrong! Please check the errors below. +

<% end %>
- <%= label f, :password, class: "block font-poppins text-gray-700 font-bold mb-2" %> - <%= password_input f, :password, class: "shadow font-poppins appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline", required: true %> - <%= error_tag f, :password %> + <%= label(f, :password, class: "block font-poppins text-gray-700 font-bold mb-2") %> + <%= password_input(f, :password, + class: + "shadow font-poppins appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline", + required: true + ) %> + <%= error_tag(f, :password) %>
- <%= label f, :password_confirmation, class: "block font-poppins text-gray-700 font-bold mb-2" %> - <%= password_input f, :password_confirmation, class: " font-poppins shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline", required: true %> - <%= error_tag f, :password_confirmation %> + <%= label(f, :password_confirmation, + class: "block font-poppins text-gray-700 font-bold mb-2" + ) %> + <%= password_input(f, :password_confirmation, + class: + " font-poppins shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline", + required: true + ) %> + <%= error_tag(f, :password_confirmation) %>
- <%= submit "Reset password", class: "bg-blue-500 font-poppins hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline" %> + <%= submit("Reset password", + class: + "bg-blue-500 font-poppins hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline" + ) %>

- Don't have an account? <%= link "Sign up", to: Routes.user_registration_path(@conn, :new), class: "font-medium font-poppins text-blue-500 hover:text-blue-600" %> + Don't have an account? <%= link("Sign up", + to: Routes.user_registration_path(@conn, :new), + class: "font-medium font-poppins text-blue-500 hover:text-blue-600" + ) %>

-

- Forgot your password? <%= link "Reset it", to: Routes.user_reset_password_path(@conn, :new), class: "font-medium font-poppins text-blue-500 hover:text-blue-600" %> -

+

+ Forgot your password? <%= link("Reset it", + to: Routes.user_reset_password_path(@conn, :new), + class: "font-medium font-poppins text-blue-500 hover:text-blue-600" + ) %> +

diff --git a/lib/fitness_web/templates/user_reset_password/new.html.heex b/lib/fitness_web/templates/user_reset_password/new.html.heex index 93735f0..6c01961 100644 --- a/lib/fitness_web/templates/user_reset_password/new.html.heex +++ b/lib/fitness_web/templates/user_reset_password/new.html.heex @@ -2,24 +2,41 @@

Forgot your password?

- <.form :let={f} for={%{}} as={:user} action={Routes.user_reset_password_path(@conn, :create)} class="bg-white font-poppins rounded px-8 pt-6 pb-8 mb-4"> + <.form + :let={f} + for={%{}} + as={:user} + action={Routes.user_reset_password_path(@conn, :create)} + class="bg-white font-poppins rounded px-8 pt-6 pb-8 mb-4" + >
- <%= label f, :email, class: "font-semibold font-poppins" %> - <%= email_input f, :email, required: true, class: "shadow font-poppins appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" %> + <%= label(f, :email, class: "font-semibold font-poppins") %> + <%= email_input(f, :email, + required: true, + class: + "shadow font-poppins appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" + ) %>
-
- <%= submit "Send instructions to reset password", class: "max-w-md font-poppins px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-gradient-to-r from-purple-400 to-pink-600 hover:from-purple-500 hover:to-pink-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" %> + <%= submit("Send instructions to reset password", + class: + "max-w-md font-poppins px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-gradient-to-r from-purple-400 to-pink-600 hover:from-purple-500 hover:to-pink-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" + ) %>

- Already have an account? - <%= link "Log in", to: Routes.user_session_path(@conn, :new), class: "font-medium font-poppins font-poppins text-blue-500 hover:text-blue-600" %>
+ Already have an account? <%= link("Log in", + to: Routes.user_session_path(@conn, :new), + class: "font-medium font-poppins font-poppins text-blue-500 hover:text-blue-600" + ) %>

- Don't have an account? <%= link "Sign up", to: Routes.user_registration_path(@conn, :new), class: "font-medium font-poppins font-poppins text-blue-500 hover:text-blue-600" %> + Don't have an account? <%= link("Sign up", + to: Routes.user_registration_path(@conn, :new), + class: "font-medium font-poppins font-poppins text-blue-500 hover:text-blue-600" + ) %>

diff --git a/lib/fitness_web/templates/user_session/new.html.heex b/lib/fitness_web/templates/user_session/new.html.heex index 5c8b671..e38440c 100644 --- a/lib/fitness_web/templates/user_session/new.html.heex +++ b/lib/fitness_web/templates/user_session/new.html.heex @@ -1,37 +1,64 @@ -

Log in

- <.form :let={f} for={@conn} action={Routes.user_session_path(@conn, :create)} as={:user} class="space-y-4"> + <.form + :let={f} + for={@conn} + action={Routes.user_session_path(@conn, :create)} + as={:user} + class="space-y-4" + > <%= if @error_message do %>

<%= @error_message %>

<% end %>
- <%= label f, :email, class: "block font-poppins font-medium text-sm text-gray-700" %> - <%= email_input f, :email, required: true, class: "mt-1 font-poppins block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" %> + <%= label(f, :email, class: "block font-poppins font-medium text-sm text-gray-700") %> + <%= email_input(f, :email, + required: true, + class: + "mt-1 font-poppins block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" + ) %>
- <%= label f, :password, class: "block font-poppins font-medium text-sm text-gray-700" %> - <%= password_input f, :password, required: true, class: "mt-1 font-poppins block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" %> + <%= label(f, :password, class: "block font-poppins font-medium text-sm text-gray-700") %> + <%= password_input(f, :password, + required: true, + class: + "mt-1 font-poppins block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" + ) %>
- <%= checkbox f, :remember_me, class: "rounded font-poppins border-gray-300 text-indigo-600 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 h-4 w-4 mr-2" %> - <%= label f, :remember_me, "Remember me", class: "font-medium font-poppins text-sm text-gray-700" %> + <%= checkbox(f, :remember_me, + class: + "rounded font-poppins border-gray-300 text-indigo-600 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 h-4 w-4 mr-2" + ) %> + <%= label(f, :remember_me, "Remember me", + class: "font-medium font-poppins text-sm text-gray-700" + ) %>
- <%= submit "Log in", class: "w-full font-poppins px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-gradient-to-r from-purple-400 to-pink-600 hover:from-purple-500 hover:to-pink-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" %> + <%= submit("Log in", + class: + "w-full font-poppins px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-gradient-to-r from-purple-400 to-pink-600 hover:from-purple-500 hover:to-pink-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" + ) %>

- Don't have an account? <%= link "Sign up", to: Routes.user_registration_path(@conn, :new), class: "font-medium font-poppins text-blue-500 hover:text-blue-600" %> + Don't have an account? <%= link("Sign up", + to: Routes.user_registration_path(@conn, :new), + class: "font-medium font-poppins text-blue-500 hover:text-blue-600" + ) %>

-

- Forgot your password? <%= link "Reset it", to: Routes.user_reset_password_path(@conn, :new), class: "font-medium font-poppins text-blue-500 hover:text-blue-600" %> -

+

+ Forgot your password? <%= link("Reset it", + to: Routes.user_reset_password_path(@conn, :new), + class: "font-medium font-poppins text-blue-500 hover:text-blue-600" + ) %> +

diff --git a/lib/fitness_web/templates/user_settings/edit.html.heex b/lib/fitness_web/templates/user_settings/edit.html.heex index 359fa35..f2adb3f 100644 --- a/lib/fitness_web/templates/user_settings/edit.html.heex +++ b/lib/fitness_web/templates/user_settings/edit.html.heex @@ -1,72 +1,114 @@ +
+
+

# Change email

-
- -
- -

# Change email

- - <.form :let={f} for={@email_changeset} action={Routes.user_settings_path(@conn, :update)} id="update_email"> + <.form + :let={f} + for={@email_changeset} + action={Routes.user_settings_path(@conn, :update)} + id="update_email" + > <%= if @email_changeset.action do %> -
-

Oops, something went wrong! Please check the errors below.

-
+
+

Oops, something went wrong! Please check the errors below.

+
<% end %> - <%= hidden_input f, :action, name: "action", value: "update_email" %> + <%= hidden_input(f, :action, name: "action", value: "update_email") %>
- <%= label f, :email, class: "text-sm font-poppins font-medium" %> - <%= email_input f, :email, required: true, class: "form-input rounded-md font-poppins shadow-sm block w-full" %> - <%= error_tag f, :email %> + <%= label(f, :email, class: "text-sm font-poppins font-medium") %> + <%= email_input(f, :email, + required: true, + class: "form-input rounded-md font-poppins shadow-sm block w-full" + ) %> + <%= error_tag(f, :email) %>
- <%= label f, :current_password, for: "current_password_for_email", class: "text-sm font-poppins font-medium" %> - <%= password_input f, :current_password, required: true, name: "current_password", placeholder: "********", id: "current_password_for_email", class: "form-input font-poppins rounded-md shadow-sm block w-full" %> - <%= error_tag f, :current_password %> + <%= label(f, :current_password, + for: "current_password_for_email", + class: "text-sm font-poppins font-medium" + ) %> + <%= password_input(f, :current_password, + required: true, + name: "current_password", + placeholder: "********", + id: "current_password_for_email", + class: "form-input font-poppins rounded-md shadow-sm block w-full" + ) %> + <%= error_tag(f, :current_password) %>
-
- <%= submit "Change email", class: "w-full font-poppins px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-gradient-to-r from-purple-400 to-pink-600 hover:from-purple-500 hover:to-pink-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" %> -
- -
+
+ <%= submit("Change email", + class: + "w-full font-poppins px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-gradient-to-r from-purple-400 to-pink-600 hover:from-purple-500 hover:to-pink-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" + ) %> +
+ +
-
+
+

# Change password

+ <.form + :let={f} + for={@password_changeset} + action={Routes.user_settings_path(@conn, :update)} + id="update_password" + > + <%= if @password_changeset.action do %> +
+

Oops, something went wrong! Please check the errors below.

+
+ <% end %> -

# Change password

- - <.form :let={f} for={@password_changeset} action={Routes.user_settings_path(@conn, :update)} id="update_password"> - <%= if @password_changeset.action do %> -
-

Oops, something went wrong! Please check the errors below.

-
- <% end %> - - <%= hidden_input f, :action, name: "action", value: "update_password" %> -
- <%= label f, :password, "New password", class: "text-sm font-poppins font-medium" %> - <%= password_input f, :password, required: true, placeholder: "********", class: "form-input font-poppins rounded-md shadow-sm block w-full" %> - <%= error_tag f, :password %> -
+ <%= hidden_input(f, :action, name: "action", value: "update_password") %> +
+ <%= label(f, :password, "New password", class: "text-sm font-poppins font-medium") %> + <%= password_input(f, :password, + required: true, + placeholder: "********", + class: "form-input font-poppins rounded-md shadow-sm block w-full" + ) %> + <%= error_tag(f, :password) %> +
-
- <%= label f, :password_confirmation, "Confirm new password", class: "text-sm font-poppins font-medium" %> - <%= password_input f, :password_confirmation, required: true, placeholder: "********", class: "form-input font-poppins rounded-md shadow-sm block w-full" %> - <%= error_tag f, :password_confirmation %> -
+
+ <%= label(f, :password_confirmation, "Confirm new password", + class: "text-sm font-poppins font-medium" + ) %> + <%= password_input(f, :password_confirmation, + required: true, + placeholder: "********", + class: "form-input font-poppins rounded-md shadow-sm block w-full" + ) %> + <%= error_tag(f, :password_confirmation) %> +
-
- <%= label f, :current_password, for: "current_password_for_password", class: "text-sm font-poppins font-medium" %> - <%= password_input f, :current_password, required: true, placeholder: "********", class: "form-input font-poppins font-poppins rounded-md shadow-sm block w-full", name: "current_password", id: "current_password_for_password" %> - <%= error_tag f, :current_password %> -
+
+ <%= label(f, :current_password, + for: "current_password_for_password", + class: "text-sm font-poppins font-medium" + ) %> + <%= password_input(f, :current_password, + required: true, + placeholder: "********", + class: "form-input font-poppins font-poppins rounded-md shadow-sm block w-full", + name: "current_password", + id: "current_password_for_password" + ) %> + <%= error_tag(f, :current_password) %> +
-
- <%= submit "Change password", class: "w-full font-poppins px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-gradient-to-r from-purple-400 to-pink-600 hover:from-purple-500 hover:to-pink-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" %> -
- -
+
+ <%= submit("Change password", + class: + "w-full font-poppins px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-gradient-to-r from-purple-400 to-pink-600 hover:from-purple-500 hover:to-pink-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" + ) %> +
+ +
diff --git a/mix.exs b/mix.exs index b9d42da..0e13fee 100644 --- a/mix.exs +++ b/mix.exs @@ -34,7 +34,8 @@ defmodule Fitness.MixProject do defp deps do [ {:bcrypt_elixir, "~> 3.0"}, - {:phoenix, "~> 1.6.15"}, + {:phoenix, "~> 1.7.0"}, + {:phoenix_view, "~> 2.0"}, {:phoenix_ecto, "~> 4.4"}, {:ecto_sql, "~> 3.6"}, {:postgrex, ">= 0.0.0"}, diff --git a/mix.lock b/mix.lock index bd3b058..c715225 100644 --- a/mix.lock +++ b/mix.lock @@ -26,7 +26,7 @@ "makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"}, "mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"}, "nimble_parsec": {:hex, :nimble_parsec, "1.3.0", "9e18a119d9efc3370a3ef2a937bf0b24c088d9c4bf0ba9d7c3751d49d347d035", [:mix], [], "hexpm", "7977f183127a7cbe9346981e2f480dc04c55ffddaef746bd58debd566070eef8"}, - "phoenix": {:hex, :phoenix, "1.6.16", "e5bdd18c7a06da5852a25c7befb72246de4ddc289182285f8685a40b7b5f5451", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0 or ~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e15989ff34f670a96b95ef6d1d25bad0d9c50df5df40b671d8f4a669e050ac39"}, + "phoenix": {:hex, :phoenix, "1.7.7", "4cc501d4d823015007ba3cdd9c41ecaaf2ffb619d6fb283199fa8ddba89191e0", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "8966e15c395e5e37591b6ed0bd2ae7f48e961f0f60ac4c733f9566b519453085"}, "phoenix_ecto": {:hex, :phoenix_ecto, "4.4.0", "0672ed4e4808b3fbed494dded89958e22fb882de47a97634c0b13e7b0b5f7720", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "09864e558ed31ee00bd48fcc1d4fc58ae9678c9e81649075431e69dbabb43cc1"}, "phoenix_html": {:hex, :phoenix_html, "3.3.2", "d6ce982c6d8247d2fc0defe625255c721fb8d5f1942c5ac051f6177bffa5973f", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "44adaf8e667c1c20fb9d284b6b0fa8dc7946ce29e81ce621860aa7e96de9a11d"}, "phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.8.1", "c4f2a2d3b26e6ca684d162ccf18aaeed8bed2181896e0393d0a2959789482e51", [:mix], [{:ecto, "~> 3.6.2 or ~> 3.7", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_mysql_extras, "~> 0.5", [hex: :ecto_mysql_extras, repo: "hexpm", optional: true]}, {:ecto_psql_extras, "~> 0.7", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:ecto_sqlite3_extras, "~> 1.1.7 or ~> 1.2.0", [hex: :ecto_sqlite3_extras, repo: "hexpm", optional: true]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.19.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6 or ~> 1.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "1ca0f954274ce1916f771f86b3d49a91d3447e7c32d171660676095c5f30abe9"}, @@ -46,4 +46,6 @@ "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"}, "telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"}, "telemetry_poller": {:hex, :telemetry_poller, "1.0.0", "db91bb424e07f2bb6e73926fcafbfcbcb295f0193e0a00e825e589a0a47e8453", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b3a24eafd66c3f42da30fc3ca7dda1e9d546c12250a2d60d7b81d264fbec4f6e"}, + "websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"}, + "websock_adapter": {:hex, :websock_adapter, "0.5.4", "7af8408e7ed9d56578539594d1ee7d8461e2dd5c3f57b0f2a5352d610ddde757", [:mix], [{:bandit, ">= 0.6.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "d2c238c79c52cbe223fcdae22ca0bb5007a735b9e933870e241fce66afb4f4ab"}, } diff --git a/test/fitness_web/live/exercise_live_test.exs b/test/fitness_web/live/exercise_live_test.exs index c8a1339..6c56061 100644 --- a/test/fitness_web/live/exercise_live_test.exs +++ b/test/fitness_web/live/exercise_live_test.exs @@ -91,7 +91,6 @@ defmodule FitnessWeb.ExerciseLiveTest do {:ok, index_live, _html} = live(conn, Routes.exercise_index_path(conn, :index)) - assert index_live |> element("#exercise-#{exercise.id} a", "Edit") |> render_click() =~ "Edit Exercise" diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 4843dcc..44caeee 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -28,6 +28,8 @@ defmodule FitnessWeb.ConnCase do # The default endpoint for testing @endpoint FitnessWeb.Endpoint + + use FitnessWeb, :verified_routes end end From 04645472aadd4c7eefc6c674488706e9e06bbdde Mon Sep 17 00:00:00 2001 From: 0xmohsinpathan <0xmohsinpathan@gmail.com> Date: Tue, 22 Aug 2023 12:23:00 +0530 Subject: [PATCH 4/4] fix bug: no longer show empty flash. all flash related test is fix. get_flash() it change to -> Phoenix.Flash.get() --- assets/css/app.css | 2 -- lib/fitness_web/templates/layout/app.html.heex | 6 +++--- lib/fitness_web/templates/layout/live.html.heex | 14 +++++--------- test/fitness_web/controllers/user_auth_test.exs | 2 +- .../user_confirmation_controller_test.exs | 14 +++++++------- .../user_reset_password_controller_test.exs | 10 +++++----- .../controllers/user_settings_controller_test.exs | 10 +++++----- 7 files changed, 26 insertions(+), 32 deletions(-) diff --git a/assets/css/app.css b/assets/css/app.css index 427b683..6b900c4 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -223,7 +223,6 @@ .alert { padding: 15px; - margin-bottom: 20px; border: 1px solid transparent; border-radius: 4px; } @@ -260,7 +259,6 @@ /* Alerts and form errors used by phx.new */ .alert { padding: 15px; - margin-bottom: 20px; border: 1px solid transparent; border-radius: 4px; } diff --git a/lib/fitness_web/templates/layout/app.html.heex b/lib/fitness_web/templates/layout/app.html.heex index a6153d0..4b84c00 100644 --- a/lib/fitness_web/templates/layout/app.html.heex +++ b/lib/fitness_web/templates/layout/app.html.heex @@ -1,9 +1,9 @@ -
+
<%= @inner_content %>
diff --git a/lib/fitness_web/templates/layout/live.html.heex b/lib/fitness_web/templates/layout/live.html.heex index 78a3699..a574cdd 100644 --- a/lib/fitness_web/templates/layout/live.html.heex +++ b/lib/fitness_web/templates/layout/live.html.heex @@ -1,21 +1,17 @@ -
+
+ ><%= Phoenix.Flash.get(@flash, :info) %>

+ ><%= Phoenix.Flash.get(@flash, :error) %>

- <%= live_flash(@flash, :bonus) %> + <%= Phoenix.Flash.get(@flash, :bonus) %>

- <%= live_flash(@flash, :loss) %> + <%= Phoenix.Flash.get(@flash, :loss) %>

<%= @inner_content %> diff --git a/test/fitness_web/controllers/user_auth_test.exs b/test/fitness_web/controllers/user_auth_test.exs index 36a5c06..1970582 100644 --- a/test/fitness_web/controllers/user_auth_test.exs +++ b/test/fitness_web/controllers/user_auth_test.exs @@ -132,7 +132,7 @@ defmodule FitnessWeb.UserAuthTest do conn = conn |> fetch_flash() |> UserAuth.require_authenticated_user([]) assert conn.halted assert redirected_to(conn) == Routes.user_session_path(conn, :new) - assert get_flash(conn, :error) == "You must log in to access this page." + assert Phoenix.Flash.get(conn.assigns.flash, :error) == "You must log in to access this page." end test "stores the path to redirect to on GET", %{conn: conn} do diff --git a/test/fitness_web/controllers/user_confirmation_controller_test.exs b/test/fitness_web/controllers/user_confirmation_controller_test.exs index ba7f9f8..3e2fc0b 100644 --- a/test/fitness_web/controllers/user_confirmation_controller_test.exs +++ b/test/fitness_web/controllers/user_confirmation_controller_test.exs @@ -26,7 +26,7 @@ defmodule FitnessWeb.UserConfirmationControllerTest do }) assert redirected_to(conn) == "/" - assert get_flash(conn, :info) =~ "If your email is in our system" + assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "If your email is in our system" assert Repo.get_by!(Accounts.UserToken, user_id: user.id).context == "confirm" end @@ -39,7 +39,7 @@ defmodule FitnessWeb.UserConfirmationControllerTest do }) assert redirected_to(conn) == "/" - assert get_flash(conn, :info) =~ "If your email is in our system" + assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "If your email is in our system" refute Repo.get_by(Accounts.UserToken, user_id: user.id) end @@ -50,7 +50,7 @@ defmodule FitnessWeb.UserConfirmationControllerTest do }) assert redirected_to(conn) == "/" - assert get_flash(conn, :info) =~ "If your email is in our system" + assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "If your email is in our system" assert Repo.all(Accounts.UserToken) == [] end end @@ -75,7 +75,7 @@ defmodule FitnessWeb.UserConfirmationControllerTest do conn = post(conn, Routes.user_confirmation_path(conn, :update, token)) assert redirected_to(conn) == "/" - assert get_flash(conn, :info) =~ "User confirmed successfully" + assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "User confirmed successfully" assert Accounts.get_user!(user.id).confirmed_at refute get_session(conn, :user_token) assert Repo.all(Accounts.UserToken) == [] @@ -83,7 +83,7 @@ defmodule FitnessWeb.UserConfirmationControllerTest do # When not logged in conn = post(conn, Routes.user_confirmation_path(conn, :update, token)) assert redirected_to(conn) == "/" - assert get_flash(conn, :error) =~ "User confirmation link is invalid or it has expired" + assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ "User confirmation link is invalid or it has expired" # When logged in conn = @@ -92,13 +92,13 @@ defmodule FitnessWeb.UserConfirmationControllerTest do |> post(Routes.user_confirmation_path(conn, :update, token)) assert redirected_to(conn) == "/" - refute get_flash(conn, :error) + refute Phoenix.Flash.get(conn.assigns.flash, :error) end test "does not confirm email with invalid token", %{conn: conn, user: user} do conn = post(conn, Routes.user_confirmation_path(conn, :update, "oops")) assert redirected_to(conn) == "/" - assert get_flash(conn, :error) =~ "User confirmation link is invalid or it has expired" + assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ "User confirmation link is invalid or it has expired" refute Accounts.get_user!(user.id).confirmed_at end end diff --git a/test/fitness_web/controllers/user_reset_password_controller_test.exs b/test/fitness_web/controllers/user_reset_password_controller_test.exs index 5ae4ac1..00fec94 100644 --- a/test/fitness_web/controllers/user_reset_password_controller_test.exs +++ b/test/fitness_web/controllers/user_reset_password_controller_test.exs @@ -26,7 +26,7 @@ defmodule FitnessWeb.UserResetPasswordControllerTest do }) assert redirected_to(conn) == "/" - assert get_flash(conn, :info) =~ "If your email is in our system" + assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "If your email is in our system" assert Repo.get_by!(Accounts.UserToken, user_id: user.id).context == "reset_password" end @@ -37,7 +37,7 @@ defmodule FitnessWeb.UserResetPasswordControllerTest do }) assert redirected_to(conn) == "/" - assert get_flash(conn, :info) =~ "If your email is in our system" + assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "If your email is in our system" assert Repo.all(Accounts.UserToken) == [] end end @@ -60,7 +60,7 @@ defmodule FitnessWeb.UserResetPasswordControllerTest do test "does not render reset password with invalid token", %{conn: conn} do conn = get(conn, Routes.user_reset_password_path(conn, :edit, "oops")) assert redirected_to(conn) == "/" - assert get_flash(conn, :error) =~ "Reset password link is invalid or it has expired" + assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ "Reset password link is invalid or it has expired" end end @@ -85,7 +85,7 @@ defmodule FitnessWeb.UserResetPasswordControllerTest do assert redirected_to(conn) == Routes.user_session_path(conn, :new) refute get_session(conn, :user_token) - assert get_flash(conn, :info) =~ "Password reset successfully" + assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Password reset successfully" assert Accounts.get_user_by_email_and_password(user.email, "new valid password") end @@ -107,7 +107,7 @@ defmodule FitnessWeb.UserResetPasswordControllerTest do test "does not reset password with invalid token", %{conn: conn} do conn = put(conn, Routes.user_reset_password_path(conn, :update, "oops")) assert redirected_to(conn) == "/" - assert get_flash(conn, :error) =~ "Reset password link is invalid or it has expired" + assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ "Reset password link is invalid or it has expired" end end end diff --git a/test/fitness_web/controllers/user_settings_controller_test.exs b/test/fitness_web/controllers/user_settings_controller_test.exs index 8f28481..ea8eec3 100644 --- a/test/fitness_web/controllers/user_settings_controller_test.exs +++ b/test/fitness_web/controllers/user_settings_controller_test.exs @@ -34,7 +34,7 @@ defmodule FitnessWeb.UserSettingsControllerTest do assert redirected_to(new_password_conn) == Routes.user_settings_path(conn, :edit) assert get_session(new_password_conn, :user_token) != get_session(conn, :user_token) - assert get_flash(new_password_conn, :info) =~ "Password updated successfully" + assert Phoenix.Flash.get(new_password_conn.assigns.flash, :info) =~ "Password updated successfully" assert Accounts.get_user_by_email_and_password(user.email, "new valid password") end @@ -70,7 +70,7 @@ defmodule FitnessWeb.UserSettingsControllerTest do }) assert redirected_to(conn) == Routes.user_settings_path(conn, :edit) - assert get_flash(conn, :info) =~ "A link to confirm your email" + assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "A link to confirm your email" assert Accounts.get_user_by_email(user.email) end @@ -104,19 +104,19 @@ defmodule FitnessWeb.UserSettingsControllerTest do test "updates the user email once", %{conn: conn, user: user, token: token, email: email} do conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token)) assert redirected_to(conn) == Routes.user_settings_path(conn, :edit) - assert get_flash(conn, :info) =~ "Email changed successfully" + assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Email changed successfully" refute Accounts.get_user_by_email(user.email) assert Accounts.get_user_by_email(email) conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token)) assert redirected_to(conn) == Routes.user_settings_path(conn, :edit) - assert get_flash(conn, :error) =~ "Email change link is invalid or it has expired" + assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ "Email change link is invalid or it has expired" end test "does not update email with invalid token", %{conn: conn, user: user} do conn = get(conn, Routes.user_settings_path(conn, :confirm_email, "oops")) assert redirected_to(conn) == Routes.user_settings_path(conn, :edit) - assert get_flash(conn, :error) =~ "Email change link is invalid or it has expired" + assert Phoenix.Flash.get(conn.assigns.flash, :error) =~ "Email change link is invalid or it has expired" assert Accounts.get_user_by_email(user.email) end