From 9f9f5437732154ac829ddc1b26bfa82076936726 Mon Sep 17 00:00:00 2001 From: Thu Savory Date: Wed, 15 Jan 2025 23:38:06 +1100 Subject: [PATCH] book review form --- lib/wild_web/components/core_components.ex | 35 ++++++++++++++++ lib/wild_web/live/book_thoughts.ex | 48 ++++++++++------------ 2 files changed, 56 insertions(+), 27 deletions(-) diff --git a/lib/wild_web/components/core_components.ex b/lib/wild_web/components/core_components.ex index e727ca2..2ddd98a 100644 --- a/lib/wild_web/components/core_components.ex +++ b/lib/wild_web/components/core_components.ex @@ -673,4 +673,39 @@ defmodule WildWeb.CoreComponents do def translate_errors(errors, field) when is_list(errors) do for {^field, {msg, opts}} <- errors, do: translate_error({msg, opts}) end + + defp a_rating_star(assigns) do + ~H""" + + + """ + end + + def rating_stars(assigns) do + ~H""" +
+ <.a_rating_star :for={i <- 1..10} value={i} /> +
+ """ + end end diff --git a/lib/wild_web/live/book_thoughts.ex b/lib/wild_web/live/book_thoughts.ex index 8cb1040..7f34896 100644 --- a/lib/wild_web/live/book_thoughts.ex +++ b/lib/wild_web/live/book_thoughts.ex @@ -3,39 +3,33 @@ defmodule WildWeb.BookThoughts do def render(assigns) do ~H""" -
- <.header class="text-center"> - Write your thoughts for a book or a series of books - <:subtitle> - Share your thoughts and suggestion on the book that you just read - +
+ <.header> + Let the forest hear your thoughts on this book + <:subtitle>The wind will carry your howl - - <.simple_form for={@form} id="login_form" action={~p"/account/log_in"} phx-update="ignore"> - <.input field={@form[:email]} type="text" label="Book Title" required /> - <.input field={@form[:password]} type="number" label="Publication Year" required /> - <.input field={@form[:password]} type="range" label="Rating" required /> - - <:actions> - <.input field={@form[:remember_me]} type="checkbox" label="Keep me logged in" /> - <.link href={~p"/account/reset_password"} class="text-sm font-semibold"> - Forgot your password? - - - <:actions> - <.button phx-disable-with="Logging in..." class="w-full"> - Log in - - -
+ <.simple_form for={@form} phx-changed="validate" phx-submit="save"> + <.input field={@form[:book_title]} type="text" label="Book Title" required /> + <.input field={@form[:author]} type="text" label="Author" required /> + <.rating_stars /> + <.input field={@form[:book_review]} type="textarea" label="Your Wild Thoughts" required /> + <.input field={@form[:start_date]} type="date" label="Reading Start Date" required /> + <.input field={@form[:finish_date]} type="date" label="Reading Finish Date" required /> + """ end def mount(_params, _session, socket) do - email = Phoenix.Flash.get(socket.assigns.flash, :email) - form = to_form(%{"email" => email}, as: "user") + form = + to_form(%{ + "book_title" => "", + "author" => "", + "book_review" => "", + "start_date" => "", + "finish_date" => "" + }) + {:ok, assign(socket, form: form), temporary_assigns: [form: form]} end - end