book review form

This commit is contained in:
Thu Savory 2025-01-15 23:38:06 +11:00
parent 5731765e8d
commit 9f9f543773
2 changed files with 56 additions and 27 deletions

View file

@ -3,39 +3,33 @@ defmodule WildWeb.BookThoughts do
def render(assigns) do
~H"""
<div class="mx-auto">
<.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
</:subtitle>
<div class="text-center">
<.header>
Let the forest hear your thoughts on this book
<:subtitle>The wind will carry your howl</:subtitle>
</.header>
<.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?
</.link>
</:actions>
<:actions>
<.button phx-disable-with="Logging in..." class="w-full">
Log in <span aria-hidden="true"></span>
</.button>
</:actions>
</.simple_form>
</div>
<.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 />
</.simple_form>
"""
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