feat(chat): initial implementation for edit live view
This commit is contained in:
parent
32350431f8
commit
a0d23e5672
lib
@ -20,6 +20,10 @@ defmodule Slax.Chat do
|
|||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def change_room(room, attrs \\ %{}) do
|
||||||
|
Room.changeset(room, attrs)
|
||||||
|
end
|
||||||
|
|
||||||
def get_first_room! do
|
def get_first_room! do
|
||||||
query = from(r in Room, limit: 1, order_by: [asc: :name])
|
query = from(r in Room, limit: 1, order_by: [asc: :name])
|
||||||
Repo.one!(query)
|
Repo.one!(query)
|
||||||
|
@ -26,7 +26,15 @@ defmodule SlaxWeb.ChatRoomLive do
|
|||||||
<div class="flex flex-col flex-grow shadow-lg">
|
<div class="flex flex-col flex-grow shadow-lg">
|
||||||
<div class="flex justify-between items-center flex-shrink-0 h-16 bg-white border-b border-slate-300 px-4">
|
<div class="flex justify-between items-center flex-shrink-0 h-16 bg-white border-b border-slate-300 px-4">
|
||||||
<div class="flex flex-col gap-1.5">
|
<div class="flex flex-col gap-1.5">
|
||||||
<h1 class="text-sm font-bold leading-none">#<%= @room.name %></h1>
|
<h1 class="text-sm font-bold leading-none">
|
||||||
|
#<%= @room.name %>
|
||||||
|
<.link
|
||||||
|
class="font-normal text-xs text-blue-600 hover:text-blue-700"
|
||||||
|
navigate={~p"/rooms/#{@room}/edit"}
|
||||||
|
>
|
||||||
|
Edit
|
||||||
|
</.link>
|
||||||
|
</h1>
|
||||||
<div class="text-xs leading-none h-3.5" phx-click="toggle-topic">
|
<div class="text-xs leading-none h-3.5" phx-click="toggle-topic">
|
||||||
<%= if @hide_topic? do %>
|
<%= if @hide_topic? do %>
|
||||||
<span class="text-slate-600">[Topic hidden]</span>
|
<span class="text-slate-600">[Topic hidden]</span>
|
||||||
|
49
lib/slax_web/live/chat_room_live/edit.ex
Normal file
49
lib/slax_web/live/chat_room_live/edit.ex
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
defmodule SlaxWeb.ChatRoomLive.Edit do
|
||||||
|
@moduledoc false
|
||||||
|
use SlaxWeb, :live_view
|
||||||
|
|
||||||
|
alias Slax.Chat
|
||||||
|
|
||||||
|
@impl Phoenix.LiveView
|
||||||
|
def render(assigns) do
|
||||||
|
~H"""
|
||||||
|
<div class="mx-auto w-96 mt-12">
|
||||||
|
<.header>
|
||||||
|
<%= @page_title %>
|
||||||
|
<:actions>
|
||||||
|
<.link
|
||||||
|
class="font-normal text-xs text-blue-600 hover:text-blue-700"
|
||||||
|
navigate={~p"/rooms/#{@room}"}
|
||||||
|
>
|
||||||
|
Back
|
||||||
|
</.link>
|
||||||
|
</:actions>
|
||||||
|
</.header>
|
||||||
|
<.simple_form for={@form} id="room-form">
|
||||||
|
<.input field={@form[:name]} type="text" label="Name" />
|
||||||
|
<.input field={@form[:topic]} type="text" label="Topic" />
|
||||||
|
<:actions>
|
||||||
|
<.button phx-disable-with="Saving..." class="w-full">Save</.button>
|
||||||
|
</:actions>
|
||||||
|
</.simple_form>
|
||||||
|
</div>
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl Phoenix.LiveView
|
||||||
|
def mount(%{"id" => id}, _session, socket) do
|
||||||
|
room = Chat.get_room!(id)
|
||||||
|
changeset = Chat.change_room(room)
|
||||||
|
|
||||||
|
socket =
|
||||||
|
socket
|
||||||
|
|> assign(page_title: "Edit chat room", room: room)
|
||||||
|
|> assign_form(changeset)
|
||||||
|
|
||||||
|
{:ok, socket}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp assign_form(socket, %Ecto.Changeset{} = changeset) do
|
||||||
|
assign(socket, :form, to_form(changeset))
|
||||||
|
end
|
||||||
|
end
|
@ -20,6 +20,7 @@ defmodule SlaxWeb.Router do
|
|||||||
get "/home", PageController, :home
|
get "/home", PageController, :home
|
||||||
live "/", ChatRoomLive
|
live "/", ChatRoomLive
|
||||||
live "/rooms/:id", ChatRoomLive
|
live "/rooms/:id", ChatRoomLive
|
||||||
|
live "/rooms/:id/edit", ChatRoomLive.Edit
|
||||||
end
|
end
|
||||||
|
|
||||||
# Other scopes may use custom stacks.
|
# Other scopes may use custom stacks.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user