Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Started on the edit modal #4

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/chat_app_live_web/live/chat_form_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ defmodule ChatAppLiveWeb.ChatFormLive do
{:ok, assign(socket, form: to_form(Messages.change_message(%Message{})), messages: messages)}
end

defp get_message!(message_id) do
case Repo.get(Message, message_id) do
nil -> {:error, "Message not found"}
message -> {:ok, message}
end
end

def handle_event("save", %{"message" => message_params}, socket) do
case Messages.create_message(message_params) do
{:ok, _message} ->
Expand Down Expand Up @@ -77,6 +84,7 @@ defmodule ChatAppLiveWeb.ChatFormLive do
<a
href="#"
class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 mr-2 mb-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800"
phx-click={show_modal("edit-form")}
>
Edit
</a>
Expand Down Expand Up @@ -106,6 +114,25 @@ defmodule ChatAppLiveWeb.ChatFormLive do
<% end %>
</ul>
</div>

<ChatAppLiveWeb.CoreComponents.modal id="edit-form">
<h1>Edit Message</h1>
<.form for={@form} phx-submit="save">
<label for="comment" class="sr-only">Add your comment</label>
<.input type="textarea" field={@form[:content]} />



<div class="flex-shrink-0">
<button
type="submit"
class="inline-flex items-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
>
Edit
</button>
</div>
</.form>
</ChatAppLiveWeb.CoreComponents.modal>
"""
end
end