basically working for one user (no user/all users actually)
This commit is contained in:
38
lib/clip_web/live/board_live.ex
Normal file
38
lib/clip_web/live/board_live.ex
Normal file
@ -0,0 +1,38 @@
|
||||
defmodule ClipWeb.BoardLive do
|
||||
use ClipWeb, :live_view
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~L"""
|
||||
<form phx-change="paste">
|
||||
<input type="text" name="snippet" value="<%= @snippet %>" data-updated-val="<%= @snippet %>" phx-hook="SnippetInput" autocomplete="off"/>
|
||||
</form>
|
||||
Current content: <%= @snippet %>
|
||||
<button phx-click="normalize">
|
||||
"""
|
||||
end
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
Phoenix.PubSub.subscribe(Clip.PubSub, "everybody") # actually only for single user
|
||||
{:ok, assign(socket, snippet: "")}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("normalize", _, %{"snippet" => snippet} = socket) do
|
||||
|
||||
Phoenix.PubSub.broadcast(Clip.PubSub, "everybody", {:snippet_pasted, %{"snippet" => snippet}})
|
||||
{:noreply, assign(socket, snippet: snippet)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("paste", %{"snippet" => snippet}, socket) do
|
||||
Phoenix.PubSub.broadcast(Clip.PubSub, "everybody", {:snippet_pasted, %{"snippet" => snippet}})
|
||||
{:noreply, assign(socket, snippet: snippet)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info({:snippet_pasted, %{"snippet" => snippet}}, socket) do
|
||||
{:noreply, assign(socket, snippet: snippet)}
|
||||
end
|
||||
end
|
||||
@ -17,7 +17,8 @@ defmodule ClipWeb.Router do
|
||||
scope "/", ClipWeb do
|
||||
pipe_through :browser
|
||||
|
||||
live "/", PageLive, :index
|
||||
# live "/", PageLive, :index
|
||||
live "/", BoardLive, :index
|
||||
end
|
||||
|
||||
# Other scopes may use custom stacks.
|
||||
|
||||
Reference in New Issue
Block a user